diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-10-27 17:36:59 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-10-27 17:36:59 +0200 |
commit | d07b467fba9030ddb6940e7c9451f15201faa23d (patch) | |
tree | 8df906c35b173144fa220ff3d79192a2a2ffd837 /common/composite/driver.cxx | |
parent | f4c94ca015b123ec01037e521582d3a04f4c4b81 (diff) |
Implement support for composite value types
New test: common/composite.
Diffstat (limited to 'common/composite/driver.cxx')
-rw-r--r-- | common/composite/driver.cxx | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/common/composite/driver.cxx b/common/composite/driver.cxx new file mode 100644 index 0000000..b1221da --- /dev/null +++ b/common/composite/driver.cxx @@ -0,0 +1,117 @@ +// file : common/composite/driver.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test composite value types. +// + +#include <memory> // std::auto_ptr +#include <cassert> +#include <iostream> + +#include <odb/database.hxx> +#include <odb/transaction.hxx> + +#include <common/common.hxx> + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr<database> db (create_database (argc, argv)); + + person p (1); + p.name_.first = "Joe"; + p.name_.last = "Dirt"; + p.name_.title = "Mr"; + p.name_.alias.first = "Anthony"; + p.name_.alias.last = "Clean"; + p.name_.nick = "Squeaky"; + p.name_.flags.nick = true; + p.name_.flags.alias = false; + p.age_ = 32; + + // + // + { + transaction t (db->begin ()); + db->persist (p); + t.commit (); + } + + // + // + { + transaction t (db->begin ()); + auto_ptr<person> p1 (db->load<person> (1)); + t.commit (); + + assert (p == *p1); + } + + p.name_.title = "Mrs"; + p.name_.alias.first = "Anthonia"; + p.name_.flags.nick = false; + p.name_.flags.alias = true; + + // + // + { + transaction t (db->begin ()); + db->update (p); + t.commit (); + } + + // + // + { + transaction t (db->begin ()); + auto_ptr<person> p1 (db->load<person> (1)); + t.commit (); + + assert (p == *p1); + } + + typedef odb::query<person> query; + typedef odb::result<person> result; + + // + // + { + transaction t (db->begin ()); + + result r (db->query<person> (query::name::first == "Joe")); + + assert (r.size () == 1); + assert (*r.begin () == p); + + t.commit (); + } + + // + // + { + transaction t (db->begin ()); + + result r (db->query<person> (query::name::flags::alias)); + + assert (r.size () == 1); + assert (*r.begin () == p); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} |