diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-01-14 16:01:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-01-14 16:01:06 +0200 |
commit | 23a537ac98066dc3994100548890112aa6e8d8ac (patch) | |
tree | 20f5bc5d93578a35437dd004dcc6a435aba173eb | |
parent | 42fee52342964c689be0e48bed07637be2fb45c1 (diff) |
Add support for MSSQL ROWVERSION
ODB can now use ROWVERSION column as an optimistic concurrency version.
-rw-r--r-- | mssql/types/driver.cxx | 26 | ||||
-rw-r--r-- | mssql/types/test.hxx | 20 |
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 |