diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-09-09 12:18:38 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-09-09 12:18:38 +0200 |
commit | 0a7c90251190205e8bd9f5193b7402e25efa2f81 (patch) | |
tree | 84d91a66ef37105c082c4154fbf3fca37c11e98b /odb/mysql/query.hxx | |
parent | 932ae000f66ec5935c368b953da24dfd6cf7581b (diff) |
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.
Diffstat (limited to 'odb/mysql/query.hxx')
-rw-r--r-- | odb/mysql/query.hxx | 99 |
1 files changed, 54 insertions, 45 deletions
diff --git a/odb/mysql/query.hxx b/odb/mysql/query.hxx index 17aa724..57d43a1 100644 --- a/odb/mysql/query.hxx +++ b/odb/mysql/query.hxx @@ -107,11 +107,16 @@ namespace odb } explicit - query (const std::string& q, - clause_part::kind_type k = clause_part::native) + query (const std::string& native) : binding_ (0, 0) { - clause_.push_back (clause_part (k, q)); + clause_.push_back (clause_part (clause_part::native, native)); + } + + query (const char* table, const char* column) + : binding_ (0, 0) + { + append (table, column); } template <typename T> @@ -140,7 +145,7 @@ namespace odb public: std::string - clause (std::string const& default_table) const; + clause () const; binding& parameters_binding () const; @@ -167,7 +172,7 @@ namespace odb query& operator+= (const std::string& q) { - append (q, clause_part::native); + append (q); return *this; } @@ -197,7 +202,10 @@ namespace odb append (ref_bind<T>); void - append (const std::string&, clause_part::kind_type); + append (const std::string& native); + + void + append (const char* table, const char* column); private: void @@ -364,16 +372,23 @@ namespace odb template <typename T, database_type_id ID> 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 @@ -382,7 +397,7 @@ namespace odb query is_null () const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "IS NULL"; return q; } @@ -390,7 +405,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; } @@ -426,7 +441,7 @@ namespace odb query equal (val_bind<T> v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "="; q.append<T, ID> (v); return q; @@ -443,7 +458,7 @@ namespace odb query equal (ref_bind<T> r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "="; q.append<T, ID> (r); return q; @@ -511,7 +526,7 @@ namespace odb query unequal (val_bind<T> v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "!="; q.append<T, ID> (v); return q; @@ -528,7 +543,7 @@ namespace odb query unequal (ref_bind<T> r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "!="; q.append<T, ID> (r); return q; @@ -596,7 +611,7 @@ namespace odb query less (val_bind<T> v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<"; q.append<T, ID> (v); return q; @@ -613,7 +628,7 @@ namespace odb query less (ref_bind<T> r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<"; q.append<T, ID> (r); return q; @@ -681,7 +696,7 @@ namespace odb query greater (val_bind<T> v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">"; q.append<T, ID> (v); return q; @@ -698,7 +713,7 @@ namespace odb query greater (ref_bind<T> r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">"; q.append<T, ID> (r); return q; @@ -766,7 +781,7 @@ namespace odb query less_equal (val_bind<T> v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<="; q.append<T, ID> (v); return q; @@ -783,7 +798,7 @@ namespace odb query less_equal (ref_bind<T> r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += "<="; q.append<T, ID> (r); return q; @@ -851,7 +866,7 @@ namespace odb query greater_equal (val_bind<T> v) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">="; q.append<T, ID> (v); return q; @@ -868,7 +883,7 @@ namespace odb query greater_equal (ref_bind<T> r) const { - query q (name_, query::clause_part::column); + query q (table_, column_); q += ">="; q.append<T, ID> (r); return q; @@ -935,9 +950,9 @@ namespace odb // (void) (sizeof (type_instance<T> () == type_instance<T2> ())); - 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; } @@ -949,9 +964,9 @@ namespace odb // (void) (sizeof (type_instance<T> () != type_instance<T2> ())); - 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; } @@ -963,9 +978,9 @@ namespace odb // (void) (sizeof (type_instance<T> () < type_instance<T2> ())); - 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; } @@ -977,9 +992,9 @@ namespace odb // (void) (sizeof (type_instance<T> () > type_instance<T2> ())); - 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; } @@ -991,9 +1006,9 @@ namespace odb // (void) (sizeof (type_instance<T> () <= type_instance<T2> ())); - 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; } @@ -1005,14 +1020,15 @@ namespace odb // (void) (sizeof (type_instance<T> () >= type_instance<T2> ())); - 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_; }; // @@ -1814,13 +1830,6 @@ namespace odb : query_selector<T>::type (qc) { } - - std::string - clause () const - { - return query_selector<T>::type::clause ( - query_selector<T>::table_name ()); - } }; } |