aboutsummaryrefslogtreecommitdiff
path: root/prepared
diff options
context:
space:
mode:
authorMichael Shepanski <michael@codesynthesis.com>2014-11-06 16:33:35 +1100
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-10 16:48:13 +0200
commit51a01cfebf933d270bf7b7fadb0fb3ca3b7a4cd5 (patch)
tree40ca9efb48c65e88822bcb7538d64bf1299d7aaf /prepared
parentf7d0e9c620d7c3117074e2618f2bc75699d6f2f0 (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).
Diffstat (limited to 'prepared')
-rw-r--r--prepared/driver.cxx9
1 files changed, 4 insertions, 5 deletions
diff --git a/prepared/driver.cxx b/prepared/driver.cxx
index 7d561a9..d805ddb 100644
--- a/prepared/driver.cxx
+++ b/prepared/driver.cxx
@@ -206,7 +206,6 @@ main (int argc, char* argv[])
{
typedef odb::query<person_count> query;
typedef odb::prepared_query<person_count> prep_query;
- typedef odb::result<person_count> result;
transaction t (db->begin ());
@@ -215,11 +214,11 @@ main (int argc, char* argv[])
prep_query pq (
db->prepare_query<person_count> ("person-count-age-query", q));
+ // Because an aggregate query result always contains one element,
+ // we use execute_value() insetad of execute() as a shortcut:
+ //
for (age = 90; age > 40; age -= 10)
- {
- result r (pq.execute ());
- cout << "over " << age << ": " << r.begin ()->count << endl;
- }
+ cout << "over " << age << ": " << pq.execute_value ().count << endl;
t.commit ();
}