diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-01-15 12:27:27 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-01-15 12:27:27 +0200 |
commit | 79121ca0e7ffdad212513a05fba76c1a19a73df5 (patch) | |
tree | b2c25369dd44d8a931a7c16d8d7093c0a646fc85 /odb/mssql/connection.cxx | |
parent | 5e113195591a9f8dccbb8f5f743cdd7776906b08 (diff) |
Add support for setting SQL Server transaction isolation level
Diffstat (limited to 'odb/mssql/connection.cxx')
-rw-r--r-- | odb/mssql/connection.cxx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/odb/mssql/connection.cxx b/odb/mssql/connection.cxx index 4c69a0c..6310bf3 100644 --- a/odb/mssql/connection.cxx +++ b/odb/mssql/connection.cxx @@ -18,6 +18,15 @@ namespace odb { namespace mssql { + static const long transaction_isolation_map[] = + { + SQL_TXN_READ_UNCOMMITTED, + SQL_TXN_READ_COMMITTED, + SQL_TXN_REPEATABLE_READ, + SQL_TXN_SS_SNAPSHOT, + SQL_TXN_SERIALIZABLE + }; + connection:: connection (database_type& db) : odb::connection (db), @@ -63,6 +72,40 @@ namespace odb if (!SQL_SUCCEEDED (r)) translate_error (r, handle_, SQL_HANDLE_DBC); + // Set transaction isolation level. + // + transaction_isolation ti (db_.transaction_isolation ()); + switch (ti) + { + case isolation_read_committed: + { + break; // SQL Server default. + } + case isolation_read_uncommitted: + case isolation_repeatable_read: + case isolation_serializable: + { + r = SQLSetConnectAttrA (handle_, + SQL_ATTR_TXN_ISOLATION, + (SQLPOINTER) transaction_isolation_map[ti], + 0); + if (!SQL_SUCCEEDED (r)) + translate_error (r, handle_, SQL_HANDLE_DBC); + break; + } + case isolation_snapshot: + { + r = SQLSetConnectAttrA (handle_, + SQL_COPT_SS_TXN_ISOLATION, + (SQLPOINTER) transaction_isolation_map[ti], + SQL_IS_INTEGER); + + if (!SQL_SUCCEEDED (r)) + translate_error (r, handle_, SQL_HANDLE_DBC); + break; + } + } + // Connect. // { |