aboutsummaryrefslogtreecommitdiff
path: root/mssql/types
diff options
context:
space:
mode:
Diffstat (limited to 'mssql/types')
-rw-r--r--mssql/types/driver.cxx51
-rw-r--r--mssql/types/test.hxx27
2 files changed, 69 insertions, 9 deletions
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;