aboutsummaryrefslogtreecommitdiff
path: root/common/composite
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-09-17 11:11:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-09-17 12:04:03 +0200
commit4c893bdef4b57193438e57b09627560e53f3e6d8 (patch)
tree01f518013ad26589e1e31f13deec7a98666791f7 /common/composite
parent24ea8fc0e06479e2c14b9ce78a95c138939c5204 (diff)
Add support for defining composite values inside persistent classes, etc
Diffstat (limited to 'common/composite')
-rw-r--r--common/composite/driver.cxx28
-rw-r--r--common/composite/test.hxx48
2 files changed, 76 insertions, 0 deletions
diff --git a/common/composite/driver.cxx b/common/composite/driver.cxx
index 0d61a3c..45ca09d 100644
--- a/common/composite/driver.cxx
+++ b/common/composite/driver.cxx
@@ -191,6 +191,34 @@ main (int argc, char* argv[])
assert (o == *o1);
}
}
+
+ // Test composite definition inside object.
+ {
+ using namespace test4;
+
+ object o (1);
+ o.str ("abc");
+ o.x (123);
+ o.y (234);
+
+ // persist
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ // load & check
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> o1 (db->load<object> (1));
+ t.commit ();
+
+ assert (o == *o1);
+ }
+ }
}
catch (const odb::exception& e)
{
diff --git a/common/composite/test.hxx b/common/composite/test.hxx
index 040d39c..8bf4b97 100644
--- a/common/composite/test.hxx
+++ b/common/composite/test.hxx
@@ -170,5 +170,53 @@ namespace test3
}
}
+// Test composite definition inside object.
+//
+#pragma db namespace table("t4_")
+namespace test4
+{
+ #pragma db object
+ struct object
+ {
+ object (unsigned long id = 0): id_ (id) {}
+
+ unsigned long id () const {return id_;}
+
+ void str (const std::string& s) {c_.str = s;}
+ const std::string& str () const {return c_.str;}
+
+ void x (int i) {p_.first = i;}
+ int x () const {return p_.first;}
+
+ void y (int i) {p_.second = i;}
+ int y () const {return p_.second;}
+
+ private:
+ friend class odb::access;
+
+ #pragma db id
+ unsigned long id_;
+
+ #pragma db value
+ struct comp
+ {
+ std::string str;
+ };
+
+ comp c_;
+
+ typedef std::pair<int, int> int_pair;
+ #pragma db value(int_pair)
+
+ int_pair p_;
+ };
+
+ inline bool
+ operator== (const object& x, const object& y)
+ {
+ return x.id () == y.id () && x.str () == y.str () &&
+ x.x () == y.x () && x.y () == y.y ();
+ }
+}
#endif // TEST_HXX