aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-02-05 15:50:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-02-05 15:50:08 +0200
commit43fa55c1b8e389838c83be933bb30a2caaf7468d (patch)
tree310bc0ecc43ea38276a7e8ff2a541f2cba395333
parent3eee63801cbe833f6557d6f85c5778b6209140be (diff)
Add support for change-tracking containers
ODB now supports "smart" ordered containers. Such containers get extra functions for updating and deleting individual elements. Based on this functionality implement two change-tracking containers: odb::vector (equivalent to std::vector) and QOdbList (equivalent to QList). New tests: common/container/change-tracking and qt/common/container/change- tracking.
-rw-r--r--common/container/basics/driver.cxx (renamed from common/container/driver.cxx)4
-rw-r--r--common/container/basics/makefile (renamed from common/container/makefile)14
-rw-r--r--common/container/basics/test.hxx (renamed from common/container/test.hxx)2
-rw-r--r--common/container/basics/test.std (renamed from common/container/test.std)0
-rw-r--r--common/container/change-tracking/driver.cxx694
-rw-r--r--common/container/change-tracking/makefile115
-rw-r--r--common/container/change-tracking/test.hxx81
-rw-r--r--common/container/change-tracking/test.std (renamed from qt/common/containers/test.std)0
-rw-r--r--common/makefile85
-rw-r--r--qt/common/containers/basics/driver.cxx (renamed from qt/common/containers/driver.cxx)4
-rw-r--r--qt/common/containers/basics/makefile (renamed from qt/common/containers/makefile)14
-rw-r--r--qt/common/containers/basics/test.hxx (renamed from qt/common/containers/test.hxx)2
-rw-r--r--qt/common/containers/basics/test.std0
-rw-r--r--qt/common/containers/change-tracking/driver.cxx632
-rw-r--r--qt/common/containers/change-tracking/makefile126
-rw-r--r--qt/common/containers/change-tracking/test.hxx43
-rw-r--r--qt/common/containers/change-tracking/test.std0
-rw-r--r--qt/common/makefile9
18 files changed, 1759 insertions, 66 deletions
diff --git a/common/container/driver.cxx b/common/container/basics/driver.cxx
index c4e1179..b50ab5a 100644
--- a/common/container/driver.cxx
+++ b/common/container/basics/driver.cxx
@@ -1,8 +1,8 @@
-// file : common/container/driver.cxx
+// file : common/container/basics/driver.cxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
-// Test container persistence.
+// Test basic container persistence.
//
#include <memory> // std::auto_ptr
diff --git a/common/container/makefile b/common/container/basics/makefile
index 7173c57..58feb3b 100644
--- a/common/container/makefile
+++ b/common/container/basics/makefile
@@ -1,8 +1,8 @@
-# file : common/container/makefile
+# file : common/container/basics/makefile
# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
# license : GNU GPL v2; see accompanying LICENSE file
-include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
cxx_tun := driver.cxx
odb_hdr := test.hxx
@@ -35,7 +35,7 @@ gen := $(addprefix $(out_base)/,$(genf))
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \
---table-prefix t_container_
+--table-prefix t_cont_bs_
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
@@ -58,10 +58,10 @@ $(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \
$(call vc10projs,$(name)) $(call vc11projs,$(name))
$(dist):
$(call dist-data,$(sources) $(headers) $(data_dist))
- $(call meta-automake,../template/Makefile.am)
- $(call meta-vc9projs,../template/template,$(name))
- $(call meta-vc10projs,../template/template,$(name))
- $(call meta-vc11projs,../template/template,$(name))
+ $(call meta-automake,../../template/Makefile.am)
+ $(call meta-vc9projs,../../template/template,$(name))
+ $(call meta-vc10projs,../../template/template,$(name))
+ $(call meta-vc11projs,../../template/template,$(name))
# Test.
#
diff --git a/common/container/test.hxx b/common/container/basics/test.hxx
index c531efb..e88edd9 100644
--- a/common/container/test.hxx
+++ b/common/container/basics/test.hxx
@@ -1,4 +1,4 @@
-// file : common/container/test.hxx
+// file : common/container/basics/test.hxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
diff --git a/common/container/test.std b/common/container/basics/test.std
index e69de29..e69de29 100644
--- a/common/container/test.std
+++ b/common/container/basics/test.std
diff --git a/common/container/change-tracking/driver.cxx b/common/container/change-tracking/driver.cxx
new file mode 100644
index 0000000..98d711c
--- /dev/null
+++ b/common/container/change-tracking/driver.cxx
@@ -0,0 +1,694 @@
+// file : common/container/change-tracking/driver.cxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test change-tracking containers.
+//
+
+#include <common/config.hxx> // HAVE_CXX11
+
+#include <memory> // std::auto_ptr
+#include <cassert>
+#include <iostream>
+
+#ifdef HAVE_CXX11
+# include <utility> // std::move
+#endif
+
+#include <odb/tracer.hxx>
+#include <odb/session.hxx>
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+
+#include <common/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+using namespace std;
+using namespace odb::core;
+
+struct counting_tracer: odb::tracer
+{
+ void
+ reset (transaction& tr) {u = i = d = s = t = 0; tr.tracer (*this);}
+
+ virtual void
+ execute (odb::connection&, const char* stmt)
+ {
+ string p (stmt, 6);
+ if (p == "UPDATE")
+ u++;
+ else if (p == "INSERT")
+ i++;
+ else if (p == "DELETE")
+ d++;
+ else if (p == "SELECT")
+ s++;
+ t++;
+ }
+
+ size_t u, i, d, s, t;
+};
+
+static counting_tracer tr;
+
+// Compilation test: instantiate all the functions. In C++11 mode only
+// do this if we have a fairly conforming compiler that implements the
+// complete std::vector interface.
+//
+
+#if defined (HAVE_CXX11)
+#if defined (__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 7
+struct item {};
+template class odb::vector<item>;
+template class odb::vector_iterator<odb::vector<item>,
+ std::vector<item>::iterator>;
+template class odb::vector_iterator<odb::vector<item>,
+ std::vector<item>::reverse_iterator>;
+#endif
+#endif
+
+void
+f (const std::vector<int>&) {}
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ // Test extended interface.
+ //
+ {
+ typedef odb::vector<int> vector;
+
+ vector ov;
+ std::vector<int> sv;
+ f (ov); // Implicit conversion to std::vector.
+ vector ov1 (sv); // Initialization from std::vector.
+ ov = sv; // Assignement from std::vector.
+
+ // Container comparison.
+ //
+ if (ov != ov1 ||
+ ov != sv ||
+ sv != ov1)
+ ov.clear ();
+
+ // Iterator comparison/conversion.
+ //
+ vector::const_iterator i (ov.begin ());
+ if (i != ov.end ())
+ i = ov.end ();
+
+ vector::const_reverse_iterator j (ov.rbegin ());
+ if (j != ov.rend ())
+ j = ov.rend ();
+ }
+
+ auto_ptr<database> db (create_database (argc, argv));
+
+ // Test traits logic.
+ //
+ {
+ object o ("1");
+ o.i = 123;
+ o.s.push_back ("a");
+
+ assert (!o.s._tracking ());
+
+ // persist
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ assert (o.s._tracking ());
+
+ // load
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p (db->load<object> ("1"));
+ assert (p->s._tracking ());
+ t.commit ();
+ }
+
+ // update
+ //
+ {
+ transaction t (db->begin ());
+ db->update (o);
+ t.commit ();
+ }
+
+ assert (o.s._tracking ());
+
+ // erase
+ //
+ {
+ transaction t (db->begin ());
+ db->erase (o);
+ t.commit ();
+ }
+
+ assert (!o.s._tracking ());
+ }
+
+ // Test change tracking.
+ //
+ object o ("1");
+ o.i = 123;
+ o.s.push_back ("a");
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ // push_back/pop_back
+ //
+ {
+ o.s.push_back ("b"); // insert
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.i == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.pop_back ();
+ o.s.push_back ("c"); // update
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 2 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.pop_back ();
+ for (int i (0); i != 1024; ++i)
+ o.s.push_back ("x"); // realloc
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 2 && tr.i == 1023 && tr.t == 1025);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ for (int i (0); i != 1024; ++i)
+ o.s.pop_back (); // delete
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.d == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.push_back ("b");
+ o.s.pop_back (); // no-op
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.t == 1);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // insert
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.insert (o.s.begin (), "a1"); // insert front
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.i == 1 && tr.t == 4);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.insert (o.s.begin () + 1, "a2"); // insert middle
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.i == 1 && tr.t == 4);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.insert (o.s.end (), "b1"); // insert back
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.i == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // erase
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.erase (o.s.begin ()); // erase front
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 4 && tr.d == 1 && tr.t == 5);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.erase (o.s.begin () + 1); // erase middle
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 2 && tr.d == 1 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.erase (o.s.end () - 1); // erase back
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.d == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // modify
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.modify (1) += 'b';
+ o.s.modify_at (2) += 'c';
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.modify_front () += 'a';
+ o.s.modify_back () += 'd';
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.begin ().modify () += 'a';
+ o.s.rbegin ().modify () += 'c';
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ (o.s.rbegin () + 1).modify (1) += 'a';
+ (o.s.rbegin () + 1).modify (-1) += 'c';
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.mbegin ();
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 5 && tr.t == 5);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // clear
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.clear ();
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.d == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // assign
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.assign (4, "x");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 4 && tr.i == 1 && tr.t == 5);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // resize
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.pop_back ();
+ o.s.resize (4, "x"); // expand
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 2 && tr.i == 1 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.push_back ("y");
+ o.s.resize (3); // shrink
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.d == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // Transaction rollback.
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ {
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ db->update (o);
+ t.rollback ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.i == 4 && tr.d == 1 && tr.t == 6);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.t == 1);
+ t.commit ();
+ }
+ }
+
+ // Armed copy.
+ //
+ {
+ auto_ptr<object> c;
+
+ {
+ o.s.pop_back ();
+
+ transaction t (db->begin ());
+ db->update (o);
+ c.reset (new object (o));
+ t.rollback ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.i == 3 && tr.d == 1 && tr.t == 5);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.t == 1);
+ t.commit ();
+ }
+ }
+
+ // Armed swap.
+ //
+ {
+ object c (o);
+
+ {
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ db->update (o);
+ assert (o.s._tracking () && !c.s._tracking ());
+ c.s.swap (o.s);
+ assert (!o.s._tracking () && c.s._tracking ());
+ t.rollback ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.i == 4 && tr.d == 1 && tr.t == 6);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.t == 1);
+ t.commit ();
+ }
+ }
+
+ // Armed move.
+ //
+#ifdef HAVE_CXX11
+ {
+ auto_ptr<object> c;
+
+ {
+ o.s.pop_back ();
+
+ transaction t (db->begin ());
+ db->update (o);
+ assert (o.s._tracking ());
+ c.reset (new object (std::move (o)));
+ assert (!o.s._tracking () && c->s._tracking ());
+ t.rollback ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.i == 2 && tr.d == 1 && tr.t == 4);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.t == 1);
+ t.commit ();
+ }
+ }
+#endif
+
+ // Test mixing "smart" and "dumb" container (specifically, erase(obj)).
+ //
+ {
+ mix_object o (1);
+ o.ov.assign (3, 123);
+ o.sv.assign (3, 123);
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ db->erase (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+ }
+
+ // Test using change tracking container as inverse member.
+ //
+ {
+ inv_object1 o1;
+ inv_object2 o2;
+ o1.o2 = &o2;
+
+ {
+ transaction t (db->begin ());
+ db->persist (o2);
+ db->persist (o1);
+ t.commit ();
+ }
+
+ assert (!o2.o1._tracking ());
+
+ {
+ session s;
+ transaction t (db->begin ());
+ auto_ptr<inv_object1> p1 (db->load<inv_object1> (o1.id_));
+ auto_ptr<inv_object2> p2 (db->load<inv_object2> (o2.id_));
+ assert (p2->o1[0] == p1.get ());
+ assert (!p2->o1._tracking ());
+ t.commit ();
+ }
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/common/container/change-tracking/makefile b/common/container/change-tracking/makefile
new file mode 100644
index 0000000..ffd149c
--- /dev/null
+++ b/common/container/change-tracking/makefile
@@ -0,0 +1,115 @@
+# file : common/container/change-tracking/makefile
+# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+odb_hdr := test.hxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+common.l := $(out_root)/libcommon/common/common.l
+common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options
+
+driver := $(out_base)/driver
+dist := $(out_base)/.dist
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/odb/stub.make,\
+ odb: odb,odb-rules: odb_rules)
+
+# Build.
+#
+$(driver): $(cxx_obj) $(common.l)
+$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base)
+$(cxx_obj) $(cxx_od): $(common.l.cpp-options)
+
+genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \
+--table-prefix t_cont_changet_
+$(gen): cpp_options := -I$(src_base)
+$(gen): $(common.l.cpp-options)
+
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Dist
+#
+name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base)))
+
+$(dist): db_id := @database@
+$(dist): sources := $(cxx_tun)
+$(dist): headers := $(odb_hdr)
+$(dist): data_dist := test.std
+$(dist): export name := $(name)
+$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \
+$(call vc10projs,$(name)) $(call vc11projs,$(name))
+$(dist):
+ $(call dist-data,$(sources) $(headers) $(data_dist))
+ $(call meta-automake,../../template/Makefile.am)
+ $(call meta-vc9projs,../../template/template,$(name))
+ $(call meta-vc10projs,../../template/template,$(name))
+ $(call meta-vc11projs,../../template/template,$(name))
+
+# Test.
+#
+$(test): $(driver) $(src_base)/test.std
+ $(call schema)
+ $(call message,test $<,$< --options-file $(dcf_root)/db.options \
+>$(out_base)/test.out)
+ $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out)
+ $(call message,,rm -f $(out_base)/test.out)
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
+ $(call message,,rm -f $(out_base)/test.out)
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/dist.make)
+$(call include,$(bld_root)/meta/vc9proj.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/vc11proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(bld_root)/cxx/standard.make) # cxx_standard
+ifdef cxx_standard
+$(gen): odb_options += --std $(cxx_standard)
+$(call include,$(odb_rules))
+endif
+
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/libcommon/makefile)
diff --git a/common/container/change-tracking/test.hxx b/common/container/change-tracking/test.hxx
new file mode 100644
index 0000000..0387faf
--- /dev/null
+++ b/common/container/change-tracking/test.hxx
@@ -0,0 +1,81 @@
+// file : common/container/change-tracking/test.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <common/config.hxx> // HAVE_CXX11
+
+#include <string>
+#include <memory>
+#include <vector>
+
+#ifdef HAVE_CXX11
+# include <utility> // std::move
+#endif
+
+#include <odb/core.hxx>
+#include <odb/vector.hxx>
+
+#pragma db object pointer(std::auto_ptr)
+struct object
+{
+ object () {}
+ object (const std::string& id): id_ (id) {}
+
+#ifdef HAVE_CXX11
+ object (const object& x): id_ (x.id_), i (x.i), s (x.s) {}
+ object (object&& x): id_ (std::move (x.id_)), i (x.i), s (std::move (x.s)) {}
+#endif
+
+ #pragma db id
+ std::string id_;
+
+ unsigned int i;
+
+ odb::vector<std::string> s;
+
+ inline bool
+ operator== (const object& o) {return id_ == o.id_ && i == o.i && s == o.s;}
+};
+
+// Test mixing "smart" and "dumb" container (specifically, erase(obj)).
+//
+#pragma db object
+struct mix_object
+{
+ mix_object () {}
+ mix_object (unsigned long id): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ odb::vector<int> ov;
+ std::vector<int> sv;
+};
+
+// Test using change tracking container as inverse member.
+//
+struct inv_object2;
+
+#pragma db object session
+struct inv_object1
+{
+ #pragma db id auto
+ unsigned long id_;
+
+ inv_object2* o2;
+};
+
+#pragma db object session
+struct inv_object2
+{
+ #pragma db id auto
+ unsigned long id_;
+
+ #pragma db inverse(o2)
+ odb::vector<inv_object1*> o1;
+};
+
+#endif // TEST_HXX
diff --git a/qt/common/containers/test.std b/common/container/change-tracking/test.std
index e69de29..e69de29 100644
--- a/qt/common/containers/test.std
+++ b/common/container/change-tracking/test.std
diff --git a/common/makefile b/common/makefile
index eae7f7e..883fe3f 100644
--- a/common/makefile
+++ b/common/makefile
@@ -4,48 +4,49 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make
-tests := \
-access \
-auto \
-blob \
-callback \
-circular/single \
-circular/multiple \
-composite \
-composite-id \
-const-object \
-const-member \
-container \
-ctor \
-default \
-definition \
-enum \
-erase-query \
-include \
-index \
-inheritance/polymorphism \
-inheritance/reuse \
-inheritance/transient \
-inverse \
-lazy-ptr \
-lifecycle \
-no-id \
-optimistic \
-pragma \
-prepared \
-query/basics \
-query/array \
-readonly \
-relationship \
-relationship-query \
-schema \
-session/cache \
-template \
-transaction/basics \
-transaction/callback \
-types \
-view \
-virtual \
+tests := \
+access \
+auto \
+blob \
+callback \
+circular/single \
+circular/multiple \
+composite \
+composite-id \
+const-object \
+const-member \
+container/basics \
+container/change-tracking \
+ctor \
+default \
+definition \
+enum \
+erase-query \
+include \
+index \
+inheritance/polymorphism \
+inheritance/reuse \
+inheritance/transient \
+inverse \
+lazy-ptr \
+lifecycle \
+no-id \
+optimistic \
+pragma \
+prepared \
+query/basics \
+query/array \
+readonly \
+relationship \
+relationship-query \
+schema \
+session/cache \
+template \
+transaction/basics \
+transaction/callback \
+types \
+view \
+virtual \
wrapper
thread_tests := threads
diff --git a/qt/common/containers/driver.cxx b/qt/common/containers/basics/driver.cxx
index 5de758c..1d22962 100644
--- a/qt/common/containers/driver.cxx
+++ b/qt/common/containers/basics/driver.cxx
@@ -1,8 +1,8 @@
-// file : qt/common/containers/driver.cxx
+// file : qt/common/containers/basics/driver.cxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
-// Test Qt containers persistence.
+// Test basic Qt containers persistence.
//
#include <memory> // std::auto_ptr
diff --git a/qt/common/containers/makefile b/qt/common/containers/basics/makefile
index 3cfc22f..2a88495 100644
--- a/qt/common/containers/makefile
+++ b/qt/common/containers/basics/makefile
@@ -1,8 +1,8 @@
-# file : qt/common/containers/makefile
+# file : qt/common/containers/basics/makefile
# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
# license : GNU GPL v2; see accompanying LICENSE file
-include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make
cxx_tun := driver.cxx
odb_hdr := test.hxx
@@ -45,7 +45,7 @@ $(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): export odb_options += --database $(db_id) \
--profile qt/containers --profile qt/basic --generate-schema \
---table-prefix qt_cont_
+--table-prefix qt_cont_bs_
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \
$(qt_core.l.cpp-options)
@@ -69,10 +69,10 @@ $(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \
$(call vc10projs,$(name)) $(call vc11projs,$(name))
$(dist):
$(call dist-data,$(sources) $(headers) $(data_dist))
- $(call meta-automake,../template/Makefile.am)
- $(call meta-vc9projs,../template/template,$(name))
- $(call meta-vc10projs,../template/template,$(name))
- $(call meta-vc11projs,../template/template,$(name))
+ $(call meta-automake,../../template/Makefile.am)
+ $(call meta-vc9projs,../../template/template,$(name))
+ $(call meta-vc10projs,../../template/template,$(name))
+ $(call meta-vc11projs,../../template/template,$(name))
# Test.
#
diff --git a/qt/common/containers/test.hxx b/qt/common/containers/basics/test.hxx
index 2e452d6..204d0f9 100644
--- a/qt/common/containers/test.hxx
+++ b/qt/common/containers/basics/test.hxx
@@ -1,4 +1,4 @@
-// file : qt/common/containers/test.hxx
+// file : qt/common/containers/basics/test.hxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
diff --git a/qt/common/containers/basics/test.std b/qt/common/containers/basics/test.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/qt/common/containers/basics/test.std
diff --git a/qt/common/containers/change-tracking/driver.cxx b/qt/common/containers/change-tracking/driver.cxx
new file mode 100644
index 0000000..15dd825
--- /dev/null
+++ b/qt/common/containers/change-tracking/driver.cxx
@@ -0,0 +1,632 @@
+// file : qt/common/containers/change-tracking/driver.cxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test change-tracking Qt containers.
+//
+
+#include <common/config.hxx> // HAVE_CXX11
+
+#include <memory> // std::auto_ptr
+#include <cassert>
+#include <iostream>
+
+#ifdef HAVE_CXX11
+# include <utility> // std::move
+#endif
+
+#include <QtCore/QtGlobal> // QT_VERSION, Q_FOREACH
+#include <QtCore/QCoreApplication>
+
+#include <odb/tracer.hxx>
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+
+#include <odb/qt/list-iterator.hxx>
+#include <odb/qt/mutable-list-iterator.hxx>
+
+#include <common/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+using namespace std;
+using namespace odb::core;
+
+struct counting_tracer: odb::tracer
+{
+ void
+ reset (transaction& tr) {u = i = d = s = t = 0; tr.tracer (*this);}
+
+ virtual void
+ execute (odb::connection&, const char* stmt)
+ {
+ string p (stmt, 6);
+ if (p == "UPDATE")
+ u++;
+ else if (p == "INSERT")
+ i++;
+ else if (p == "DELETE")
+ d++;
+ else if (p == "SELECT")
+ s++;
+ t++;
+ }
+
+ size_t u, i, d, s, t;
+};
+
+static counting_tracer tr;
+
+// Compilation test: instantiate all the functions. Only do this if we
+// have a fairly recent version of Qt, otherwise some underlying
+// functions will be missing.
+//
+#if QT_VERSION >= 0x050000
+template class QOdbList<short>;
+template class QOdbListIteratorImpl<QOdbList<short> >;
+template class QOdbListIterator<short>;
+template class QMutableOdbListIterator<short>;
+#endif
+
+void
+f (const QList<int>&) {}
+
+int
+main (int argc, char* argv[])
+{
+ QCoreApplication app (argc, argv);
+
+ try
+ {
+ // Test extended interface.
+ //
+ {
+ typedef QOdbList<int> list;
+
+ list ol;
+ QList<int> ql;
+ f (ol); // Implicit conversion to QList.
+ list ol1 (ql); // Initialization from QList.
+ ol = ql; // Assignement from QList.
+
+ // Container comparison.
+ //
+ if (ol != ol1 ||
+ ol != ql ||
+ ql != ol1)
+ ol.clear ();
+
+ // Container operators.
+ //
+ ol += ol1;
+ ol += ql;
+ ol = ol1 + ql;
+ ol = ql + ol1;
+
+ // Iterator comparison/conversion.
+ //
+#ifndef QT_STRICT_ITERATORS
+ list::const_iterator i (ol.begin ());
+ if (i != ol.end ())
+ i = ol.end ();
+#endif
+
+ Q_FOREACH (const int& i, ol)
+ cerr << i;
+ }
+
+ auto_ptr<database> db (create_database (argc, argv));
+
+ // Test traits logic.
+ //
+ {
+ object o ("1");
+ o.i = 123;
+ o.s.push_back ("a");
+
+ assert (!o.s._tracking ());
+
+ // persist
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ assert (o.s._tracking ());
+
+ // load
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p (db->load<object> ("1"));
+ assert (p->s._tracking ());
+ t.commit ();
+ }
+
+ // update
+ //
+ {
+ transaction t (db->begin ());
+ db->update (o);
+ t.commit ();
+ }
+
+ assert (o.s._tracking ());
+
+ // erase
+ //
+ {
+ transaction t (db->begin ());
+ db->erase (o);
+ t.commit ();
+ }
+
+ assert (!o.s._tracking ());
+ }
+
+ // Test change tracking.
+ //
+ object o ("1");
+ o.i = 123;
+ o.s.push_back ("a");
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ // push_back/pop_back
+ //
+ {
+ o.s.push_back ("b"); // insert
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.i == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.pop_back ();
+ o.s.push_back ("c"); // update
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 2 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.pop_back (); // delete
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.d == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.push_back ("b");
+ o.s.pop_back (); // no-op
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.t == 1);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // insert
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.insert (o.s.begin (), "a1"); // insert front
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.i == 1 && tr.t == 4);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.insert (o.s.begin () + 1, "a2"); // insert middle
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.i == 1 && tr.t == 4);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.insert (o.s.end (), "b1"); // insert back
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.i == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // erase
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.erase (o.s.begin ()); // erase front
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 4 && tr.d == 1 && tr.t == 5);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.erase (o.s.begin () + 1); // erase middle
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 2 && tr.d == 1 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.erase (o.s.end () - 1); // erase back
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.d == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // modify
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.modify (1) += 'b';
+ o.s.modify_back () += 'd';
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.modify_front () += 'a';
+ o.s.modify_back () += 'd';
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.t == 3);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.begin ().modify () += 'a';
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 2 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.mbegin ();
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 5 && tr.t == 5);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // clear
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.clear ();
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.d == 1 && tr.t == 2);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // assign
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ QList<QString> v;
+ v.push_back ("1");
+ v.push_back ("2");
+ v.push_back ("3");
+ v.push_back ("4");
+ o.s = v;
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 4 && tr.i == 1 && tr.t == 5);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // removeOne/removeAll
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+ o.s.push_back ("a");
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.removeOne ("c");
+ assert (o.s.size () == 5 && o.s[3] == "a");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.d == 1 && tr.t == 4);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ o.s.removeAll ("a");
+ assert (o.s.size () == 2 && o.s[0] == "b" && o.s[1] == "d");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 3 && tr.d == 1 && tr.t == 4);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ // Transaction rollback.
+ //
+ {
+ o.s.clear ();
+ o.s.push_back ("a");
+ o.s.push_back ("b");
+ o.s.push_back ("c");
+
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (*db->load<object> ("1") == o);
+ t.commit ();
+ }
+
+ {
+ {
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ db->update (o);
+ t.rollback ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.i == 4 && tr.d == 1 && tr.t == 6);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (o);
+ assert (tr.u == 1 && tr.t == 1);
+ t.commit ();
+ }
+ }
+
+ // Armed copy.
+ //
+ {
+ auto_ptr<object> c;
+
+ {
+ o.s.pop_back ();
+
+ transaction t (db->begin ());
+ db->update (o);
+ c.reset (new object (o));
+ t.rollback ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.i == 3 && tr.d == 1 && tr.t == 5);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.t == 1);
+ t.commit ();
+ }
+ }
+
+ // Armed swap.
+ //
+ {
+ object c (o);
+
+ {
+ o.s.push_back ("d");
+
+ transaction t (db->begin ());
+ db->update (o);
+ assert (o.s._tracking () && !c.s._tracking ());
+ c.s.swap (o.s);
+ assert (!o.s._tracking () && c.s._tracking ());
+ t.rollback ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.i == 4 && tr.d == 1 && tr.t == 6);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.t == 1);
+ t.commit ();
+ }
+ }
+
+ // Armed move.
+ //
+#ifdef HAVE_CXX11
+ {
+ auto_ptr<object> c;
+
+ {
+ o.s.pop_back ();
+
+ transaction t (db->begin ());
+ db->update (o);
+ assert (o.s._tracking ());
+ c.reset (new object (std::move (o)));
+ assert (!o.s._tracking () && c->s._tracking ());
+ t.rollback ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.i == 2 && tr.d == 1 && tr.t == 4);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ tr.reset (t);
+ db->update (c);
+ assert (tr.u == 1 && tr.t == 1);
+ t.commit ();
+ }
+ }
+#endif
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/qt/common/containers/change-tracking/makefile b/qt/common/containers/change-tracking/makefile
new file mode 100644
index 0000000..7a25503
--- /dev/null
+++ b/qt/common/containers/change-tracking/makefile
@@ -0,0 +1,126 @@
+# file : qt/common/containers/change-tracking/makefile
+# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+odb_hdr := test.hxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+common.l := $(out_root)/libcommon/common/common.l
+common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options
+
+driver := $(out_base)/driver
+dist := $(out_base)/.dist
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/odb/stub.make,\
+ odb: odb,odb-rules: odb_rules)
+
+$(call import,\
+ $(scf_root)/import/libodb-qt/stub.make,\
+ l: odb_qt.l,cpp-options: odb_qt.l.cpp-options)
+
+$(call import,\
+ $(scf_root)/import/libqt/core/stub.make,\
+ l: qt_core.l,cpp-options: qt.l.cpp-options)
+
+# Build.
+#
+$(driver): $(cxx_obj) $(odb_qt.l) $(common.l) $(qt_core.l)
+$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base)
+$(cxx_obj) $(cxx_od): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \
+$(qt_core.l.cpp-options)
+
+genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen) $(dist): export odb_options += --database $(db_id) \
+--profile qt/containers --profile qt/basic --generate-schema \
+--table-prefix qt_cont_ct_
+$(gen): cpp_options := -I$(src_base)
+$(gen): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \
+$(qt_core.l.cpp-options)
+
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Dist
+#
+name := $(subst /,-,$(subst $(src_root)/qt/common/,,$(src_base)))
+
+$(dist): db_id := @database@
+$(dist): sources := $(cxx_tun)
+$(dist): headers := $(odb_hdr)
+$(dist): data_dist := test.std
+$(dist): export name := $(name)
+$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \
+$(call vc10projs,$(name)) $(call vc11projs,$(name))
+$(dist):
+ $(call dist-data,$(sources) $(headers) $(data_dist))
+ $(call meta-automake,../../template/Makefile.am)
+ $(call meta-vc9projs,../../template/template,$(name))
+ $(call meta-vc10projs,../../template/template,$(name))
+ $(call meta-vc11projs,../../template/template,$(name))
+
+# Test.
+#
+$(test): $(driver) $(src_base)/test.std
+ $(call schema)
+ $(call message,test $<,$< --options-file $(dcf_root)/db.options \
+>$(out_base)/test.out)
+ $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out)
+ $(call message,,rm -f $(out_base)/test.out)
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
+ $(call message,,rm -f $(out_base)/test.out)
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/dist.make)
+$(call include,$(bld_root)/meta/vc9proj.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/vc11proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(bld_root)/cxx/standard.make) # cxx_standard
+ifdef cxx_standard
+$(gen): odb_options += --std $(cxx_standard)
+$(call include,$(odb_rules))
+endif
+
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/libcommon/makefile)
diff --git a/qt/common/containers/change-tracking/test.hxx b/qt/common/containers/change-tracking/test.hxx
new file mode 100644
index 0000000..7ad230e
--- /dev/null
+++ b/qt/common/containers/change-tracking/test.hxx
@@ -0,0 +1,43 @@
+// file : qt/common/containers/change-tracking/test.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <common/config.hxx> // HAVE_CXX11
+
+#include <memory>
+
+#ifdef HAVE_CXX11
+# include <utility> // std::move
+#endif
+
+#include <QtCore/QString>
+
+#include <odb/core.hxx>
+#include <odb/qt/list.hxx>
+
+#pragma db object pointer(std::auto_ptr)
+struct object
+{
+ object () {}
+ object (const QString& id): id_ (id) {}
+
+#ifdef HAVE_CXX11
+ object (const object& x): id_ (x.id_), i (x.i), s (x.s) {}
+ object (object&& x): id_ (std::move (x.id_)), i (x.i), s (std::move (x.s)) {}
+#endif
+
+ #pragma db id
+ QString id_;
+
+ unsigned int i;
+
+ QOdbList<QString> s;
+
+ inline bool
+ operator== (const object& o) {return id_ == o.id_ && i == o.i && s == o.s;}
+};
+
+#endif // TEST_HXX
diff --git a/qt/common/containers/change-tracking/test.std b/qt/common/containers/change-tracking/test.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/qt/common/containers/change-tracking/test.std
diff --git a/qt/common/makefile b/qt/common/makefile
index 33b17aa..2cadcee 100644
--- a/qt/common/makefile
+++ b/qt/common/makefile
@@ -4,10 +4,11 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
-tests := \
-basic \
-containers \
-smart-ptr \
+tests := \
+basic \
+containers/basics \
+containers/change-tracking \
+smart-ptr \
template
all_tests := $(tests)