From a8b1a89c291ab5bd170568eab3d7666631adf035 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 9 Sep 2011 12:18:39 +0200 Subject: New templated query_columns architecture We also now use the correct separate "role"-base join approach instead of having a single merged join for each table. --- odb/sqlite/query.hxx | 99 ++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 45 deletions(-) (limited to 'odb/sqlite/query.hxx') diff --git a/odb/sqlite/query.hxx b/odb/sqlite/query.hxx index f413756..9731d10 100644 --- a/odb/sqlite/query.hxx +++ b/odb/sqlite/query.hxx @@ -137,11 +137,16 @@ namespace odb } explicit - query (const std::string& q, - clause_part::kind_type k = clause_part::native) + query (const std::string& native) : parameters_ (new (details::shared) query_params) { - clause_.push_back (clause_part (k, q)); + clause_.push_back (clause_part (clause_part::native, native)); + } + + query (const char* table, const char* column) + : parameters_ (new (details::shared) query_params) + { + append (table, column); } template @@ -170,7 +175,7 @@ namespace odb public: std::string - clause (std::string const& default_table) const; + clause () const; binding& parameters_binding () const; @@ -200,7 +205,7 @@ namespace odb query& operator+= (const std::string& q) { - append (q, clause_part::native); + append (q); return *this; } @@ -230,7 +235,10 @@ namespace odb append (ref_bind); void - append (const std::string&, clause_part::kind_type); + append (const std::string& native); + + void + append (const char* table, const char* column); private: void @@ -394,16 +402,23 @@ namespace odb template struct query_column { - explicit - query_column (const char* name) - : name_ (name) + // Note that we keep shalow copies of the table and column names. + // + query_column (const char* table, const char* column) + : table_ (table), column_ (column) { } const char* - name () const + table () const { - return name_; + return table_; + } + + const char* + column () const + { + return column_; } // is_null, is_not_null @@ -412,7 +427,7 @@ namespace odb query is_null () const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "IS NULL"; return q; } @@ -420,7 +435,7 @@ namespace odb query is_not_null () const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "IS NOT NULL"; return q; } @@ -456,7 +471,7 @@ namespace odb query equal (val_bind v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "="; q.append (v); return q; @@ -473,7 +488,7 @@ namespace odb query equal (ref_bind r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "="; q.append (r); return q; @@ -541,7 +556,7 @@ namespace odb query unequal (val_bind v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "!="; q.append (v); return q; @@ -558,7 +573,7 @@ namespace odb query unequal (ref_bind r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "!="; q.append (r); return q; @@ -626,7 +641,7 @@ namespace odb query less (val_bind v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<"; q.append (v); return q; @@ -643,7 +658,7 @@ namespace odb query less (ref_bind r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<"; q.append (r); return q; @@ -711,7 +726,7 @@ namespace odb query greater (val_bind v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">"; q.append (v); return q; @@ -728,7 +743,7 @@ namespace odb query greater (ref_bind r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">"; q.append (r); return q; @@ -796,7 +811,7 @@ namespace odb query less_equal (val_bind v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<="; q.append (v); return q; @@ -813,7 +828,7 @@ namespace odb query less_equal (ref_bind r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<="; q.append (r); return q; @@ -881,7 +896,7 @@ namespace odb query greater_equal (val_bind v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">="; q.append (v); return q; @@ -898,7 +913,7 @@ namespace odb query greater_equal (ref_bind r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">="; q.append (r); return q; @@ -965,9 +980,9 @@ namespace odb // (void) (sizeof (type_instance () == type_instance ())); - query q (name_, query::clause_part::column); + query q (table_, column_); q += "="; - q.append (c.name (), query::clause_part::column); + q.append (c.table (), c.column ()); return q; } @@ -979,9 +994,9 @@ namespace odb // (void) (sizeof (type_instance () != type_instance ())); - query q (name_, query::clause_part::column); + query q (table_, column_); q += "!="; - q.append (c.name (), query::clause_part::column); + q.append (c.table (), c.column ()); return q; } @@ -993,9 +1008,9 @@ namespace odb // (void) (sizeof (type_instance () < type_instance ())); - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<"; - q.append (c.name (), query::clause_part::column); + q.append (c.table (), c.column ()); return q; } @@ -1007,9 +1022,9 @@ namespace odb // (void) (sizeof (type_instance () > type_instance ())); - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">"; - q.append (c.name (), query::clause_part::column); + q.append (c.table (), c.column ()); return q; } @@ -1021,9 +1036,9 @@ namespace odb // (void) (sizeof (type_instance () <= type_instance ())); - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<="; - q.append (c.name (), query::clause_part::column); + q.append (c.table (), c.column ()); return q; } @@ -1035,14 +1050,15 @@ namespace odb // (void) (sizeof (type_instance () >= type_instance ())); - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">="; - q.append (c.name (), query::clause_part::column); + q.append (c.table (), c.column ()); return q; } private: - const char* name_; + const char* table_; + const char* column_; }; // @@ -1240,13 +1256,6 @@ namespace odb : query_selector::type (qc) { } - - std::string - clause () const - { - return query_selector::type::clause ( - query_selector::table_name ()); - } }; } -- cgit v1.1