diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-17 11:11:43 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-17 12:04:03 +0200 |
commit | 4c893bdef4b57193438e57b09627560e53f3e6d8 (patch) | |
tree | 01f518013ad26589e1e31f13deec7a98666791f7 /common/composite-id | |
parent | 24ea8fc0e06479e2c14b9ce78a95c138939c5204 (diff) |
Add support for defining composite values inside persistent classes, etc
Diffstat (limited to 'common/composite-id')
-rw-r--r-- | common/composite-id/driver.cxx | 26 | ||||
-rw-r--r-- | common/composite-id/test.hxx | 47 |
2 files changed, 73 insertions, 0 deletions
diff --git a/common/composite-id/driver.cxx b/common/composite-id/driver.cxx index 86d13b0..f8773d5 100644 --- a/common/composite-id/driver.cxx +++ b/common/composite-id/driver.cxx @@ -695,6 +695,32 @@ main (int argc, char* argv[]) assert (p3->o1[1] == 0); } } + + // Test 9. + { + using namespace test9; + + object o (123, "abc"); + o.v.push_back (123); + + // persist + // + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + // load & check + // + { + transaction t (db->begin ()); + result<object> r (db->query<object> ()); + result<object>::iterator i (r.begin ()); + assert (i != r.end () && o == *i && ++i == r.end ()); + t.commit (); + } + } } catch (const odb::exception& e) { diff --git a/common/composite-id/test.hxx b/common/composite-id/test.hxx index a2773d0..adf9495 100644 --- a/common/composite-id/test.hxx +++ b/common/composite-id/test.hxx @@ -470,4 +470,51 @@ namespace test8 }; } +// Test composite id definition inside object. +// +#pragma db namespace table("t9_") +namespace test9 +{ + #pragma db object + struct object + { + object (unsigned long n = 0, const std::string& s = "") + { + id_.num = n; + id_.str = s; + } + + unsigned long num () const {return id_.num;} + const std::string& str () const {return id_.str;} + + std::vector<int> v; + + private: + friend class odb::access; + + #pragma db value + struct comp + { + unsigned long num; + std::string str; + + bool + operator< (const comp& x) const + { + return num < x.num || (num == x.num && str < x.str); + } + }; + + #pragma db id + comp id_; + }; + + inline bool + operator== (const object& x, const object& y) + { + return x.num () == y.num () && x.str () == y.str () && x.v == y.v; + } +} + + #endif // TEST_HXX |