1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// file : mssql/database/driver.cxx
// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
// license : GNU GPL; see accompanying LICENSE file
// 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)
{
{
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 d (argc, argv, false, "", isolation_read_uncommitted);
connection_ptr c (d.connection ());
assert (check_isolation (*c, isolation_read_uncommitted));
}
{
database d (argc, argv, false, "");
connection_ptr c (d.connection ());
assert (check_isolation (*c, isolation_read_committed));
}
{
database d (argc, argv, false, "", isolation_repeatable_read);
connection_ptr c (d.connection ());
assert (check_isolation (*c, isolation_repeatable_read));
}
{
database d (argc, argv, false, "", isolation_snapshot);
connection_ptr c (d.connection ());
assert (check_isolation (*c, isolation_snapshot));
}
{
database d (argc, argv, false, "", isolation_serializable);
connection_ptr c (d.connection ());
assert (check_isolation (*c, isolation_serializable));
}
}
|