From 0d90255b54daafff9de1f4fee4cfee722e02171a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 14 Nov 2014 16:24:50 +0200 Subject: Old interface compatibility and testing fixes Now all tests pass for both Oracle and SQL Server. --- common/auto/test.hxx | 2 +- common/section/basics/driver.cxx | 14 +++++++++++ mssql/types/driver.cxx | 51 ++++++++++++++++++++++++++++++++++++---- mssql/types/test.hxx | 27 +++++++++++++++++---- 4 files changed, 84 insertions(+), 10 deletions(-) diff --git a/common/auto/test.hxx b/common/auto/test.hxx index 61fbcc6..0e7585e 100644 --- a/common/auto/test.hxx +++ b/common/auto/test.hxx @@ -35,7 +35,7 @@ private: struct auto_only { #pragma db auto id - unsigned long id_; + unsigned short id_; }; #endif // TEST_HXX diff --git a/common/section/basics/driver.cxx b/common/section/basics/driver.cxx index f34ed90..a2b7006 100644 --- a/common/section/basics/driver.cxx +++ b/common/section/basics/driver.cxx @@ -1273,6 +1273,13 @@ main (int argc, char* argv[]) db->update (o1, o1.s); assert (o.v != o1.v); + // Double-check object version was updated. + // + { + auto_ptr p1 (db->load (o.id)); + assert (o1.v == p1->v); + } + try { db->load (*p, p->s); @@ -1393,6 +1400,13 @@ main (int argc, char* argv[]) db->update (o1, o1.s); assert (o.v != o1.v); + // Double-check object version was updated. + // + { + auto_ptr p1 (db->load (o.id)); + assert (o1.v == p1->v); + } + try { db->load (*p, p->s); diff --git a/mssql/types/driver.cxx b/mssql/types/driver.cxx index 33b606e..55e4c68 100644 --- a/mssql/types/driver.cxx +++ b/mssql/types/driver.cxx @@ -269,23 +269,64 @@ main (int argc, char* argv[]) // Test optimistic concurrency using ROWVERSION. // { - rowversion o; + rowversion o (123); o.str = "abc"; { transaction t (db->begin ()); db->persist (o); - assert (o.version != 0); + assert (o.ver != 0); t.commit (); } { transaction t (db->begin ()); auto_ptr p (db->load (o.id_)); - assert (p->version == o.version); + assert (p->ver == o.ver); p->str += 'd'; db->update (*p); - assert (p->version > o.version); + assert (p->ver > o.ver); + + // Double-check object version was updated. + // + { + auto_ptr p1 (db->load (o.id_)); + assert (p->ver == p1->ver); + } + + o.str += 'D'; + try + { + db->update (o); + assert (false); + } + catch (const odb::object_changed&) {} + db->reload (o); + assert (o.ver == p->ver); + o.str += 'D'; + db->update (o); + t.commit (); + } + } + + { + rowversion_auto o; + o.str = "abc"; + + { + transaction t (db->begin ()); + db->persist (o); + assert (o.ver != 0); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr p (db->load (o.id_)); + assert (p->ver == o.ver); + p->str += 'd'; + db->update (*p); + assert (p->ver > o.ver); o.str += 'D'; try { @@ -294,7 +335,7 @@ main (int argc, char* argv[]) } catch (const odb::object_changed&) {} db->reload (o); - assert (o.version == p->version); + assert (o.ver == p->ver); o.str += 'D'; db->update (o); t.commit (); diff --git a/mssql/types/test.hxx b/mssql/types/test.hxx index 82f8147..9d9ab89 100644 --- a/mssql/types/test.hxx +++ b/mssql/types/test.hxx @@ -470,21 +470,40 @@ struct char_array } }; -// Test optimistic concurrency using ROWVERSION. +// Test optimistic concurrency using ROWVERSION, both with auto and +// manually-assigned ids. // #pragma db object optimistic struct rowversion { - rowversion (): version (0) {} + rowversion (unsigned int id = 0): id_ (id), ver (0) {} + + #pragma db id + unsigned int id_; + + #pragma db version type("ROWVERSION") +#ifdef _WIN32 + unsigned __int64 ver; +#else + unsigned long long ver; +#endif + + std::string str; +}; + +#pragma db object optimistic +struct rowversion_auto +{ + rowversion_auto (): ver (0) {} #pragma db id auto unsigned int id_; #pragma db version type("ROWVERSION") #ifdef _WIN32 - unsigned __int64 version; + unsigned __int64 ver; #else - unsigned long long version; + unsigned long long ver; #endif std::string str; -- cgit v1.1