aboutsummaryrefslogtreecommitdiff
path: root/mssql
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-01-15 12:27:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-01-15 12:27:27 +0200
commit2d2824da38f4ad89c3d9a675042547e13c03f64f (patch)
tree642cb28a5a729467c0d3eebbb729bee15f190874 /mssql
parentf221c0a4f291646a1e698a8de2909043e7d0313d (diff)
Add support for setting SQL Server transaction isolation level
Diffstat (limited to 'mssql')
-rw-r--r--mssql/database/driver.cxx92
1 files changed, 73 insertions, 19 deletions
diff --git a/mssql/database/driver.cxx b/mssql/database/driver.cxx
index 7f8aa8f..47a1559 100644
--- a/mssql/database/driver.cxx
+++ b/mssql/database/driver.cxx
@@ -5,48 +5,102 @@
// Test that database constructors are unambiguous (compilation only).
//
+#include <string>
+#include <cassert>
+
#include <odb/mssql/database.hxx>
namespace mssql = odb::mssql;
using namespace mssql;
+static const char* isolation_map[] = {"1", "2", "3", "5", "4"};
+
+static bool
+check_isolation (connection& c, transaction_isolation i)
+{
+ std::string s ("SELECT 1 FROM sys.dm_exec_sessions WHERE session_id = @@SPID"
+ " AND transaction_isolation_level = ");
+ s += isolation_map[i];
+ return c.execute (s) == 1;
+}
+
int
main (int argc, char* argv[])
{
// This code should not execute.
//
- if (argc != 0)
- return 0;
+ if (argc == 0)
+ {
+ {
+ database d1 ("bob", "secret", "db1", "server1");
+ database d2 ("bob", "secret", "db1", "server1", "driver1");
+ database d3 ("bob", "secret", "db1", "server1", "driver1", "extra");
+ database d4 ("bob", "secret", "db1", "server1", "driver1", "extra",
+ isolation_read_uncommitted);
+ }
+ {
+ database d1 ("bob", "secret", "db1", protocol_auto);
+ database d2 ("bob", "secret", "db1", protocol_auto, "server1");
+ database d3 ("bob", "secret", "db1", protocol_auto, "server1", "inst1");
+ database d4 ("bob", "secret", "db1", protocol_auto, "server1", "inst1",
+ "driver1");
+ database d5 ("bob", "secret", "db1", protocol_auto, "server1", "inst1",
+ "driver1", "extra");
+ database d6 ("bob", "secret", "db1", protocol_auto, "server1", "inst1",
+ "driver1", "extra", isolation_read_uncommitted);
+ }
+
+ {
+ database d1 ("bob", "secret", "db1", "server1", 0);
+ database d2 ("bob", "secret", "db1", "server1", 999, "driver1");
+ database d3 ("bob", "secret", "db1", "server1", 999, "driver1", "extra");
+ database d4 ("bob", "secret", "db1", "server1", 999, "driver1", "extra",
+ isolation_read_uncommitted);
+ }
+
+ {
+ database d1 ("conn1");
+ database d2 ("conn1", isolation_read_uncommitted);
+ }
+
+ {
+ database d1 (argc, argv);
+ database d2 (argc, argv, false);
+ database d3 (argc, argv, true, "extra");
+ database d4 (argc, argv, false, "extra", isolation_read_uncommitted);
+ }
+ }
+
+ // Test transaction isolation levels.
+ //
{
- database d1 ("bob", "secret", "db1", "server1");
- database d2 ("bob", "secret", "db1", "server1", "driver1");
- database d3 ("bob", "secret", "db1", "server1", "driver1", "extra");
+ database d (argc, argv, false, "", isolation_read_uncommitted);
+ connection_ptr c (d.connection ());
+ assert (check_isolation (*c, isolation_read_uncommitted));
}
{
- database d1 ("bob", "secret", "db1", protocol_auto);
- database d2 ("bob", "secret", "db1", protocol_auto, "server1");
- database d3 ("bob", "secret", "db1", protocol_auto, "server1", "inst1");
- database d4 ("bob", "secret", "db1", protocol_auto, "server1", "inst1",
- "driver1");
- database d5 ("bob", "secret", "db1", protocol_auto, "server1", "inst1",
- "driver1", "extra");
+ database d (argc, argv, false, "");
+ connection_ptr c (d.connection ());
+ assert (check_isolation (*c, isolation_read_committed));
}
{
- database d1 ("bob", "secret", "db1", "server1", 0);
- database d2 ("bob", "secret", "db1", "server1", 999, "driver1");
- database d3 ("bob", "secret", "db1", "server1", 999, "driver1", "extra");
+ database d (argc, argv, false, "", isolation_repeatable_read);
+ connection_ptr c (d.connection ());
+ assert (check_isolation (*c, isolation_repeatable_read));
}
{
- database d1 ("conn1");
+ database d (argc, argv, false, "", isolation_snapshot);
+ connection_ptr c (d.connection ());
+ assert (check_isolation (*c, isolation_snapshot));
}
{
- database d1 (argc, argv);
- database d2 (argc, argv, false);
- database d3 (argc, argv, true, "extra");
+ database d (argc, argv, false, "", isolation_serializable);
+ connection_ptr c (d.connection ());
+ assert (check_isolation (*c, isolation_serializable));
}
}