From 4d51a8a248bcbe50849b6c7682aaca1aa9ebff98 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/pgsql/query.hxx | 95 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 27 deletions(-) (limited to 'odb/pgsql/query.hxx') diff --git a/odb/pgsql/query.hxx b/odb/pgsql/query.hxx index 401f29a..997f206 100644 --- a/odb/pgsql/query.hxx +++ b/odb/pgsql/query.hxx @@ -11,6 +11,7 @@ #include #include // std::size_t +#include // odb::query_column #include #include @@ -119,7 +120,7 @@ namespace odb query_base (bool v) : binding_ (0, 0), native_binding_ (0, 0, 0, 0) { - clause_.push_back (clause_part (v)); + append (v); } explicit @@ -163,6 +164,13 @@ namespace odb template query_base (const query_column&); + // Translate common query representation to PostgreSQL native. Defined + // in query-dynamic.cxx + // + query_base (const odb::query_base&); + + // Copy c-tor and assignment. + // query_base (const query_base&); query_base& @@ -259,6 +267,8 @@ namespace odb return *this; } + // Implementation details. + // public: template void @@ -269,14 +279,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; @@ -406,28 +427,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_PGSQL_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) { } @@ -452,6 +459,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: @@ -1086,11 +1127,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 @@ -1824,6 +1860,11 @@ namespace odb : query_base (qc) { } + + query (const odb::query_base& q) + : query_base (q) + { + } }; } -- cgit v1.1