From 64b27b86025d160e49bf617143d80671ccb1e0e4 Mon Sep 17 00:00:00 2001 From: Michael Shepanski Date: Wed, 5 Nov 2014 14:23:54 +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). --- common/view/driver.cxx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'common/view') diff --git a/common/view/driver.cxx b/common/view/driver.cxx index 7ef8272..28c3ba0 100644 --- a/common/view/driver.cxx +++ b/common/view/driver.cxx @@ -76,6 +76,25 @@ view2_test (const auto_ptr& db) assert (i->count == 2); } + { + auto_ptr v (db->query_one ()); + assert (v->count == 4); + } + + { + auto_ptr v; + if (db->id () != odb::id_oracle) + v.reset (db->query_one ("age < 31")); + else + v.reset (db->query_one ("\"age\" < 31")); + assert (v->count == 2); + } + + { + auto_ptr v (db->query_one (query::age < 31)); + assert (v->count == 2); + } + t.commit (); } -- cgit v1.1