annotate PostgreSQL/UnitTests/PostgreSQLTests.cpp @ 237:35598014f140

refactoring to remove GlobalProperties.cpp
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 Apr 2021 19:09:04 +0200
parents 675f8322eb7c
children b97a537f4613
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
193
3236894320d6 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include <gtest/gtest.h>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #if defined(_WIN32)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 // Fix redefinition of symbols on MinGW (these symbols are manually
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 // defined both by PostgreSQL and Google Test)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 # undef S_IRGRP
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 # undef S_IROTH
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 # undef S_IRWXG
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 # undef S_IRWXO
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 # undef S_IWGRP
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 # undef S_IWOTH
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 # undef S_IXGRP
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 # undef S_IXOTH
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #endif
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
37 #include "../../Framework/Plugins/GlobalProperties.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
38 #include "../../Framework/PostgreSQL/PostgreSQLLargeObject.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
39 #include "../../Framework/PostgreSQL/PostgreSQLResult.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
40 #include "../../Framework/PostgreSQL/PostgreSQLTransaction.h"
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
41 #include "../Plugins/PostgreSQLIndex.h"
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
42 #include "../Plugins/PostgreSQLStorageArea.h"
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
44 #include <Compatibility.h> // For std::unique_ptr<>
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 140
diff changeset
45 #include <OrthancException.h>
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 #include <boost/lexical_cast.hpp>
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 using namespace OrthancDatabases;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
51 extern PostgreSQLParameters globalParameters_;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
54 static PostgreSQLDatabase* CreateTestDatabase()
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
56 std::unique_ptr<PostgreSQLDatabase> pg
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
57 (new PostgreSQLDatabase(globalParameters_));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 pg->Open();
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
60 pg->ClearAll();
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return pg.release();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 static int64_t CountLargeObjects(PostgreSQLDatabase& db)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
68 PostgreSQLTransaction transaction(db, TransactionType_ReadOnly);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
69
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
70 int64_t count;
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
71
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
72 {
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
73 // Count the number of large objects in the DB
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
74 PostgreSQLStatement s(db, "SELECT COUNT(*) FROM pg_catalog.pg_largeobject");
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
75 PostgreSQLResult r(s);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
76 count = r.GetInteger64(0);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
77 }
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
78
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
79 transaction.Commit();
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
80 return count;
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 TEST(PostgreSQL, Basic)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
86 std::unique_ptr<PostgreSQLDatabase> pg(CreateTestDatabase());
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ASSERT_FALSE(pg->DoesTableExist("Test"));
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
89 pg->ExecuteMultiLines("CREATE TABLE Test(name INTEGER, value BIGINT)");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 ASSERT_TRUE(pg->DoesTableExist("Test"));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
92 PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 s.DeclareInputInteger(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 s.DeclareInputInteger64(1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 s.BindInteger(0, 43);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 s.BindNull(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 s.BindInteger(0, 42);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 s.BindInteger64(1, -4242);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 s.BindInteger(0, 43);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 s.BindNull(1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 s.BindNull(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 s.BindInteger64(1, 4444);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
111 PostgreSQLStatement t(*pg, "SELECT name, value FROM Test ORDER BY name");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 PostgreSQLResult r(t);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(42, r.GetInteger(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ(-4242, r.GetInteger64(1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 r.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(43, r.GetInteger(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 ASSERT_TRUE(r.IsNull(1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 r.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 ASSERT_TRUE(r.IsNull(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ(4444, r.GetInteger64(1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 r.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 ASSERT_TRUE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
133 PostgreSQLStatement t(*pg, "SELECT name, value FROM Test WHERE name=$1");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 t.DeclareInputInteger(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 t.BindInteger(0, 42);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 PostgreSQLResult r(t);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(42, r.GetInteger(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ(-4242, r.GetInteger64(1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 r.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ASSERT_TRUE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 t.BindInteger(0, 40);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 PostgreSQLResult r(t);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 ASSERT_TRUE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 TEST(PostgreSQL, String)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
159 std::unique_ptr<PostgreSQLDatabase> pg(CreateTestDatabase());
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
161 pg->ExecuteMultiLines("CREATE TABLE Test(name INTEGER, value VARCHAR(40))");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
163 PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 s.DeclareInputInteger(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 s.DeclareInputString(1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 s.BindInteger(0, 42);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 s.BindString(1, "Hello");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 s.BindInteger(0, 43);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 s.BindNull(1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 s.BindNull(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 s.BindString(1, "");
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
180 PostgreSQLStatement t(*pg, "SELECT name, value FROM Test ORDER BY name");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 PostgreSQLResult r(t);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(42, r.GetInteger(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ("Hello", r.GetString(1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 r.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 ASSERT_FALSE(r.IsNull(0)); ASSERT_EQ(43, r.GetInteger(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 ASSERT_TRUE(r.IsNull(1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 r.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 ASSERT_TRUE(r.IsNull(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 ASSERT_FALSE(r.IsNull(1)); ASSERT_EQ("", r.GetString(1));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 r.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 ASSERT_TRUE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 TEST(PostgreSQL, Transaction)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
205 std::unique_ptr<PostgreSQLDatabase> pg(CreateTestDatabase());
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
207 pg->ExecuteMultiLines("CREATE TABLE Test(name INTEGER, value INTEGER)");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
210 PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 s.DeclareInputInteger(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 s.DeclareInputInteger(1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 s.BindInteger(0, 42);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 s.BindInteger(1, 4242);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
216
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
218 PostgreSQLTransaction t(*pg, TransactionType_ReadOnly);
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
219 s.BindInteger(0, 0);
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
220 s.BindInteger(1, 1);
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
221 // Failure, as INSERT in a read-only transaction
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
222 ASSERT_THROW(s.Run(), Orthanc::OrthancException);
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
223 }
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
224
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
225 {
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
226 PostgreSQLTransaction t(*pg, TransactionType_ReadWrite);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 s.BindInteger(0, 43);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 s.BindInteger(1, 4343);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 s.BindInteger(0, 44);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 s.BindInteger(1, 4444);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
234 PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 PostgreSQLResult r(u);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 ASSERT_EQ(3, r.GetInteger64(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 // No commit
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
216
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
242 // Implicit transaction
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
243 PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 PostgreSQLResult r(u);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 ASSERT_EQ(1, r.GetInteger64(0)); // Just "1" because of implicit rollback
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 {
216
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
249 PostgreSQLTransaction t(*pg, TransactionType_ReadWrite);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 s.BindInteger(0, 43);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 s.BindInteger(1, 4343);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 s.BindInteger(0, 44);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 s.BindInteger(1, 4444);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
258 PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 PostgreSQLResult r(u);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 ASSERT_EQ(3, r.GetInteger64(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 t.Commit();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 ASSERT_THROW(t.Rollback(), Orthanc::OrthancException);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 ASSERT_THROW(t.Commit(), Orthanc::OrthancException);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
216
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
269 PostgreSQLTransaction t(*pg, TransactionType_ReadOnly);
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
270 PostgreSQLStatement u(*pg, "SELECT COUNT(*) FROM Test");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 PostgreSQLResult r(u);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 ASSERT_EQ(3, r.GetInteger64(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 TEST(PostgreSQL, LargeObject)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
283 std::unique_ptr<PostgreSQLDatabase> pg(CreateTestDatabase());
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 ASSERT_EQ(0, CountLargeObjects(*pg));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
286 pg->ExecuteMultiLines("CREATE TABLE Test(name VARCHAR, value OID)");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 // Automatically remove the large objects associated with the table
237
35598014f140 refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 230
diff changeset
289 pg->ExecuteMultiLines("CREATE RULE TestDelete AS ON DELETE TO Test DO SELECT lo_unlink(old.value);");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 {
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
292 PostgreSQLStatement s(*pg, "INSERT INTO Test VALUES ($1,$2)");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 s.DeclareInputString(0);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 s.DeclareInputLargeObject(1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 for (int i = 0; i < 10; i++)
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 {
216
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
298 PostgreSQLTransaction t(*pg, TransactionType_ReadWrite);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 std::string value = "Value " + boost::lexical_cast<std::string>(i * 2);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 PostgreSQLLargeObject obj(*pg, value);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 s.BindString(0, "Index " + boost::lexical_cast<std::string>(i));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 s.BindLargeObject(1, obj);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 std::string tmp;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 PostgreSQLLargeObject::Read(tmp, *pg, obj.GetOid());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 ASSERT_EQ(value, tmp);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 t.Commit();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 ASSERT_EQ(10, CountLargeObjects(*pg));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 {
216
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
319 PostgreSQLTransaction t(*pg, TransactionType_ReadOnly);
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
320 PostgreSQLStatement s(*pg, "SELECT * FROM Test ORDER BY name DESC");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 PostgreSQLResult r(s);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 ASSERT_FALSE(r.IsNull(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 ASSERT_EQ("Index 9", r.GetString(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 std::string data;
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 r.GetLargeObject(data, 1);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 ASSERT_EQ("Value 18", data);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 r.Next();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 ASSERT_FALSE(r.IsDone());
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 //ASSERT_TRUE(r.IsString(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 {
216
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
340 PostgreSQLTransaction t(*pg, TransactionType_ReadWrite);
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
341 PostgreSQLStatement s(*pg, "DELETE FROM Test WHERE name='Index 9'");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 s.Run();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 t.Commit();
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 // Count the number of items in the DB
216
fbb52129158a TransactionType given to PostgreSQLTransaction constructor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
349 PostgreSQLTransaction t(*pg, TransactionType_ReadOnly);
214
ab96698c73a3 removed useless information about read-only in ITransaction and IPrecompiledStatement
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 207
diff changeset
350 PostgreSQLStatement s(*pg, "SELECT COUNT(*) FROM Test");
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 PostgreSQLResult r(s);
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 ASSERT_EQ(9, r.GetInteger64(0));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 ASSERT_EQ(9, CountLargeObjects(*pg));
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 }
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
359 TEST(PostgreSQL, StorageArea)
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
360 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
361 std::unique_ptr<PostgreSQLDatabase> database(PostgreSQLDatabase::OpenDatabaseConnection(globalParameters_));
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
362
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
363 PostgreSQLStorageArea storageArea(globalParameters_, true /* clear database */);
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
365 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
366 PostgreSQLStorageArea::Accessor accessor(storageArea);
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
367
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
368 ASSERT_EQ(0, CountLargeObjects(*database));
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
369
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
370 for (int i = 0; i < 10; i++)
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
371 {
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
372 std::string uuid = boost::lexical_cast<std::string>(i);
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
373 std::string value = "Value " + boost::lexical_cast<std::string>(i * 2);
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
374 accessor.Create(uuid, value.c_str(), value.size(), OrthancPluginContentType_Unknown);
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
375 }
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
376
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 216
diff changeset
377 std::string buffer;
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
378 ASSERT_THROW(accessor.ReadToString(buffer, "nope", OrthancPluginContentType_Unknown),
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
379 Orthanc::OrthancException);
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
380
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
381 ASSERT_EQ(10, CountLargeObjects(*database));
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
382 accessor.Remove("5", OrthancPluginContentType_Unknown);
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
383
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
384 ASSERT_EQ(9, CountLargeObjects(*database));
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
386 for (int i = 0; i < 10; i++)
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
387 {
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
388 std::string uuid = boost::lexical_cast<std::string>(i);
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
389 std::string expected = "Value " + boost::lexical_cast<std::string>(i * 2);
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
390
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
391 if (i == 5)
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
392 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
393 ASSERT_THROW(accessor.ReadToString(buffer, uuid, OrthancPluginContentType_Unknown),
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
394 Orthanc::OrthancException);
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
395 }
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
396 else
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
397 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
398 accessor.ReadToString(buffer, uuid, OrthancPluginContentType_Unknown);
219
dd6cfc250747 removed useless class StorageAreaBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 216
diff changeset
399 ASSERT_EQ(expected, buffer);
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
400 }
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
401 }
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
402
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
403 for (int i = 0; i < 10; i++)
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
404 {
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
405 accessor.Remove(boost::lexical_cast<std::string>(i), OrthancPluginContentType_Unknown);
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
406 }
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
407
230
675f8322eb7c refactored StorageBackend by introducing an accessor class
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 226
diff changeset
408 ASSERT_EQ(0, CountLargeObjects(*database));
14
9774802fd05f PostgreSQLStorageArea working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
409 }
0
7cea966b6829 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 }
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
411
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
412
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
413 TEST(PostgreSQL, ImplicitTransaction)
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
414 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
415 std::unique_ptr<PostgreSQLDatabase> db(CreateTestDatabase());
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
416
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
417 ASSERT_FALSE(db->DoesTableExist("test"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
418 ASSERT_FALSE(db->DoesTableExist("test2"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
419
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
420 {
215
b40b30075c51 added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
421 std::unique_ptr<OrthancDatabases::ITransaction> t(db->CreateTransaction(TransactionType_ReadWrite));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
422 ASSERT_FALSE(t->IsImplicit());
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
423 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
424
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
425 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
426 Query query("CREATE TABLE test(id INT)", false);
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
427 std::unique_ptr<IPrecompiledStatement> s(db->Compile(query));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
428
215
b40b30075c51 added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
429 std::unique_ptr<ITransaction> t(db->CreateTransaction(TransactionType_Implicit));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
430 ASSERT_TRUE(t->IsImplicit());
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
431 ASSERT_THROW(t->Commit(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
432 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
433
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
434 Dictionary args;
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
435 t->ExecuteWithoutResult(*s, args);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
436 ASSERT_THROW(t->Rollback(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
437 t->Commit();
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
438
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
439 ASSERT_THROW(t->Commit(), Orthanc::OrthancException);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
440 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
441
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
442 {
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
443 // An implicit transaction does not need to be explicitely committed
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
444 Query query("CREATE TABLE test2(id INT)", false);
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
445 std::unique_ptr<IPrecompiledStatement> s(db->Compile(query));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
446
215
b40b30075c51 added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 214
diff changeset
447 std::unique_ptr<ITransaction> t(db->CreateTransaction(TransactionType_Implicit));
23
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
448
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
449 Dictionary args;
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
450 t->ExecuteWithoutResult(*s, args);
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
451 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
452
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
453 ASSERT_TRUE(db->DoesTableExist("test"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
454 ASSERT_TRUE(db->DoesTableExist("test2"));
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
455 }
b2ff1cd2907a handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 14
diff changeset
456
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
457
78
2ee166f77501 renamed macro
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 74
diff changeset
458 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
459 TEST(PostgreSQLIndex, CreateInstance)
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
460 {
201
42990b2dd51b create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 195
diff changeset
461 OrthancDatabases::PostgreSQLIndex db(NULL, globalParameters_);
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
462 db.SetClearAll(true);
225
94c9908e6aca removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 221
diff changeset
463
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
464 std::unique_ptr<OrthancDatabases::DatabaseManager> manager(OrthancDatabases::IndexBackend::CreateSingleDatabaseManager(db));
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
465
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
466 std::string s;
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
467 ASSERT_TRUE(db.LookupGlobalProperty(s, *manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseInternal1));
95
aceb0174c4ed fix unit test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 78
diff changeset
468 ASSERT_EQ("2", s);
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
469
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
470 OrthancPluginCreateInstanceResult r1, r2;
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
471
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
472 memset(&r1, 0, sizeof(r1));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
473 db.CreateInstance(r1, *manager, "a", "b", "c", "d");
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
474 ASSERT_TRUE(r1.isNewInstance);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
475 ASSERT_TRUE(r1.isNewSeries);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
476 ASSERT_TRUE(r1.isNewStudy);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
477 ASSERT_TRUE(r1.isNewPatient);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
478
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
479 memset(&r2, 0, sizeof(r2));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
480 db.CreateInstance(r2, *manager, "a", "b", "c", "d");
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
481 ASSERT_FALSE(r2.isNewInstance);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
482 ASSERT_EQ(r1.instanceId, r2.instanceId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
483
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
484 // Breaking the hierarchy
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
485 memset(&r2, 0, sizeof(r2));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
486 ASSERT_THROW(db.CreateInstance(r2, *manager, "a", "e", "c", "f"), Orthanc::OrthancException);
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
487
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
488 memset(&r2, 0, sizeof(r2));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
489 db.CreateInstance(r2, *manager, "a", "b", "c", "e");
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
490 ASSERT_TRUE(r2.isNewInstance);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
491 ASSERT_FALSE(r2.isNewSeries);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
492 ASSERT_FALSE(r2.isNewStudy);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
493 ASSERT_FALSE(r2.isNewPatient);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
494 ASSERT_EQ(r1.patientId, r2.patientId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
495 ASSERT_EQ(r1.studyId, r2.studyId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
496 ASSERT_EQ(r1.seriesId, r2.seriesId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
497 ASSERT_NE(r1.instanceId, r2.instanceId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
498
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
499 memset(&r2, 0, sizeof(r2));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
500 db.CreateInstance(r2, *manager, "a", "b", "f", "g");
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
501 ASSERT_TRUE(r2.isNewInstance);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
502 ASSERT_TRUE(r2.isNewSeries);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
503 ASSERT_FALSE(r2.isNewStudy);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
504 ASSERT_FALSE(r2.isNewPatient);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
505 ASSERT_EQ(r1.patientId, r2.patientId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
506 ASSERT_EQ(r1.studyId, r2.studyId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
507 ASSERT_NE(r1.seriesId, r2.seriesId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
508 ASSERT_NE(r1.instanceId, r2.instanceId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
509
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
510 memset(&r2, 0, sizeof(r2));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
511 db.CreateInstance(r2, *manager, "a", "h", "i", "j");
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
512 ASSERT_TRUE(r2.isNewInstance);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
513 ASSERT_TRUE(r2.isNewSeries);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
514 ASSERT_TRUE(r2.isNewStudy);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
515 ASSERT_FALSE(r2.isNewPatient);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
516 ASSERT_EQ(r1.patientId, r2.patientId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
517 ASSERT_NE(r1.studyId, r2.studyId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
518 ASSERT_NE(r1.seriesId, r2.seriesId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
519 ASSERT_NE(r1.instanceId, r2.instanceId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
520
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
521 memset(&r2, 0, sizeof(r2));
226
a4918d57435c DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 225
diff changeset
522 db.CreateInstance(r2, *manager, "k", "l", "m", "n");
71
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
523 ASSERT_TRUE(r2.isNewInstance);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
524 ASSERT_TRUE(r2.isNewSeries);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
525 ASSERT_TRUE(r2.isNewStudy);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
526 ASSERT_TRUE(r2.isNewPatient);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
527 ASSERT_NE(r1.patientId, r2.patientId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
528 ASSERT_NE(r1.studyId, r2.studyId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
529 ASSERT_NE(r1.seriesId, r2.seriesId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
530 ASSERT_NE(r1.instanceId, r2.instanceId);
d40c5fecd160 new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 67
diff changeset
531 }
73
aa81c1c80c75 fix compatibility with older sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 71
diff changeset
532 #endif
134
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
533
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
534
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
535 TEST(PostgreSQL, Lock2)
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
536 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
537 std::unique_ptr<PostgreSQLDatabase> db1(CreateTestDatabase());
134
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
538
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
539 ASSERT_FALSE(db1->ReleaseAdvisoryLock(43)); // lock counter = 0
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
540 ASSERT_TRUE(db1->AcquireAdvisoryLock(43)); // lock counter = 1
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
541
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
542 // OK, as this is the same connection
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
543 ASSERT_TRUE(db1->AcquireAdvisoryLock(43)); // lock counter = 2
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
544 ASSERT_TRUE(db1->ReleaseAdvisoryLock(43)); // lock counter = 1
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
545
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
546 // Try and release twice the lock
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
547 ASSERT_TRUE(db1->ReleaseAdvisoryLock(43)); // lock counter = 0
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
548 ASSERT_FALSE(db1->ReleaseAdvisoryLock(43)); // cannot unlock
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
549 ASSERT_TRUE(db1->AcquireAdvisoryLock(43)); // lock counter = 1
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
550
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
551 {
157
275e14f57f1e replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
552 std::unique_ptr<PostgreSQLDatabase> db2(CreateTestDatabase());
134
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
553
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
554 // The "db1" is still actively locking
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
555 ASSERT_FALSE(db2->AcquireAdvisoryLock(43));
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
556
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
557 // Release the "db1" lock
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
558 ASSERT_TRUE(db1->ReleaseAdvisoryLock(43));
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
559 ASSERT_FALSE(db1->ReleaseAdvisoryLock(43));
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
560
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
561 // "db2" can now acquire the lock, but not "db1"
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
562 ASSERT_TRUE(db2->AcquireAdvisoryLock(43));
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
563 ASSERT_FALSE(db1->AcquireAdvisoryLock(43));
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
564 }
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
565
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
566 // "db2" is closed, "db1" can now acquire the lock
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
567 ASSERT_TRUE(db1->AcquireAdvisoryLock(43));
cc3dc759c989 Added an advisory lock to avoid race conditions during database setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 95
diff changeset
568 }