diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-01-26 12:43:17 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-01-26 12:43:17 +0200 |
commit | d3905b172b7d3cd1df933f57072aee652d10c186 (patch) | |
tree | a0c65d355d29285dce239b0d2328c168118e3646 /common/schema/driver.cxx | |
parent | 32b8b828dc0e8ffea918c8cf9f07ba213ef63724 (diff) |
Implement support for database schema
New pragma qualifier: namespace. New pragma specifier: schema. The table
specifier was extended to accept a schema prefix. New option: --default-
schema. The common/schema test was extended to cover the new functionality.
Diffstat (limited to 'common/schema/driver.cxx')
-rw-r--r-- | common/schema/driver.cxx | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/common/schema/driver.cxx b/common/schema/driver.cxx index b53464c..eb1358e 100644 --- a/common/schema/driver.cxx +++ b/common/schema/driver.cxx @@ -3,7 +3,7 @@ // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file -// Test database schema creation. +// Test various aspects of database schema. // #include <memory> // std::auto_ptr @@ -28,11 +28,81 @@ main (int argc, char* argv[]) { auto_ptr<database> db (create_database (argc, argv)); + // Test database schema (aka database namespace). // - // - cout << "test 001" << endl; + using ns::object2; + + object2 o2; + o2.id = "aaa"; + o2.nums.push_back (1); + o2.nums.push_back (2); + o2.nums.push_back (3); + o2.obj1 = new object1; + o2.obj1->str = "aaa"; + + { + transaction t (db->begin ()); + db->persist (o2.obj1); + db->persist (o2); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<object2> p2 (db->load<object2> ("aaa")); + t.commit (); + + assert (o2 == *p2); + } + + { + typedef odb::query<object2> query; + typedef odb::result<object2> result; + + transaction t (db->begin ()); + + { + result r (db->query<object2> (query::id == "aaa")); + assert (size (r) == 1); + } + + { + result r (db->query<object2> (query::obj1->str == "aaa")); + assert (size (r) == 1); + } + + t.commit (); + } + + { + typedef odb::query<object_view> query; + typedef odb::result<object_view> result; + + transaction t (db->begin ()); + + result r (db->query<object_view> (query::object2::id == "aaa")); + + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->id2 == "aaa" && i->str == "aaa"); + assert (++i == r.end ()); + + t.commit (); + } + { + typedef odb::query<table_view> query; + typedef odb::result<table_view> result; + transaction t (db->begin ()); + + result r (db->query<table_view> ()); + + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->str == "aaa"); + assert (++i == r.end ()); + t.commit (); } } |