From 05ff680189f689d5bf82cd514e9d650c59aaf3da Mon Sep 17 00:00:00 2001 From: Michael Shepanski Date: Tue, 4 Nov 2014 16:10:03 +1100 Subject: Implement {query,execute}_{one,value}() shortcut functions Useful in situations where the query is know to return at most one element (*_one) or exactly one element (*_value). --- odb/mssql/database.hxx | 62 +++++++++++++++++++++++++ odb/mssql/database.ixx | 120 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) diff --git a/odb/mssql/database.hxx b/odb/mssql/database.hxx index b949892..4ac85d2 100644 --- a/odb/mssql/database.hxx +++ b/odb/mssql/database.hxx @@ -348,6 +348,68 @@ namespace odb result query (const odb::query_base&); + // Query one API. + // + template + typename object_traits::pointer_type + query_one (); + + template + bool + query_one (T& object); + + template + T + query_value (); + + template + typename object_traits::pointer_type + query_one (const char*); + + template + bool + query_one (const char*, T& object); + + template + T + query_value (const char*); + + template + typename object_traits::pointer_type + query_one (const std::string&); + + template + bool + query_one (const std::string&, T& object); + + template + T + query_value (const std::string&); + + template + typename object_traits::pointer_type + query_one (const mssql::query_base&); + + template + bool + query_one (const mssql::query_base&, T& object); + + template + T + query_value (const mssql::query_base&); + + template + typename object_traits::pointer_type + query_one (const odb::query_base&); + + template + bool + query_one (const odb::query_base&, T& object); + + template + T + query_value (const odb::query_base&); + // Query preparation. // template diff --git a/odb/mssql/database.ixx b/odb/mssql/database.ixx index cd79eef..93919f6 100644 --- a/odb/mssql/database.ixx +++ b/odb/mssql/database.ixx @@ -429,6 +429,126 @@ namespace odb } template + inline typename object_traits::pointer_type database:: + query_one () + { + return query_one (mssql::query_base ()); + } + + template + inline bool database:: + query_one (T& o) + { + return query_one (mssql::query_base (), o); + } + + template + inline T database:: + query_value () + { + return query_value (mssql::query_base ()); + } + + template + inline typename object_traits::pointer_type database:: + query_one (const char* q) + { + return query_one (mssql::query_base (q)); + } + + template + inline bool database:: + query_one (const char* q, T& o) + { + return query_one (mssql::query_base (q), o); + } + + template + inline T database:: + query_value (const char* q) + { + return query_value (mssql::query_base (q)); + } + + template + inline typename object_traits::pointer_type database:: + query_one (const std::string& q) + { + return query_one (mssql::query_base (q)); + } + + template + inline bool database:: + query_one (const std::string& q, T& o) + { + return query_one (mssql::query_base (q), o); + } + + template + inline T database:: + query_value (const std::string& q) + { + return query_value (mssql::query_base (q)); + } + + template + inline typename object_traits::pointer_type database:: + query_one (const mssql::query_base& q) + { + // T is always object_type. We also don't need to check for transaction + // here; object_traits::query () does this. + // + return query_one_ (q); + } + + template + inline bool database:: + query_one (const mssql::query_base& q, T& o) + { + // T is always object_type. We also don't need to check for transaction + // here; object_traits::query () does this. + // + return query_one_ (q, o); + } + + template + inline T database:: + query_value (const mssql::query_base& q) + { + // T is always object_type. We also don't need to check for transaction + // here; object_traits::query () does this. + // + return query_value_ (q); + } + + template + inline typename object_traits::pointer_type database:: + query_one (const odb::query_base& q) + { + // Translate to native query. + // + return query_one (mssql::query_base (q)); + } + + template + inline bool database:: + query_one (const odb::query_base& q, T& o) + { + // Translate to native query. + // + return query_one (mssql::query_base (q), o); + } + + template + inline T database:: + query_value (const odb::query_base& q) + { + // Translate to native query. + // + return query_value (mssql::query_base (q)); + } + + template inline prepared_query database:: prepare_query (const char* n, const char* q) { -- cgit v1.1