aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shepanski <michael@codesynthesis.com>2014-11-04 16:10:03 +1100
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-10 16:52:17 +0200
commit0d695ddc84b574646b62c9be8ce45570ac3656c4 (patch)
tree65286bfbd79883f91f62e9fdbff3e37ffe75f9bd
parenta881873f216c6311118449ee433ac6cfcd7904a6 (diff)
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).
-rw-r--r--odb/oracle/database.hxx62
-rw-r--r--odb/oracle/database.ixx120
2 files changed, 182 insertions, 0 deletions
diff --git a/odb/oracle/database.hxx b/odb/oracle/database.hxx
index 3fe5de2..d40611f 100644
--- a/odb/oracle/database.hxx
+++ b/odb/oracle/database.hxx
@@ -290,6 +290,68 @@ namespace odb
result<T>
query (const odb::query_base&);
+ // Query one API.
+ //
+ template <typename T>
+ typename object_traits<T>::pointer_type
+ query_one ();
+
+ template <typename T>
+ bool
+ query_one (T& object);
+
+ template <typename T>
+ T
+ query_value ();
+
+ template <typename T>
+ typename object_traits<T>::pointer_type
+ query_one (const char*);
+
+ template <typename T>
+ bool
+ query_one (const char*, T& object);
+
+ template <typename T>
+ T
+ query_value (const char*);
+
+ template <typename T>
+ typename object_traits<T>::pointer_type
+ query_one (const std::string&);
+
+ template <typename T>
+ bool
+ query_one (const std::string&, T& object);
+
+ template <typename T>
+ T
+ query_value (const std::string&);
+
+ template <typename T>
+ typename object_traits<T>::pointer_type
+ query_one (const oracle::query_base&);
+
+ template <typename T>
+ bool
+ query_one (const oracle::query_base&, T& object);
+
+ template <typename T>
+ T
+ query_value (const oracle::query_base&);
+
+ template <typename T>
+ typename object_traits<T>::pointer_type
+ query_one (const odb::query_base&);
+
+ template <typename T>
+ bool
+ query_one (const odb::query_base&, T& object);
+
+ template <typename T>
+ T
+ query_value (const odb::query_base&);
+
// Query preparation.
//
template <typename T>
diff --git a/odb/oracle/database.ixx b/odb/oracle/database.ixx
index 8f46e7a..d3b56ae 100644
--- a/odb/oracle/database.ixx
+++ b/odb/oracle/database.ixx
@@ -429,6 +429,126 @@ namespace odb
}
template <typename T>
+ inline typename object_traits<T>::pointer_type database::
+ query_one ()
+ {
+ return query_one<T> (oracle::query_base ());
+ }
+
+ template <typename T>
+ inline bool database::
+ query_one (T& o)
+ {
+ return query_one<T> (oracle::query_base (), o);
+ }
+
+ template <typename T>
+ inline T database::
+ query_value ()
+ {
+ return query_value<T> (oracle::query_base ());
+ }
+
+ template <typename T>
+ inline typename object_traits<T>::pointer_type database::
+ query_one (const char* q)
+ {
+ return query_one<T> (oracle::query_base (q));
+ }
+
+ template <typename T>
+ inline bool database::
+ query_one (const char* q, T& o)
+ {
+ return query_one<T> (oracle::query_base (q), o);
+ }
+
+ template <typename T>
+ inline T database::
+ query_value (const char* q)
+ {
+ return query_value<T> (oracle::query_base (q));
+ }
+
+ template <typename T>
+ inline typename object_traits<T>::pointer_type database::
+ query_one (const std::string& q)
+ {
+ return query_one<T> (oracle::query_base (q));
+ }
+
+ template <typename T>
+ inline bool database::
+ query_one (const std::string& q, T& o)
+ {
+ return query_one<T> (oracle::query_base (q), o);
+ }
+
+ template <typename T>
+ inline T database::
+ query_value (const std::string& q)
+ {
+ return query_value<T> (oracle::query_base (q));
+ }
+
+ template <typename T>
+ inline typename object_traits<T>::pointer_type database::
+ query_one (const oracle::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_<T, id_oracle> (q);
+ }
+
+ template <typename T>
+ inline bool database::
+ query_one (const oracle::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_<T, id_oracle> (q, o);
+ }
+
+ template <typename T>
+ inline T database::
+ query_value (const oracle::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_<T, id_oracle> (q);
+ }
+
+ template <typename T>
+ inline typename object_traits<T>::pointer_type database::
+ query_one (const odb::query_base& q)
+ {
+ // Translate to native query.
+ //
+ return query_one<T> (oracle::query_base (q));
+ }
+
+ template <typename T>
+ inline bool database::
+ query_one (const odb::query_base& q, T& o)
+ {
+ // Translate to native query.
+ //
+ return query_one<T> (oracle::query_base (q), o);
+ }
+
+ template <typename T>
+ inline T database::
+ query_value (const odb::query_base& q)
+ {
+ // Translate to native query.
+ //
+ return query_value<T> (oracle::query_base (q));
+ }
+
+ template <typename T>
inline prepared_query<T> database::
prepare_query (const char* n, const char* q)
{