From de82079ff82a62e69ed3e70122ba9af6ecefcacf Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 3 Dec 2012 13:12:15 +0200 Subject: Add support for executing common query using static interface --- odb/pgsql/connection.hxx | 6 +++++- odb/pgsql/connection.ixx | 11 ++++++++++- odb/pgsql/database.hxx | 18 ++++++++++++++--- odb/pgsql/database.ixx | 51 ++++++++++++++++++++++++++++++++++++------------ 4 files changed, 69 insertions(+), 17 deletions(-) (limited to 'odb/pgsql') diff --git a/odb/pgsql/connection.hxx b/odb/pgsql/connection.hxx index 472ee63..f43955d 100644 --- a/odb/pgsql/connection.hxx +++ b/odb/pgsql/connection.hxx @@ -72,7 +72,11 @@ namespace odb template prepared_query - prepare_query (const char* name, const query&); + prepare_query (const char* name, const pgsql::query_base&); + + template + prepared_query + prepare_query (const char* name, const odb::query_base&); // SQL statement tracing. // diff --git a/odb/pgsql/connection.ixx b/odb/pgsql/connection.ixx index 70501e1..f1552bd 100644 --- a/odb/pgsql/connection.ixx +++ b/odb/pgsql/connection.ixx @@ -22,9 +22,18 @@ namespace odb template inline prepared_query connection:: - prepare_query (const char* n, const query& q) + prepare_query (const char* n, const pgsql::query_base& q) { return query_::call (*this, n, q); } + + template + inline prepared_query connection:: + prepare_query (const char* n, const odb::query_base& q) + { + // Translate to native query. + // + return prepare_query (n, pgsql::query_base (q)); + } } } diff --git a/odb/pgsql/database.hxx b/odb/pgsql/database.hxx index 02aa240..714dcfe 100644 --- a/odb/pgsql/database.hxx +++ b/odb/pgsql/database.hxx @@ -246,7 +246,11 @@ namespace odb template unsigned long long - erase_query (const pgsql::query&); + erase_query (const pgsql::query_base&); + + template + unsigned long long + erase_query (const odb::query_base&); // Query API. // @@ -264,7 +268,11 @@ namespace odb template result - query (const pgsql::query&); + query (const pgsql::query_base&); + + template + result + query (const odb::query_base&); // Query preparation. // @@ -278,7 +286,11 @@ namespace odb template prepared_query - prepare_query (const char* name, const pgsql::query&); + prepare_query (const char* name, const pgsql::query_base&); + + template + prepared_query + prepare_query (const char* name, const odb::query_base&); // Transactions. // diff --git a/odb/pgsql/database.ixx b/odb/pgsql/database.ixx index 7ad92be..8124a28 100644 --- a/odb/pgsql/database.ixx +++ b/odb/pgsql/database.ixx @@ -335,7 +335,7 @@ namespace odb { // T is always object_type. // - return erase_query (pgsql::query ()); + return erase_query (pgsql::query_base ()); } template @@ -344,7 +344,7 @@ namespace odb { // T is always object_type. // - return erase_query (pgsql::query (q)); + return erase_query (pgsql::query_base (q)); } template @@ -353,12 +353,12 @@ namespace odb { // T is always object_type. // - return erase_query (pgsql::query (q)); + return erase_query (pgsql::query_base (q)); } template inline unsigned long long database:: - erase_query (const pgsql::query& q) + erase_query (const pgsql::query_base& q) { // T is always object_type. // @@ -366,29 +366,38 @@ namespace odb } template + inline unsigned long long database:: + erase_query (const odb::query_base& q) + { + // Translate to native query. + // + return erase_query (pgsql::query_base (q)); + } + + template inline result database:: query () { - return query (pgsql::query ()); + return query (pgsql::query_base ()); } template inline result database:: query (const char* q) { - return query (pgsql::query (q)); + return query (pgsql::query_base (q)); } template inline result database:: query (const std::string& q) { - return query (pgsql::query (q)); + return query (pgsql::query_base (q)); } template inline result database:: - query (const pgsql::query& q) + query (const pgsql::query_base& q) { // T is always object_type. We also don't need to check for transaction // here; object_traits::query () does this. @@ -397,27 +406,45 @@ namespace odb } template + inline result database:: + query (const odb::query_base& q) + { + // Translate to native query. + // + return query (pgsql::query_base (q)); + } + + template inline prepared_query database:: prepare_query (const char* n, const char* q) { - return prepare_query (n, pgsql::query (q)); + return prepare_query (n, pgsql::query_base (q)); } template inline prepared_query database:: prepare_query (const char* n, const std::string& q) { - return prepare_query (n, pgsql::query (q)); + return prepare_query (n, pgsql::query_base (q)); } template inline prepared_query database:: - prepare_query (const char* n, const pgsql::query& q) + prepare_query (const char* n, const pgsql::query_base& q) { // Throws if not in transaction. // pgsql::connection& c (transaction::current ().connection ()); - return c.prepare_query (n, q); + return c.prepare_query (n, q); + } + + template + inline prepared_query database:: + prepare_query (const char* n, const odb::query_base& q) + { + // Translate to native query. + // + return prepare_query (n, pgsql::query_base (q)); } } } -- cgit v1.1