aboutsummaryrefslogtreecommitdiff
path: root/mssql
diff options
context:
space:
mode:
Diffstat (limited to 'mssql')
-rw-r--r--mssql/types/driver.cxx26
-rw-r--r--mssql/types/test.hxx20
2 files changed, 46 insertions, 0 deletions
diff --git a/mssql/types/driver.cxx b/mssql/types/driver.cxx
index 6390950..a779079 100644
--- a/mssql/types/driver.cxx
+++ b/mssql/types/driver.cxx
@@ -217,6 +217,32 @@ main (int argc, char* argv[])
assert (o == *p);
}
}
+
+ // Test optimistic concurrency using ROWVERSION.
+ //
+ {
+ rowversion o;
+ o.str = "abc";
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ assert (o.version != 0);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<rowversion> p (db->load<rowversion> (o.id_));
+ assert (p->version == o.version);
+ p->str += 'd';
+ db->update (*p);
+ assert (p->version > o.version);
+ db->reload (o);
+ assert (o.version == p->version);
+ t.commit ();
+ }
+ }
}
catch (const odb::exception& e)
{
diff --git a/mssql/types/test.hxx b/mssql/types/test.hxx
index d735acf..3e20e73 100644
--- a/mssql/types/test.hxx
+++ b/mssql/types/test.hxx
@@ -369,4 +369,24 @@ struct long_cont
}
};
+// Test optimistic concurrency using ROWVERSION.
+//
+#pragma db object optimistic
+struct rowversion
+{
+ rowversion (): version (0) {}
+
+ #pragma db id auto
+ unsigned int id_;
+
+ #pragma db version type("ROWVERSION")
+#ifdef _WIN32
+ unsigned __int64 version;
+#else
+ unsigned long long version;
+#endif
+
+ std::string str;
+};
+
#endif // TEST_HXX