From 23a537ac98066dc3994100548890112aa6e8d8ac Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 Jan 2013 16:01:06 +0200 Subject: Add support for MSSQL ROWVERSION ODB can now use ROWVERSION column as an optimistic concurrency version. --- mssql/types/driver.cxx | 26 ++++++++++++++++++++++++++ mssql/types/test.hxx | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+) 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 p (db->load (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 -- cgit v1.1