aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/auto/test.hxx4
-rw-r--r--common/section/basics/driver.cxx14
-rw-r--r--mssql/types/driver.cxx51
-rw-r--r--mssql/types/test.hxx27
4 files changed, 85 insertions, 11 deletions
diff --git a/common/auto/test.hxx b/common/auto/test.hxx
index 61fbcc6..cee27c5 100644
--- a/common/auto/test.hxx
+++ b/common/auto/test.hxx
@@ -34,8 +34,8 @@ private:
#pragma db object
struct auto_only
{
- #pragma db auto id
- unsigned long id_;
+ #pragma db auto id pgsql:type("BIGINT")
+ 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<object> p1 (db->load<object> (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<object> p1 (db->load<object> (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<rowversion> p (db->load<rowversion> (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<rowversion> p1 (db->load<rowversion> (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<rowversion_auto> p (db->load<rowversion_auto> (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;