diff options
Diffstat (limited to 'common/virtual')
-rw-r--r-- | common/virtual/driver.cxx | 25 | ||||
-rw-r--r-- | common/virtual/test.hxx | 35 |
2 files changed, 59 insertions, 1 deletions
diff --git a/common/virtual/driver.cxx b/common/virtual/driver.cxx index 05acfcb..1083cab 100644 --- a/common/virtual/driver.cxx +++ b/common/virtual/driver.cxx @@ -119,6 +119,31 @@ main (int argc, char* argv[]) t.commit (); } } + + // Use virtual data members to implement multi-member composite object id. + // + { + using namespace test3; + + person o; + o.first_ = "John"; + o.last_ = "Doe"; + + name id; + { + transaction t (db->begin ()); + id = db->persist (o); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr<person> p (db->load<person> (id)); + t.commit (); + + assert (o.first_ == p->first_ && o.last_ == p->last_); + } + } } catch (const odb::exception& e) { diff --git a/common/virtual/test.hxx b/common/virtual/test.hxx index 3c0b0f1..a6caf2c 100644 --- a/common/virtual/test.hxx +++ b/common/virtual/test.hxx @@ -22,7 +22,7 @@ namespace test1 #pragma db transient std::string s; - #pragma db member(s_) virtual(std::string) access (s) + #pragma db member(s_) virtual(std::string) access(s) bool operator== (const comp& v) const { @@ -136,4 +136,37 @@ namespace test2 }; } +// Use virtual data members to implement multi-member composite object id. +// +#pragma db namespace table("t3_") +namespace test3 +{ + #pragma db value + struct name + { + name () {} + name (std::string const& f, std::string const& l) + : first (f), last(l) {} + + std::string first; + std::string last; + + bool operator< (const name& x) const + { + return first < x.first || (first == x.first && last < x.last); + } + }; + + #pragma db object transient + struct person + { + std::string first_; + std::string last_; + + #pragma db member(name) virtual(name) id \ + get(::test3::name (this.first_, this.last_)) \ + set(this.first_ = (?).first; this.last_ = (?).last) + }; +} + #endif // TEST_HXX |