From b3826d5ff054deeb7ba22aecb242cec2dca2f93a 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/oracle/query.hxx | 160 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 103 insertions(+), 57 deletions(-) (limited to 'odb/oracle/query.hxx') diff --git a/odb/oracle/query.hxx b/odb/oracle/query.hxx index 9980833..1bf6853 100644 --- a/odb/oracle/query.hxx +++ b/odb/oracle/query.hxx @@ -11,6 +11,7 @@ #include #include // std::size_t +#include // odb::query_column #include #include @@ -136,7 +137,7 @@ namespace odb query_base (bool v) : binding_ (0, 0) { - clause_.push_back (clause_part (v)); + append (v); } explicit @@ -180,6 +181,13 @@ namespace odb template query_base (const query_column&); + // Translate common query representation to Oracle native. Defined + // in query-dynamic.cxx + // + query_base (const odb::query_base&); + + // Copy c-tor and assignment. + // query_base (const query_base&); query_base& @@ -264,24 +272,37 @@ namespace odb return *this; } + // Implementation details. + // public: template void - append (val_bind, const char* conv); + append (val_bind, const char* conv); template void - append (ref_bind, const char* conv); + 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; @@ -404,34 +425,18 @@ 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_ORACLE_EXPORT query_column_base { - // Note that we keep shalow copies of the table, column, and conversion + // 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, - unsigned short prec = 0xFFF, - short scale = 0xFFF) - : table_ (table), column_ (column), conversion_ (conv), - prec_ (prec), scale_ (scale) + query_column_base (const char* table, + const char* column, + const char* conv, + unsigned short prec, + short scale) + : table_ (table), column_ (column), conversion_ (conv), + prec_ (prec), scale_ (scale) { } @@ -467,6 +472,51 @@ namespace odb return scale_; } + protected: + const char* table_; + const char* column_; + const char* conversion_; + + unsigned short prec_; + short scale_; + }; + + 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 shalow copies of the table, column, and conversion + // expression. The latter can be NULL. + // + query_column (const char* table, + const char* column, + const char* conv, + unsigned short prec = 0xFFF, + short scale = 0xFFF) + : query_column_base (table, column, conv, prec, scale) {} + + // Implementation is in query-dynamic.ixx. + // + query_column (odb::query_column&, + const char* table, + const char* column, + const char* conv, + unsigned short prec = 0xFFF, + short scale = 0xFFF); + // is_null, is_not_null // public: @@ -1137,14 +1187,6 @@ namespace odb q.append (c.table (), c.column ()); return q; } - - private: - const char* table_; - const char* column_; - const char* conversion_; - - unsigned short prec_; - short scale_; }; // @@ -1153,27 +1195,15 @@ namespace odb // predicates for these types. // - struct LIBODB_ORACLE_EXPORT lob_query_column + struct LIBODB_ORACLE_EXPORT lob_query_column: query_column_base { // Note that we keep shallow copies of the table and column names. // There is also no need for conversion expression since the only // valid tests are is IS NULL/IS NOT NULL. // lob_query_column (const char* table, const char* column) - : table_ (table), column_ (column) - { - } - - const char* - table () const + : query_column_base (table, column, 0, 0xFFF, 0xFFF) { - return table_; - } - - const char* - column () const - { - return column_; } // is_null, is_not_null @@ -1194,10 +1224,6 @@ namespace odb q += "IS NOT NULL"; return q; } - - private: - const char* table_; - const char* column_; }; template @@ -1207,6 +1233,11 @@ namespace odb : lob_query_column (table, column) { } + + // Implementation is in query-dynamic.ixx. + // + query_column (odb::query_column&, + const char* table, const char* column, const char*); }; template @@ -1216,6 +1247,11 @@ namespace odb : lob_query_column (table, column) { } + + // Implementation is in query-dynamic.ixx. + // + query_column (odb::query_column&, + const char* table, const char* column, const char*); }; template @@ -1225,6 +1261,11 @@ namespace odb : lob_query_column (table, column) { } + + // Implementation is in query-dynamic.ixx. + // + query_column (odb::query_column&, + const char* table, const char* column, const char*); }; // Provide operator+() for using columns to construct native @@ -1890,6 +1931,11 @@ namespace odb : query_base (qc) { } + + query (const odb::query_base& q) + : query_base (q) + { + } }; } -- cgit v1.1