aboutsummaryrefslogtreecommitdiff
path: root/view/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-02-04 17:23:54 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-02-04 17:23:54 +0200
commit0ac8f52ddfae8537651c65b8ab8b32db47756e74 (patch)
treebe6239b8e7f528c7c25a05f83af2ec806043fbd6 /view/driver.cxx
parent613da395f986ff748448d5afc06319f84a734397 (diff)
Implement object loading views
See section 10.2 in the manual for details.
Diffstat (limited to 'view/driver.cxx')
-rw-r--r--view/driver.cxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/view/driver.cxx b/view/driver.cxx
index cbe26ee..74d6eed 100644
--- a/view/driver.cxx
+++ b/view/driver.cxx
@@ -277,6 +277,44 @@ main (int argc, char* argv[])
t.commit ();
}
+ // The same but using the object loading view.
+ //
+ {
+ typedef odb::query<employee_country_objects> query;
+ typedef odb::result<employee_country_objects> result;
+
+ transaction t (db->begin ());
+
+ // We have to use a session in order for the object pointers
+ // in our view and object pointers inside objects that we load
+ // to point to the same instances, where appropriate.
+ //
+ session s;
+
+ result r (db->query<employee_country_objects> (
+ query::res::name == query::nat::name));
+
+ cout << "Employees residing inside the country of nationality" << endl;
+
+ for (result::iterator i (r.begin ()); i != r.end (); ++i)
+ {
+ assert (i->e->nationality () == i->nat);
+ assert (i->e->residence () == i->res);
+
+ const employee& e (*i->e);
+ const country& r (*i->res);
+ const country& n (*i->nat);
+
+ cout << " " << e.first () << " " << e.last () << " "
+ << r.name () << " " << n.name () << endl;
+ }
+
+ cout << endl;
+
+ t.commit ();
+ }
+
+
// Get the list of employees that have accumulated vacation days.
//
{