aboutsummaryrefslogtreecommitdiff
path: root/query/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:29:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:29:43 +0200
commitf2955b7052e571eb4af0ad8194970f29e4b4ff9b (patch)
tree8b2a4e4fc37e742bd001e2fa35cfbb0c92fbe729 /query/driver.cxx
parent037ecbd0b2ed37880a670de33d2ac9ead53e5acb (diff)
Add support for value wrappers
Wrapper is a class that wraps another type. Examples of wrappers are various smart pointers, holders, etc. A wrapper can be transparent or it can handle the NULL semantics. The new odb::nullable class template is a NULL wrapper that helps to add the NULL semantics to a value type. New test: common/wrapper.
Diffstat (limited to 'query/driver.cxx')
-rw-r--r--query/driver.cxx24
1 files changed, 20 insertions, 4 deletions
diff --git a/query/driver.cxx b/query/driver.cxx
index 5b7c926..1be6107 100644
--- a/query/driver.cxx
+++ b/query/driver.cxx
@@ -27,7 +27,12 @@ print (result& r)
{
for (result::iterator i (r.begin ()); i != r.end (); ++i)
{
- cout << i->first () << " " << i->last () << " " << i->age () << endl;
+ cout << i->first () << " ";
+
+ if (!i->middle ().null ())
+ cout << i->middle ().get () << " ";
+
+ cout << i->last () << " " << i->age () << endl;
}
cout << endl;
@@ -48,9 +53,9 @@ main (int argc, char* argv[])
p.push_back (person ("John", "Doe", 21));
p.push_back (person ("John", "Smith", 22));
p.push_back (person ("Jack", "Johnson", 31));
- p.push_back (person ("John", "Jackson", 32));
- p.push_back (person ("Jane", "Doe", 23));
- p.push_back (person ("Jane", "Smith", 24));
+ p.push_back (person ("John", "JJ", "Jackson", 32));
+ p.push_back (person ("Jane", "JD", "Doe", 23));
+ p.push_back (person ("Jane", "JS", "Smith", 24));
transaction t (db->begin ());
@@ -174,6 +179,17 @@ main (int argc, char* argv[])
t.commit ();
}
+
+ // Query that shows how to test for NULL values using the
+ // is_null()/is_not_null() functions.
+ //
+ {
+ transaction t (db->begin ());
+ result r (db->query<person> (query::middle.is_not_null ()));
+ print (r);
+ t.commit ();
+ }
+
}
catch (const odb::exception& e)
{