Mercurial > hg > orthanc-databases
annotate Framework/Common/DatabaseManager.cpp @ 385:346fe629d638 db-protobuf
clarifying types of since/limit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Apr 2023 11:19:19 +0200 |
parents | 16aac0287485 |
children | 3d6886f3e5b3 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
359
16aac0287485
copyright upgraded to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
322
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
16aac0287485
copyright upgraded to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
322
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Affero General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "DatabaseManager.h" | |
24 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
25 #include "Integer64Value.h" |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
26 #include "BinaryStringValue.h" |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
27 #include "Utf8StringValue.h" |
116 | 28 |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
29 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 30 #include <Logging.h> |
31 #include <OrthancException.h> | |
0 | 32 |
33 #include <boost/thread.hpp> | |
34 | |
35 namespace OrthancDatabases | |
36 { | |
37 void DatabaseManager::Close() | |
38 { | |
39 LOG(TRACE) << "Closing the connection to the database"; | |
40 | |
41 // Rollback active transaction, if any | |
42 transaction_.reset(NULL); | |
43 | |
44 // Delete all the cached statements (must occur before closing | |
45 // the database) | |
46 for (CachedStatements::iterator it = cachedStatements_.begin(); | |
47 it != cachedStatements_.end(); ++it) | |
48 { | |
49 assert(it->second != NULL); | |
50 delete it->second; | |
51 } | |
52 | |
53 cachedStatements_.clear(); | |
54 | |
55 // Close the database | |
56 database_.reset(NULL); | |
57 | |
58 LOG(TRACE) << "Connection to the database is closed"; | |
59 } | |
60 | |
61 | |
62 void DatabaseManager::CloseIfUnavailable(Orthanc::ErrorCode e) | |
63 { | |
322
7e9622c64c40
compatibility with Orthanc framework < 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
64 if (e != Orthanc::ErrorCode_Success |
7e9622c64c40
compatibility with Orthanc framework < 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
65 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 2) |
7e9622c64c40
compatibility with Orthanc framework < 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
66 && e != Orthanc::ErrorCode_DatabaseCannotSerialize |
7e9622c64c40
compatibility with Orthanc framework < 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
67 #endif |
7e9622c64c40
compatibility with Orthanc framework < 1.9.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
305
diff
changeset
|
68 ) |
0 | 69 { |
70 transaction_.reset(NULL); | |
71 } | |
72 | |
73 if (e == Orthanc::ErrorCode_DatabaseUnavailable) | |
74 { | |
75 LOG(ERROR) << "The database is not available, closing the connection"; | |
76 Close(); | |
77 } | |
78 } | |
79 | |
80 | |
81 IPrecompiledStatement* DatabaseManager::LookupCachedStatement(const StatementLocation& location) const | |
82 { | |
83 CachedStatements::const_iterator found = cachedStatements_.find(location); | |
84 | |
85 if (found == cachedStatements_.end()) | |
86 { | |
87 return NULL; | |
88 } | |
89 else | |
90 { | |
91 assert(found->second != NULL); | |
92 return found->second; | |
93 } | |
94 } | |
95 | |
96 | |
97 IPrecompiledStatement& DatabaseManager::CacheStatement(const StatementLocation& location, | |
98 const Query& query) | |
99 { | |
100 LOG(TRACE) << "Caching statement from " << location.GetFile() << ":" << location.GetLine(); | |
101 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
102 std::unique_ptr<IPrecompiledStatement> statement(GetDatabase().Compile(query)); |
0 | 103 |
104 IPrecompiledStatement* tmp = statement.get(); | |
105 if (tmp == NULL) | |
106 { | |
107 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
108 } | |
109 | |
110 assert(cachedStatements_.find(location) == cachedStatements_.end()); | |
111 cachedStatements_[location] = statement.release(); | |
112 | |
113 return *tmp; | |
114 } | |
115 | |
116 | |
117 ITransaction& DatabaseManager::GetTransaction() | |
118 { | |
119 if (transaction_.get() == NULL) | |
120 { | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
121 LOG(TRACE) << "Automatically creating an implicit database transaction"; |
0 | 122 |
123 try | |
124 { | |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
125 transaction_.reset(GetDatabase().CreateTransaction(TransactionType_Implicit)); |
0 | 126 } |
127 catch (Orthanc::OrthancException& e) | |
128 { | |
129 CloseIfUnavailable(e.GetErrorCode()); | |
130 throw; | |
131 } | |
132 } | |
133 | |
134 assert(transaction_.get() != NULL); | |
135 return *transaction_; | |
136 } | |
137 | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
138 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
139 void DatabaseManager::ReleaseImplicitTransaction() |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
140 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
141 if (transaction_.get() != NULL && |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
142 transaction_->IsImplicit()) |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
143 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
144 LOG(TRACE) << "Committing an implicit database transaction"; |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
145 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
146 try |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
147 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
148 transaction_->Commit(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
149 transaction_.reset(NULL); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
150 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
151 catch (Orthanc::OrthancException& e) |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
152 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
153 // Don't throw the exception, as we are in CachedStatement destructor |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
154 LOG(ERROR) << "Error while committing an implicit database transaction: " << e.What(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
155 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
156 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
157 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
158 |
0 | 159 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
160 DatabaseManager::DatabaseManager(IDatabaseFactory* factory) : |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
161 factory_(factory), |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
162 dialect_(Dialect_Unknown) |
0 | 163 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
164 if (factory == NULL) |
0 | 165 { |
166 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
167 } | |
168 } | |
169 | |
170 | |
254
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
171 IDatabase& DatabaseManager::GetDatabase() |
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
172 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
173 assert(factory_.get() != NULL); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
174 |
254
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
175 if (database_.get() == NULL) |
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
176 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
177 database_.reset(factory_->Open()); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
178 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
179 if (database_.get() == NULL) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
180 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
181 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
182 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
183 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
184 dialect_ = database_->GetDialect(); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
185 if (dialect_ == Dialect_Unknown) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
186 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
187 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
188 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
189 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
190 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
191 return *database_; |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
192 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
193 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
194 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
195 Dialect DatabaseManager::GetDialect() const |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
196 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
197 if (database_.get() == NULL) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
198 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
199 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
254
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
200 } |
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
201 else |
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
202 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
203 assert(dialect_ != Dialect_Unknown); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
204 return dialect_; |
254
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
205 } |
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
206 } |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
254
diff
changeset
|
207 |
254
8a4ce70f456a
fix crash if connection to server is lost
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
242
diff
changeset
|
208 |
207
d9ef3f16e6a2
wrapping transactions in API v3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
209 void DatabaseManager::StartTransaction(TransactionType type) |
0 | 210 { |
211 try | |
212 { | |
213 if (transaction_.get() != NULL) | |
214 { | |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
215 LOG(ERROR) << "Cannot start another transaction while there is an uncommitted transaction"; |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
216 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
0 | 217 } |
218 | |
215
b40b30075c51
added TransactionType_Implicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
219 transaction_.reset(GetDatabase().CreateTransaction(type)); |
0 | 220 } |
221 catch (Orthanc::OrthancException& e) | |
222 { | |
223 CloseIfUnavailable(e.GetErrorCode()); | |
224 throw; | |
225 } | |
226 } | |
227 | |
228 | |
229 void DatabaseManager::CommitTransaction() | |
230 { | |
231 if (transaction_.get() == NULL) | |
232 { | |
233 LOG(ERROR) << "Cannot commit a non-existing transaction"; | |
234 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
235 } | |
236 else | |
237 { | |
238 try | |
239 { | |
240 transaction_->Commit(); | |
241 transaction_.reset(NULL); | |
242 } | |
243 catch (Orthanc::OrthancException& e) | |
244 { | |
245 CloseIfUnavailable(e.GetErrorCode()); | |
246 throw; | |
247 } | |
248 } | |
249 } | |
250 | |
251 | |
252 void DatabaseManager::RollbackTransaction() | |
253 { | |
254 if (transaction_.get() == NULL) | |
255 { | |
234
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
231
diff
changeset
|
256 LOG(INFO) << "Cannot rollback a non-existing transaction"; |
0 | 257 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
258 } | |
259 else | |
260 { | |
261 try | |
262 { | |
263 transaction_->Rollback(); | |
264 transaction_.reset(NULL); | |
265 } | |
266 catch (Orthanc::OrthancException& e) | |
267 { | |
268 CloseIfUnavailable(e.GetErrorCode()); | |
269 throw; | |
270 } | |
271 } | |
272 } | |
273 | |
274 | |
207
d9ef3f16e6a2
wrapping transactions in API v3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
275 DatabaseManager::Transaction::Transaction(DatabaseManager& manager, |
d9ef3f16e6a2
wrapping transactions in API v3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
276 TransactionType type) : |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
277 manager_(manager), |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
278 database_(manager.GetDatabase()), |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
279 active_(true) |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
280 { |
207
d9ef3f16e6a2
wrapping transactions in API v3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
281 manager_.StartTransaction(type); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
282 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
283 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
284 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
285 DatabaseManager::Transaction::~Transaction() |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
286 { |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
287 if (active_) |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
288 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
289 try |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
290 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
291 manager_.RollbackTransaction(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
292 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
293 catch (Orthanc::OrthancException& e) |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
294 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
295 // Don't rethrow the exception as we are in a destructor |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
296 LOG(ERROR) << "Uncatched error during some transaction rollback: " << e.What(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
297 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
298 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
299 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
300 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
301 |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
302 void DatabaseManager::Transaction::Commit() |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
303 { |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
304 if (active_) |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
305 { |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
306 manager_.CommitTransaction(); |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
307 active_ = false; |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
308 } |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
309 else |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
310 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
311 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
312 } |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
313 } |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
314 |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
315 |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
316 void DatabaseManager::Transaction::Rollback() |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
317 { |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
318 if (active_) |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
319 { |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
320 manager_.RollbackTransaction(); |
242
b97a537f4613
MySQL: Support of range reads for the storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
321 active_ = false; |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
322 } |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
323 else |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
324 { |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
325 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
326 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
327 } |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
328 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
329 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
330 IResult& DatabaseManager::StatementBase::GetResult() const |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
331 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
332 if (result_.get() == NULL) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
333 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
334 LOG(ERROR) << "Accessing the results of a statement without having executed it"; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
335 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
336 } |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
337 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
338 return *result_; |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
339 } |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
340 |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
341 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
342 void DatabaseManager::StatementBase::SetQuery(Query* query) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
343 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
344 std::unique_ptr<Query> protection(query); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
345 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
346 if (query_.get() != NULL) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
347 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
348 LOG(ERROR) << "Cannot set twice a query"; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
349 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
350 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
351 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
352 if (query == NULL) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
353 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
354 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
355 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
356 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
357 query_.reset(protection.release()); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
358 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
359 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
360 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
361 void DatabaseManager::StatementBase::SetResult(IResult* result) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
362 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
363 if (result == NULL) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
364 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
365 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
366 } |
305
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
297
diff
changeset
|
367 else |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
297
diff
changeset
|
368 { |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
297
diff
changeset
|
369 result_.reset(result); |
87f0e29a1dc1
added Dictionary::Clear()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
297
diff
changeset
|
370 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
371 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
372 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
373 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
374 DatabaseManager::StatementBase::StatementBase(DatabaseManager& manager) : |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
375 manager_(manager), |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
376 transaction_(manager_.GetTransaction()) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
377 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
378 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
379 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
380 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
381 DatabaseManager::StatementBase::~StatementBase() |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
382 { |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
383 manager_.ReleaseImplicitTransaction(); |
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
384 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
385 |
23
b2ff1cd2907a
handling of implicit transactions in DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
18
diff
changeset
|
386 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
387 void DatabaseManager::StatementBase::SetReadOnly(bool readOnly) |
0 | 388 { |
389 if (query_.get() != NULL) | |
390 { | |
391 query_->SetReadOnly(readOnly); | |
392 } | |
393 } | |
394 | |
395 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
396 void DatabaseManager::StatementBase::SetParameterType(const std::string& parameter, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
397 ValueType type) |
0 | 398 { |
399 if (query_.get() != NULL) | |
400 { | |
401 query_->SetType(parameter, type); | |
402 } | |
403 } | |
404 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
405 bool DatabaseManager::StatementBase::IsDone() const |
0 | 406 { |
407 try | |
408 { | |
409 return GetResult().IsDone(); | |
410 } | |
411 catch (Orthanc::OrthancException& e) | |
412 { | |
413 manager_.CloseIfUnavailable(e.GetErrorCode()); | |
414 throw; | |
415 } | |
416 } | |
417 | |
418 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
419 void DatabaseManager::StatementBase::Next() |
0 | 420 { |
421 try | |
422 { | |
423 GetResult().Next(); | |
424 } | |
425 catch (Orthanc::OrthancException& e) | |
426 { | |
427 manager_.CloseIfUnavailable(e.GetErrorCode()); | |
428 throw; | |
429 } | |
430 } | |
431 | |
432 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
433 size_t DatabaseManager::StatementBase::GetResultFieldsCount() const |
0 | 434 { |
435 try | |
436 { | |
437 return GetResult().GetFieldsCount(); | |
438 } | |
439 catch (Orthanc::OrthancException& e) | |
440 { | |
441 manager_.CloseIfUnavailable(e.GetErrorCode()); | |
442 throw; | |
443 } | |
444 } | |
445 | |
446 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
447 void DatabaseManager::StatementBase::SetResultFieldType(size_t field, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
448 ValueType type) |
0 | 449 { |
450 try | |
451 { | |
452 if (!GetResult().IsDone()) | |
453 { | |
454 GetResult().SetExpectedType(field, type); | |
455 } | |
456 } | |
457 catch (Orthanc::OrthancException& e) | |
458 { | |
459 manager_.CloseIfUnavailable(e.GetErrorCode()); | |
460 throw; | |
461 } | |
462 } | |
463 | |
464 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
465 const IValue& DatabaseManager::StatementBase::GetResultField(size_t index) const |
0 | 466 { |
467 try | |
468 { | |
469 return GetResult().GetField(index); | |
470 } | |
471 catch (Orthanc::OrthancException& e) | |
472 { | |
473 manager_.CloseIfUnavailable(e.GetErrorCode()); | |
474 throw; | |
475 } | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
476 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
477 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
478 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
479 int64_t DatabaseManager::StatementBase::ReadInteger64(size_t field) const |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
480 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
481 if (IsDone()) |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
482 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
483 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
484 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
485 else |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
486 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
487 const IValue& value = GetResultField(field); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
488 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
489 switch (value.GetType()) |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
490 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
491 case ValueType_Integer64: |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
492 return dynamic_cast<const Integer64Value&>(value).GetValue(); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
493 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
494 default: |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
495 //LOG(ERROR) << value.Format(); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
496 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
497 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
498 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
499 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
500 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
501 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
502 int32_t DatabaseManager::StatementBase::ReadInteger32(size_t field) const |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
503 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
504 if (IsDone()) |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
505 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
506 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
507 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
508 else |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
509 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
510 int64_t value = ReadInteger64(field); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
511 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
512 if (value != static_cast<int64_t>(static_cast<int32_t>(value))) |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
513 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
514 LOG(ERROR) << "Integer overflow"; |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
515 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
516 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
517 else |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
518 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
519 return static_cast<int32_t>(value); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
520 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
521 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
522 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
523 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
524 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
525 std::string DatabaseManager::StatementBase::ReadString(size_t field) const |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
526 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
527 const IValue& value = GetResultField(field); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
528 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
529 switch (value.GetType()) |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
530 { |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
531 case ValueType_BinaryString: |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
532 return dynamic_cast<const BinaryStringValue&>(value).GetContent(); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
533 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
534 case ValueType_Utf8String: |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
535 return dynamic_cast<const Utf8StringValue&>(value).GetContent(); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
536 |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
537 default: |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
538 //LOG(ERROR) << value.Format(); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
539 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
540 } |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
541 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
542 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
543 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
544 DatabaseManager::CachedStatement::CachedStatement(const StatementLocation& location, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
545 DatabaseManager& manager, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
546 const std::string& sql) : |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
547 StatementBase(manager), |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
548 location_(location) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
549 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
550 statement_ = GetManager().LookupCachedStatement(location_); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
551 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
552 if (statement_ == NULL) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
553 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
554 SetQuery(new Query(sql)); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
555 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
556 else |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
557 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
558 LOG(TRACE) << "Reusing cached statement from " |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
559 << location_.GetFile() << ":" << location_.GetLine(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
560 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
561 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
562 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
563 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
564 void DatabaseManager::CachedStatement::Execute(const Dictionary& parameters) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
565 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
566 try |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
567 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
568 std::unique_ptr<Query> query(ReleaseQuery()); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
569 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
570 if (query.get() != NULL) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
571 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
572 // Register the newly-created statement |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
573 assert(statement_ == NULL); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
574 statement_ = &GetManager().CacheStatement(location_, *query); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
575 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
576 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
577 assert(statement_ != NULL); |
116 | 578 |
579 /* | |
580 TODO - Sample code to monitor the execution time of each | |
581 cached statement, and publish it as an Orthanc metrics | |
582 | |
583 #if HAS_ORTHANC_PLUGIN_METRICS == 1 | |
584 std::string name = (std::string(location_.GetFile()) + "_" + | |
585 boost::lexical_cast<std::string>(location_.GetLine())); | |
586 OrthancPlugins::MetricsTimer timer(name.c_str()); | |
587 #endif | |
588 */ | |
589 | |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
590 SetResult(GetTransaction().Execute(*statement_, parameters)); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
591 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
592 catch (Orthanc::OrthancException& e) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
593 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
594 GetManager().CloseIfUnavailable(e.GetErrorCode()); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
595 throw; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
596 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
597 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
598 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
599 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
600 DatabaseManager::StandaloneStatement::StandaloneStatement(DatabaseManager& manager, |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
601 const std::string& sql) : |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
602 StatementBase(manager) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
603 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
604 SetQuery(new Query(sql)); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
605 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
606 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
607 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
608 DatabaseManager::StandaloneStatement::~StandaloneStatement() |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
609 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
610 // The result must be removed before the statement, cf. (*) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
611 ClearResult(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
612 statement_.reset(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
613 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
614 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
615 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
616 void DatabaseManager::StandaloneStatement::Execute(const Dictionary& parameters) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
617 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
618 try |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
619 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
620 std::unique_ptr<Query> query(ReleaseQuery()); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
621 assert(query.get() != NULL); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
622 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
623 // The "statement_" object must be kept as long as the "IResult" |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
624 // is not destroyed, as the "IResult" can make calls to the |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
625 // statement (this is the case for SQLite and MySQL) - (*) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
626 statement_.reset(GetManager().GetDatabase().Compile(*query)); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
627 assert(statement_.get() != NULL); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
628 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
629 SetResult(GetTransaction().Execute(*statement_, parameters)); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
630 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
631 catch (Orthanc::OrthancException& e) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
632 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
633 GetManager().CloseIfUnavailable(e.GetErrorCode()); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
634 throw; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
635 } |
0 | 636 } |
637 } |