aboutsummaryrefslogtreecommitdiff
path: root/common/prepared/driver.cxx
diff options
context:
space:
mode:
authorMichael Shepanski <michael@codesynthesis.com>2014-10-22 16:42:05 +0200
committerMichael Shepanski <michael@codesynthesis.com>2014-10-30 15:23:57 +1100
commitdee5f10d1d75eee43596ad1dfb47ecec9e0b1307 (patch)
tree75deb3233adc5cb970a77227f1ebbb4176b9af9a /common/prepared/driver.cxx
parent53d936af40ca044289695404d577e99f6cca2304 (diff)
Allow lambdas & std::functions as query factories with C++-98 builds of libodb
Diffstat (limited to 'common/prepared/driver.cxx')
-rw-r--r--common/prepared/driver.cxx46
1 files changed, 43 insertions, 3 deletions
diff --git a/common/prepared/driver.cxx b/common/prepared/driver.cxx
index 5c622c0..dfbdf13 100644
--- a/common/prepared/driver.cxx
+++ b/common/prepared/driver.cxx
@@ -249,7 +249,7 @@ main (int argc, char* argv[])
}
db->query_factory ("person-params-query",
- database::query_factory_type ());
+ database::query_factory_ptr ());
}
// Cached query with wildcard factory.
@@ -273,7 +273,7 @@ main (int argc, char* argv[])
t.commit ();
}
- db->query_factory ("", database::query_factory_type ());
+ db->query_factory ("", database::query_factory_ptr ());
}
// Cached query with lambda factory.
@@ -312,7 +312,47 @@ main (int argc, char* argv[])
}
db->query_factory ("person-params-query-2",
- database::query_factory_type ());
+ database::query_factory_ptr ());
+ }
+
+ // Cached query with lambda factory using closure. Forces nonoptimized
+ // representation of std::function.
+ //
+ {
+ const std::string person_name ("John First");
+
+ db->query_factory (
+ "person-params-query-3",
+ [person_name] (const char* name, connection& c)
+ {
+ typedef odb::query<person> query;
+
+ prepared_query<person> pq (
+ c.prepare_query<person> (
+ name,
+ query::age > 50 && query::name != person_name));
+ c.cache_query (pq);
+ });
+
+ {
+ transaction t (db->begin ());
+
+ prep_query pq (db->lookup_query<person> ("person-params-query-3"));
+ assert (pq);
+
+ result r (pq.execute ());
+ assert (size (r) == 4);
+
+ t.commit ();
+ }
+
+ db->query_factory ("person-params-query-3",
+#ifdef HAVE_CXX11_NULLPTR
+ nullptr
+#else
+ database::query_factory_ptr ()
+#endif
+ );
}
#endif