aboutsummaryrefslogtreecommitdiff
path: root/odb/prepared-query.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-10-04 11:33:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-10-19 11:38:24 +0200
commitf101a400442692f349822ab1d9119bca5d2b7240 (patch)
treee046f3b727226810d08813cc4c7a55244937f275 /odb/prepared-query.hxx
parentbe97326d67365e16175cc599e23348feaf80e0fe (diff)
Initial support for prepared queries
Diffstat (limited to 'odb/prepared-query.hxx')
-rw-r--r--odb/prepared-query.hxx65
1 files changed, 65 insertions, 0 deletions
diff --git a/odb/prepared-query.hxx b/odb/prepared-query.hxx
new file mode 100644
index 0000000..60ae48d
--- /dev/null
+++ b/odb/prepared-query.hxx
@@ -0,0 +1,65 @@
+// file : odb/prepared-query.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_PREPARED_QUERY_HXX
+#define ODB_PREPARED_QUERY_HXX
+
+#include <odb/pre.hxx>
+
+#include <odb/forward.hxx>
+#include <odb/traits.hxx>
+#include <odb/result.hxx>
+
+#include <odb/details/export.hxx>
+#include <odb/details/shared-ptr.hxx>
+
+namespace odb
+{
+ struct LIBODB_EXPORT prepared_query_impl: details::shared_base
+ {
+ virtual
+ ~prepared_query_impl ();
+
+ const char* name;
+ details::shared_ptr<result_impl> (*execute) (prepared_query_impl&);
+ };
+
+ template <typename T>
+ struct prepared_query
+ {
+ result<T>
+ execute (bool cache = true)
+ {
+ typedef
+ typename result_base<T, class_traits<T>::kind>::result_impl_type
+ derived_type;
+
+ details::shared_ptr<result_impl> ri (impl_->execute (*impl_));
+ result<T> r (
+ details::shared_ptr<derived_type> (
+ static_cast<derived_type*> (ri.release ())));
+
+ if (cache)
+ r.cache ();
+
+ return r;
+ }
+
+ explicit
+ prepared_query (details::shared_ptr<prepared_query_impl> impl)
+ : impl_ (impl) {}
+
+ private:
+ details::shared_ptr<prepared_query_impl> impl_;
+ };
+
+ namespace core
+ {
+ using odb::prepared_query;
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_PREPARED_QUERY_HXX