diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-11-06 18:06:31 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-11-06 18:06:31 +0200 |
commit | 7c715b18cb0c675ba110921c28a94961b3ca481b (patch) | |
tree | 87dc8a0bf7aec46597b075ec96164ae584e1f78e /common/composite/driver.cxx | |
parent | d10d9fb09bf53e088c3c54120763b650fd77acd8 (diff) |
Perform two iterations of the test
Diffstat (limited to 'common/composite/driver.cxx')
-rw-r--r-- | common/composite/driver.cxx | 168 |
1 files changed, 90 insertions, 78 deletions
diff --git a/common/composite/driver.cxx b/common/composite/driver.cxx index b1221da..05d7298 100644 --- a/common/composite/driver.cxx +++ b/common/composite/driver.cxx @@ -28,85 +28,97 @@ main (int argc, char* argv[]) { 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; - - // - // + for (unsigned short i (0); i < 2; ++i) { - 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 (); + 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; + + // persist + // + { + transaction t (db->begin ()); + db->persist (p); + t.commit (); + } + + // load & check + // + { + 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; + + // update + // + { + transaction t (db->begin ()); + db->update (p); + t.commit (); + } + + // load & check + // + { + 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; + + // query + // + { + transaction t (db->begin ()); + + result r (db->query<person> (query::name::first == "Joe")); + + assert (r.size () == 1); + assert (*r.begin () == p); + + t.commit (); + } + + // query + // + { + transaction t (db->begin ()); + + result r (db->query<person> (query::name::flags::alias)); + + assert (r.size () == 1); + assert (*r.begin () == p); + + t.commit (); + } + + // erase + // + if (i == 0) + { + transaction t (db->begin ()); + db->erase<person> (1); + t.commit (); + } } } catch (const odb::exception& e) |