From a2914e837c6442db936fd035b49f60ee488df533 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 21 Nov 2012 13:11:43 +0200 Subject: Add dynamic multi-database query support --- odb/sqlite/query.hxx | 95 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 27 deletions(-) (limited to 'odb/sqlite/query.hxx') diff --git a/odb/sqlite/query.hxx b/odb/sqlite/query.hxx index 2a17b4f..18c10bb 100644 --- a/odb/sqlite/query.hxx +++ b/odb/sqlite/query.hxx @@ -11,6 +11,7 @@ #include #include // std::size_t +#include // odb::query_column #include #include #include @@ -149,7 +150,7 @@ namespace odb query_base (bool v) : parameters_ (new (details::shared) query_params) { - clause_.push_back (clause_part (v)); + append (v); } explicit @@ -193,6 +194,13 @@ namespace odb template query_base (const query_column&); + // Translate common query representation to SQLite native. Defined + // in query-dynamic.cxx + // + query_base (const odb::query_base&); + + // Copy c-tor and assignment. + // query_base (const query_base&); query_base& @@ -280,6 +288,8 @@ namespace odb return *this; } + // Implementation details. + // public: template void @@ -290,14 +300,25 @@ namespace odb append (ref_bind, const char* conv); void + append (details::shared_ptr, const char* conv); + + void + append (bool v) + { + clause_.push_back (clause_part (v)); + } + + void append (const std::string& native); void - append (const char* table, const char* column); + append (const char* native) // Clashes with append(bool). + { + append (std::string (native)); + } - private: void - add (details::shared_ptr, const char* conv); + append (const char* table, const char* column); private: typedef std::vector clause_type; @@ -417,28 +438,14 @@ namespace odb // query_column // - - template - class copy_bind: public val_bind - { - public: - explicit - copy_bind (const T2& v): val_bind (val), val (v) {} - - const T val; - }; - - template - const T& - type_instance (); - - template - struct query_column + struct LIBODB_SQLITE_EXPORT query_column_base { // Note that we keep shallow copies of the table, column, and conversion // expression. The latter can be NULL. // - query_column (const char* table, const char* column, const char* conv) + query_column_base (const char* table, + const char* column, + const char* conv) : table_ (table), column_ (column), conversion_ (conv) { } @@ -463,6 +470,40 @@ namespace odb return conversion_; } + protected: + const char* table_; + const char* column_; + const char* conversion_; + }; + + template + class copy_bind: public val_bind + { + public: + explicit + copy_bind (const T2& v): val_bind (val), val (v) {} + + const T val; + }; + + template + const T& + type_instance (); + + template + struct query_column: query_column_base + { + // Note that we keep shallow copies of the table, column, and conversion + // expression. The latter can be NULL. + // + query_column (const char* table, const char* column, const char* conv) + : query_column_base (table, column, conv) {} + + // Implementation is in query-dynamic.ixx. + // + query_column (odb::query_column&, + const char* table, const char* column, const char* conv); + // is_null, is_not_null // public: @@ -1097,11 +1138,6 @@ namespace odb q.append (c.table (), c.column ()); return q; } - - private: - const char* table_; - const char* column_; - const char* conversion_; }; // Provide operator+() for using columns to construct native @@ -1353,6 +1389,11 @@ namespace odb : query_base (qc) { } + + query (const odb::query_base& q) + : query_base (q) + { + } }; } -- cgit v1.1