diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-02 09:22:39 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-09-17 12:04:02 +0200 |
commit | 179eb696191958bae891916eec2708c4d3e34983 (patch) | |
tree | 2fe609f15a0453c92f7bc096b065cd503e2c4d8e /common/container/change-tracking | |
parent | aa12a6286a51c21cbae51ff1d880d10fc6f4e617 (diff) |
Fix UPDATE statement for smart containers with read-only value members
Here we have to include them (think what happens when we erase an element
somewhere in the middle of a container).
Diffstat (limited to 'common/container/change-tracking')
-rw-r--r-- | common/container/change-tracking/driver.cxx | 28 | ||||
-rw-r--r-- | common/container/change-tracking/test.hxx | 33 |
2 files changed, 61 insertions, 0 deletions
diff --git a/common/container/change-tracking/driver.cxx b/common/container/change-tracking/driver.cxx index 78f7a7f..9baf6a2 100644 --- a/common/container/change-tracking/driver.cxx +++ b/common/container/change-tracking/driver.cxx @@ -699,6 +699,34 @@ main (int argc, char* argv[]) t.commit (); } } + + // Test read-only values. + { + ro_object o (1); + o.v.push_back (ro_value (1, 1)); + o.v.push_back (ro_value (2, 2)); + o.v.push_back (ro_value (3, 3)); + + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + o.v.erase (o.v.begin ()); + + { + transaction t (db->begin ()); + db->update (o); + t.commit (); + } + + { + transaction t (db->begin ()); + assert (db->load<ro_object> (1)->v == o.v); + t.commit (); + } + } } catch (const odb::exception& e) { diff --git a/common/container/change-tracking/test.hxx b/common/container/change-tracking/test.hxx index 6281322..edbff0a 100644 --- a/common/container/change-tracking/test.hxx +++ b/common/container/change-tracking/test.hxx @@ -78,4 +78,37 @@ struct inv_object2 odb::vector<inv_object1*> o1; }; +// Test read-only values (we still need to include them in the UPDATE +// statement). +// +#pragma db value +struct ro_value +{ + ro_value (int i_ = 0, int j_ = 0): i (i_), j (j_) {} + + #pragma db readonly + int i; + + #pragma db readonly + int j; +}; + +inline bool +operator== (const ro_value& x, const ro_value& y) +{ + return x.i == y.i && x.j == y.j; +} + +#pragma db object +struct ro_object +{ + ro_object () {} + ro_object (unsigned long id): id_ (id) {} + + #pragma db id + unsigned long id_; + + odb::vector<ro_value> v; +}; + #endif // TEST_HXX |