aboutsummaryrefslogtreecommitdiff
path: root/common/composite
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-06 18:06:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-06 18:06:31 +0200
commit7c715b18cb0c675ba110921c28a94961b3ca481b (patch)
tree87dc8a0bf7aec46597b075ec96164ae584e1f78e /common/composite
parentd10d9fb09bf53e088c3c54120763b650fd77acd8 (diff)
Perform two iterations of the test
Diffstat (limited to 'common/composite')
-rw-r--r--common/composite/driver.cxx168
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)