Mercurial > hg > orthanc-databases
annotate Framework/Plugins/IndexBackend.cpp @ 432:8b7c1c423367 pg-transactions
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 11 Dec 2023 14:39:27 +0100 |
parents | 7c1fe5d6c12c |
children | 5964ce6385a5 |
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 | |
389
3d6886f3e5b3
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
3d6886f3e5b3
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
385
diff
changeset
|
6 * Copyright (C) 2021-2023 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 "IndexBackend.h" | |
24 | |
25 #include "../Common/BinaryStringValue.h" | |
26 #include "../Common/Integer64Value.h" | |
27 #include "../Common/Utf8StringValue.h" | |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
28 #include "DatabaseBackendAdapterV2.h" |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
29 #include "DatabaseBackendAdapterV3.h" |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
30 #include "DatabaseBackendAdapterV4.h" |
0 | 31 #include "GlobalProperties.h" |
32 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
33 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 34 #include <Logging.h> |
35 #include <OrthancException.h> | |
0 | 36 |
37 | |
38 namespace OrthancDatabases | |
39 { | |
40 static std::string ConvertWildcardToLike(const std::string& query) | |
41 { | |
42 std::string s = query; | |
43 | |
44 for (size_t i = 0; i < s.size(); i++) | |
45 { | |
46 if (s[i] == '*') | |
47 { | |
48 s[i] = '%'; | |
49 } | |
50 else if (s[i] == '?') | |
51 { | |
52 s[i] = '_'; | |
53 } | |
54 } | |
55 | |
65 | 56 // TODO Escape underscores and percents |
57 | |
0 | 58 return s; |
59 } | |
60 | |
61 | |
62 template <typename T> | |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
63 static void ReadListOfIntegers(std::list<T>& target, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
64 DatabaseManager::CachedStatement& statement, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
65 const Dictionary& args) |
0 | 66 { |
67 statement.Execute(args); | |
68 | |
69 target.clear(); | |
70 | |
71 if (!statement.IsDone()) | |
72 { | |
73 if (statement.GetResultFieldsCount() != 1) | |
74 { | |
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
76 } | |
77 | |
78 statement.SetResultFieldType(0, ValueType_Integer64); | |
79 | |
80 while (!statement.IsDone()) | |
81 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
82 target.push_back(static_cast<T>(statement.ReadInteger64(0))); |
0 | 83 statement.Next(); |
84 } | |
85 } | |
86 } | |
87 | |
88 | |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
89 static void ReadListOfStrings(std::list<std::string>& target, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
90 DatabaseManager::CachedStatement& statement, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
91 const Dictionary& args) |
0 | 92 { |
93 statement.Execute(args); | |
94 | |
95 target.clear(); | |
96 | |
97 if (!statement.IsDone()) | |
98 { | |
99 if (statement.GetResultFieldsCount() != 1) | |
100 { | |
101 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
102 } | |
103 | |
104 while (!statement.IsDone()) | |
105 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
106 target.push_back(statement.ReadString(0)); |
0 | 107 statement.Next(); |
108 } | |
109 } | |
110 } | |
111 | |
112 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
113 void IndexBackend::ReadChangesInternal(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
114 bool& done, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
115 DatabaseManager& manager, |
0 | 116 DatabaseManager::CachedStatement& statement, |
117 const Dictionary& args, | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
118 uint32_t limit) |
0 | 119 { |
120 statement.Execute(args); | |
121 | |
122 uint32_t count = 0; | |
123 | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
124 while (count < limit && |
0 | 125 !statement.IsDone()) |
126 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
127 output.AnswerChange( |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
128 statement.ReadInteger64(0), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
129 statement.ReadInteger32(1), |
310
f3eac614b32e
fixed two DatabaseManager::CachedStatement in the same scope
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
130 static_cast<OrthancPluginResourceType>(statement.ReadInteger32(2)), |
f3eac614b32e
fixed two DatabaseManager::CachedStatement in the same scope
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
131 statement.ReadString(3), |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
132 statement.ReadString(4)); |
0 | 133 |
134 statement.Next(); | |
135 count++; | |
136 } | |
137 | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
138 done = (count < limit || |
0 | 139 statement.IsDone()); |
140 } | |
141 | |
142 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
143 void IndexBackend::ReadExportedResourcesInternal(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
144 bool& done, |
0 | 145 DatabaseManager::CachedStatement& statement, |
146 const Dictionary& args, | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
147 uint32_t limit) |
0 | 148 { |
149 statement.Execute(args); | |
150 | |
151 uint32_t count = 0; | |
152 | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
153 while (count < limit && |
0 | 154 !statement.IsDone()) |
155 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
156 int64_t seq = statement.ReadInteger64(0); |
0 | 157 OrthancPluginResourceType resourceType = |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
158 static_cast<OrthancPluginResourceType>(statement.ReadInteger32(1)); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
159 std::string publicId = statement.ReadString(2); |
0 | 160 |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
161 output.AnswerExportedResource(seq, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
162 resourceType, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
163 publicId, |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
164 statement.ReadString(3), // modality |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
165 statement.ReadString(8), // date |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
166 statement.ReadString(4), // patient ID |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
167 statement.ReadString(5), // study instance UID |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
168 statement.ReadString(6), // series instance UID |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
169 statement.ReadString(7)); // sop instance UID |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
170 |
0 | 171 statement.Next(); |
172 count++; | |
173 } | |
174 | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
175 done = (count < limit || |
0 | 176 statement.IsDone()); |
177 } | |
178 | |
179 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
180 void IndexBackend::ClearDeletedFiles(DatabaseManager& manager) |
0 | 181 { |
182 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
183 STATEMENT_FROM_HERE, manager, |
0 | 184 "DELETE FROM DeletedFiles"); |
185 | |
186 statement.Execute(); | |
187 } | |
188 | |
189 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
190 void IndexBackend::ClearDeletedResources(DatabaseManager& manager) |
0 | 191 { |
192 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
193 STATEMENT_FROM_HERE, manager, |
0 | 194 "DELETE FROM DeletedResources"); |
195 | |
196 statement.Execute(); | |
197 } | |
198 | |
199 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
200 void IndexBackend::SignalDeletedFiles(IDatabaseBackendOutput& output, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
201 DatabaseManager& manager) |
0 | 202 { |
203 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
204 STATEMENT_FROM_HERE, manager, |
314
64763998cdff
clarification in IndexBackend::SignalDeletedFiles()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
205 "SELECT uuid, fileType, uncompressedSize, uncompressedHash, compressionType, " |
64763998cdff
clarification in IndexBackend::SignalDeletedFiles()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
206 "compressedSize, compressedHash FROM DeletedFiles"); |
0 | 207 |
208 statement.SetReadOnly(true); | |
209 statement.Execute(); | |
210 | |
211 while (!statement.IsDone()) | |
212 { | |
314
64763998cdff
clarification in IndexBackend::SignalDeletedFiles()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
213 output.SignalDeletedAttachment(statement.ReadString(0), |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
214 statement.ReadInteger32(1), |
314
64763998cdff
clarification in IndexBackend::SignalDeletedFiles()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
215 statement.ReadInteger64(2), |
64763998cdff
clarification in IndexBackend::SignalDeletedFiles()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
216 statement.ReadString(3), |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
217 statement.ReadInteger32(4), |
314
64763998cdff
clarification in IndexBackend::SignalDeletedFiles()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
218 statement.ReadInteger64(5), |
64763998cdff
clarification in IndexBackend::SignalDeletedFiles()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
310
diff
changeset
|
219 statement.ReadString(6)); |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
220 |
0 | 221 statement.Next(); |
222 } | |
223 } | |
224 | |
225 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
226 void IndexBackend::SignalDeletedResources(IDatabaseBackendOutput& output, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
227 DatabaseManager& manager) |
0 | 228 { |
229 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
230 STATEMENT_FROM_HERE, manager, |
307
8de3a1ecac11
MySQL: Added missing calls to OrthancPluginDatabaseSignalDeletedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
306
diff
changeset
|
231 "SELECT resourceType, publicId FROM DeletedResources"); |
0 | 232 |
233 statement.SetReadOnly(true); | |
234 statement.Execute(); | |
235 | |
236 while (!statement.IsDone()) | |
237 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
238 output.SignalDeletedResource( |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
239 statement.ReadString(1), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
240 static_cast<OrthancPluginResourceType>(statement.ReadInteger32(0))); |
0 | 241 |
242 statement.Next(); | |
243 } | |
244 } | |
245 | |
246 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
247 IndexBackend::IndexBackend(OrthancPluginContext* context) : |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
248 context_(context) |
0 | 249 { |
250 } | |
251 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
252 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
253 void IndexBackend::SetOutputFactory(IDatabaseBackendOutput::IFactory* factory) |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
254 { |
232
4e15eace9b90
reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
255 boost::unique_lock<boost::shared_mutex> lock(outputFactoryMutex_); |
4e15eace9b90
reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
256 |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
257 if (factory == NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
258 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
259 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
260 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
261 else if (outputFactory_.get() != NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
262 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
263 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
264 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
265 else |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
266 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
267 outputFactory_.reset(factory); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
268 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
269 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
270 |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
271 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
272 IDatabaseBackendOutput* IndexBackend::CreateOutput() |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
273 { |
232
4e15eace9b90
reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
274 boost::shared_lock<boost::shared_mutex> lock(outputFactoryMutex_); |
4e15eace9b90
reorganization in DatabaseBackendAdapterV3
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
275 |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
276 if (outputFactory_.get() == NULL) |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
277 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
278 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
279 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
280 else |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
281 { |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
282 return outputFactory_->CreateOutput(); |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
283 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
284 } |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
285 |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
286 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
287 static void ExecuteAddAttachment(DatabaseManager::CachedStatement& statement, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
288 Dictionary& args, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
289 int64_t id, |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
290 const OrthancPluginAttachment& attachment) |
0 | 291 { |
292 statement.SetParameterType("id", ValueType_Integer64); | |
293 statement.SetParameterType("type", ValueType_Integer64); | |
294 statement.SetParameterType("uuid", ValueType_Utf8String); | |
295 statement.SetParameterType("compressed", ValueType_Integer64); | |
296 statement.SetParameterType("uncompressed", ValueType_Integer64); | |
297 statement.SetParameterType("compression", ValueType_Integer64); | |
298 statement.SetParameterType("hash", ValueType_Utf8String); | |
299 statement.SetParameterType("hash-compressed", ValueType_Utf8String); | |
300 | |
301 args.SetIntegerValue("id", id); | |
302 args.SetIntegerValue("type", attachment.contentType); | |
303 args.SetUtf8Value("uuid", attachment.uuid); | |
304 args.SetIntegerValue("compressed", attachment.compressedSize); | |
305 args.SetIntegerValue("uncompressed", attachment.uncompressedSize); | |
306 args.SetIntegerValue("compression", attachment.compressionType); | |
307 args.SetUtf8Value("hash", attachment.uncompressedHash); | |
308 args.SetUtf8Value("hash-compressed", attachment.compressedHash); | |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
309 |
0 | 310 statement.Execute(args); |
311 } | |
312 | |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
313 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
314 void IndexBackend::AddAttachment(DatabaseManager& manager, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
315 int64_t id, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
316 const OrthancPluginAttachment& attachment, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
317 int64_t revision) |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
318 { |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
319 if (HasRevisionsSupport()) |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
320 { |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
321 DatabaseManager::CachedStatement statement( |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
322 STATEMENT_FROM_HERE, manager, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
323 "INSERT INTO AttachedFiles VALUES(${id}, ${type}, ${uuid}, ${compressed}, " |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
324 "${uncompressed}, ${compression}, ${hash}, ${hash-compressed}, ${revision})"); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
325 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
326 Dictionary args; |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
327 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
328 statement.SetParameterType("revision", ValueType_Integer64); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
329 args.SetIntegerValue("revision", revision); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
330 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
331 ExecuteAddAttachment(statement, args, id, attachment); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
332 } |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
333 else |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
334 { |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
335 DatabaseManager::CachedStatement statement( |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
336 STATEMENT_FROM_HERE, manager, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
337 "INSERT INTO AttachedFiles VALUES(${id}, ${type}, ${uuid}, ${compressed}, " |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
338 "${uncompressed}, ${compression}, ${hash}, ${hash-compressed})"); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
339 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
340 Dictionary args; |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
341 ExecuteAddAttachment(statement, args, id, attachment); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
342 } |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
343 } |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
344 |
0 | 345 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
346 void IndexBackend::AttachChild(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
347 int64_t parent, |
0 | 348 int64_t child) |
349 { | |
350 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
351 STATEMENT_FROM_HERE, manager, |
0 | 352 "UPDATE Resources SET parentId = ${parent} WHERE internalId = ${child}"); |
353 | |
354 statement.SetParameterType("parent", ValueType_Integer64); | |
355 statement.SetParameterType("child", ValueType_Integer64); | |
356 | |
357 Dictionary args; | |
358 args.SetIntegerValue("parent", parent); | |
359 args.SetIntegerValue("child", child); | |
360 | |
361 statement.Execute(args); | |
362 } | |
363 | |
364 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
365 void IndexBackend::ClearChanges(DatabaseManager& manager) |
0 | 366 { |
367 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
368 STATEMENT_FROM_HERE, manager, |
0 | 369 "DELETE FROM Changes"); |
370 | |
371 statement.Execute(); | |
372 } | |
373 | |
374 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
375 void IndexBackend::ClearExportedResources(DatabaseManager& manager) |
0 | 376 { |
377 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
378 STATEMENT_FROM_HERE, manager, |
0 | 379 "DELETE FROM ExportedResources"); |
380 | |
381 statement.Execute(); | |
382 } | |
383 | |
384 | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
385 void IndexBackend::DeleteAttachment(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
386 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
387 int64_t id, |
0 | 388 int32_t attachment) |
389 { | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
390 ClearDeletedFiles(manager); |
0 | 391 |
392 { | |
393 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
394 STATEMENT_FROM_HERE, manager, |
0 | 395 "DELETE FROM AttachedFiles WHERE id=${id} AND fileType=${type}"); |
396 | |
397 statement.SetParameterType("id", ValueType_Integer64); | |
398 statement.SetParameterType("type", ValueType_Integer64); | |
399 | |
400 Dictionary args; | |
401 args.SetIntegerValue("id", id); | |
402 args.SetIntegerValue("type", static_cast<int>(attachment)); | |
403 | |
404 statement.Execute(args); | |
405 } | |
406 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
407 SignalDeletedFiles(output, manager); |
0 | 408 } |
409 | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
410 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
411 void IndexBackend::DeleteMetadata(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
412 int64_t id, |
0 | 413 int32_t metadataType) |
414 { | |
415 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
416 STATEMENT_FROM_HERE, manager, |
0 | 417 "DELETE FROM Metadata WHERE id=${id} and type=${type}"); |
418 | |
419 statement.SetParameterType("id", ValueType_Integer64); | |
420 statement.SetParameterType("type", ValueType_Integer64); | |
421 | |
422 Dictionary args; | |
423 args.SetIntegerValue("id", id); | |
424 args.SetIntegerValue("type", static_cast<int>(metadataType)); | |
425 | |
426 statement.Execute(args); | |
427 } | |
428 | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
429 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
430 void IndexBackend::DeleteResource(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
431 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
432 int64_t id) |
0 | 433 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
434 ClearDeletedFiles(manager); |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
435 ClearDeletedResources(manager); |
0 | 436 |
437 { | |
438 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
439 STATEMENT_FROM_HERE, manager, |
0 | 440 "DELETE FROM RemainingAncestor"); |
441 | |
442 statement.Execute(); | |
443 } | |
444 | |
445 { | |
446 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
447 STATEMENT_FROM_HERE, manager, |
0 | 448 "DELETE FROM Resources WHERE internalId=${id}"); |
449 | |
450 statement.SetParameterType("id", ValueType_Integer64); | |
451 | |
452 Dictionary args; | |
453 args.SetIntegerValue("id", id); | |
454 | |
455 statement.Execute(args); | |
456 } | |
457 | |
458 | |
459 { | |
460 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
461 STATEMENT_FROM_HERE, manager, |
0 | 462 "SELECT * FROM RemainingAncestor"); |
463 | |
464 statement.Execute(); | |
465 | |
466 if (!statement.IsDone()) | |
467 { | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
468 output.SignalRemainingAncestor( |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
469 statement.ReadString(1), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
470 static_cast<OrthancPluginResourceType>(statement.ReadInteger32(0))); |
0 | 471 |
472 // There is at most 1 remaining ancestor | |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
431
diff
changeset
|
473 //assert((statement.Next(), statement.IsDone())); |
0 | 474 } |
475 } | |
476 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
477 SignalDeletedFiles(output, manager); |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
478 SignalDeletedResources(output, manager); |
0 | 479 } |
480 | |
481 | |
482 void IndexBackend::GetAllInternalIds(std::list<int64_t>& target, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
483 DatabaseManager& manager, |
0 | 484 OrthancPluginResourceType resourceType) |
485 { | |
486 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
487 STATEMENT_FROM_HERE, manager, |
0 | 488 "SELECT internalId FROM Resources WHERE resourceType=${type}"); |
489 | |
490 statement.SetReadOnly(true); | |
491 statement.SetParameterType("type", ValueType_Integer64); | |
492 | |
493 Dictionary args; | |
494 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
495 | |
496 ReadListOfIntegers<int64_t>(target, statement, args); | |
497 } | |
498 | |
499 | |
500 void IndexBackend::GetAllPublicIds(std::list<std::string>& target, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
501 DatabaseManager& manager, |
0 | 502 OrthancPluginResourceType resourceType) |
503 { | |
504 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
505 STATEMENT_FROM_HERE, manager, |
0 | 506 "SELECT publicId FROM Resources WHERE resourceType=${type}"); |
507 | |
508 statement.SetReadOnly(true); | |
509 statement.SetParameterType("type", ValueType_Integer64); | |
510 | |
511 Dictionary args; | |
512 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
513 | |
514 ReadListOfStrings(target, statement, args); | |
515 } | |
516 | |
517 | |
518 void IndexBackend::GetAllPublicIds(std::list<std::string>& target, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
519 DatabaseManager& manager, |
0 | 520 OrthancPluginResourceType resourceType, |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
521 int64_t since, |
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
522 uint32_t limit) |
0 | 523 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
524 std::string suffix; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
525 if (manager.GetDialect() == Dialect_MSSQL) |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
526 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
527 suffix = "OFFSET ${since} ROWS FETCH FIRST ${limit} ROWS ONLY"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
528 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
529 else |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
530 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
531 suffix = "LIMIT ${limit} OFFSET ${since}"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
532 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
533 |
0 | 534 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
535 STATEMENT_FROM_HERE, manager, |
0 | 536 "SELECT publicId FROM (SELECT publicId FROM Resources " |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
537 "WHERE resourceType=${type}) AS tmp ORDER BY tmp.publicId " + suffix); |
0 | 538 |
539 statement.SetReadOnly(true); | |
540 statement.SetParameterType("type", ValueType_Integer64); | |
541 statement.SetParameterType("limit", ValueType_Integer64); | |
542 statement.SetParameterType("since", ValueType_Integer64); | |
543 | |
544 Dictionary args; | |
545 args.SetIntegerValue("type", static_cast<int>(resourceType)); | |
546 args.SetIntegerValue("limit", limit); | |
547 args.SetIntegerValue("since", since); | |
548 | |
549 ReadListOfStrings(target, statement, args); | |
550 } | |
551 | |
552 | |
553 /* Use GetOutput().AnswerChange() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
554 void IndexBackend::GetChanges(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
555 bool& done /*out*/, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
556 DatabaseManager& manager, |
0 | 557 int64_t since, |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
558 uint32_t limit) |
0 | 559 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
560 std::string suffix; |
304
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
561 if (manager.GetDialect() == Dialect_MSSQL) |
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
562 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
563 suffix = "OFFSET 0 ROWS FETCH FIRST ${limit} ROWS ONLY"; |
304
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
564 } |
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
565 else |
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
566 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
567 suffix = "LIMIT ${limit}"; |
304
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
568 } |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
569 |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
570 DatabaseManager::CachedStatement statement( |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
571 STATEMENT_FROM_HERE, manager, |
326
4454545bb265
Fix issue 200 (fields messed up in /changes route)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
572 "SELECT Changes.seq, Changes.changeType, Changes.resourceType, Resources.publicId, " |
4454545bb265
Fix issue 200 (fields messed up in /changes route)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
573 "Changes.date FROM Changes INNER JOIN Resources " |
310
f3eac614b32e
fixed two DatabaseManager::CachedStatement in the same scope
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
574 "ON Changes.internalId = Resources.internalId WHERE seq>${since} ORDER BY seq " + suffix); |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
575 |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
576 statement.SetReadOnly(true); |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
577 statement.SetParameterType("limit", ValueType_Integer64); |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
578 statement.SetParameterType("since", ValueType_Integer64); |
0 | 579 |
580 Dictionary args; | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
581 args.SetIntegerValue("limit", limit + 1); |
0 | 582 args.SetIntegerValue("since", since); |
583 | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
584 ReadChangesInternal(output, done, manager, statement, args, limit); |
0 | 585 } |
586 | |
587 | |
588 void IndexBackend::GetChildrenInternalId(std::list<int64_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
589 DatabaseManager& manager, |
0 | 590 int64_t id) |
591 { | |
592 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
593 STATEMENT_FROM_HERE, manager, |
0 | 594 "SELECT a.internalId FROM Resources AS a, Resources AS b " |
595 "WHERE a.parentId = b.internalId AND b.internalId = ${id}"); | |
596 | |
597 statement.SetReadOnly(true); | |
598 statement.SetParameterType("id", ValueType_Integer64); | |
599 | |
600 Dictionary args; | |
601 args.SetIntegerValue("id", id); | |
602 | |
603 ReadListOfIntegers<int64_t>(target, statement, args); | |
604 } | |
605 | |
606 | |
607 void IndexBackend::GetChildrenPublicId(std::list<std::string>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
608 DatabaseManager& manager, |
0 | 609 int64_t id) |
610 { | |
611 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
612 STATEMENT_FROM_HERE, manager, |
0 | 613 "SELECT a.publicId FROM Resources AS a, Resources AS b " |
614 "WHERE a.parentId = b.internalId AND b.internalId = ${id}"); | |
615 | |
616 statement.SetReadOnly(true); | |
617 statement.SetParameterType("id", ValueType_Integer64); | |
618 | |
619 Dictionary args; | |
620 args.SetIntegerValue("id", id); | |
621 | |
622 ReadListOfStrings(target, statement, args); | |
623 } | |
624 | |
625 | |
626 /* Use GetOutput().AnswerExportedResource() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
627 void IndexBackend::GetExportedResources(IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
628 bool& done /*out*/, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
629 DatabaseManager& manager, |
0 | 630 int64_t since, |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
631 uint32_t limit) |
0 | 632 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
633 std::string suffix; |
304
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
634 if (manager.GetDialect() == Dialect_MSSQL) |
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
635 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
636 suffix = "OFFSET 0 ROWS FETCH FIRST ${limit} ROWS ONLY"; |
304
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
637 } |
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
638 else |
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
639 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
640 suffix = "LIMIT ${limit}"; |
304
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
641 } |
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
642 |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
643 DatabaseManager::CachedStatement statement( |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
644 STATEMENT_FROM_HERE, manager, |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
645 "SELECT * FROM ExportedResources WHERE seq>${since} ORDER BY seq " + suffix); |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
646 |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
647 statement.SetReadOnly(true); |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
648 statement.SetParameterType("limit", ValueType_Integer64); |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
649 statement.SetParameterType("since", ValueType_Integer64); |
0 | 650 |
651 Dictionary args; | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
652 args.SetIntegerValue("limit", limit + 1); |
0 | 653 args.SetIntegerValue("since", since); |
654 | |
385
346fe629d638
clarifying types of since/limit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
655 ReadExportedResourcesInternal(output, done, statement, args, limit); |
0 | 656 } |
657 | |
658 | |
659 /* Use GetOutput().AnswerChange() */ | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
660 void IndexBackend::GetLastChange(IDatabaseBackendOutput& output, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
661 DatabaseManager& manager) |
0 | 662 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
663 std::string suffix; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
664 if (manager.GetDialect() == Dialect_MSSQL) |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
665 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
666 suffix = "OFFSET 0 ROWS FETCH FIRST 1 ROWS ONLY"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
667 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
668 else |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
669 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
670 suffix = "LIMIT 1"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
671 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
672 |
0 | 673 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
674 STATEMENT_FROM_HERE, manager, |
326
4454545bb265
Fix issue 200 (fields messed up in /changes route)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
675 "SELECT Changes.seq, Changes.changeType, Changes.resourceType, Resources.publicId, " |
4454545bb265
Fix issue 200 (fields messed up in /changes route)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
314
diff
changeset
|
676 "Changes.date FROM Changes INNER JOIN Resources " |
310
f3eac614b32e
fixed two DatabaseManager::CachedStatement in the same scope
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
677 "ON Changes.internalId = Resources.internalId ORDER BY seq DESC " + suffix); |
0 | 678 |
679 statement.SetReadOnly(true); | |
680 | |
681 Dictionary args; | |
682 | |
683 bool done; // Ignored | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
684 ReadChangesInternal(output, done, manager, statement, args, 1); |
0 | 685 } |
686 | |
687 | |
688 /* Use GetOutput().AnswerExportedResource() */ | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
689 void IndexBackend::GetLastExportedResource(IDatabaseBackendOutput& output, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
690 DatabaseManager& manager) |
0 | 691 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
692 std::string suffix; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
693 if (manager.GetDialect() == Dialect_MSSQL) |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
694 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
695 suffix = "OFFSET 0 ROWS FETCH FIRST 1 ROWS ONLY"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
696 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
697 else |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
698 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
699 suffix = "LIMIT 1"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
700 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
701 |
0 | 702 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
703 STATEMENT_FROM_HERE, manager, |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
704 "SELECT * FROM ExportedResources ORDER BY seq DESC " + suffix); |
0 | 705 |
706 statement.SetReadOnly(true); | |
707 | |
708 Dictionary args; | |
709 | |
710 bool done; // Ignored | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
711 ReadExportedResourcesInternal(output, done, statement, args, 1); |
0 | 712 } |
713 | |
714 | |
715 /* Use GetOutput().AnswerDicomTag() */ | |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
716 void IndexBackend::GetMainDicomTags(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
717 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
718 int64_t id) |
0 | 719 { |
720 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
721 STATEMENT_FROM_HERE, manager, |
0 | 722 "SELECT * FROM MainDicomTags WHERE id=${id}"); |
723 | |
724 statement.SetReadOnly(true); | |
725 statement.SetParameterType("id", ValueType_Integer64); | |
726 | |
727 Dictionary args; | |
728 args.SetIntegerValue("id", id); | |
729 | |
730 statement.Execute(args); | |
731 | |
732 while (!statement.IsDone()) | |
733 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
734 output.AnswerDicomTag(static_cast<uint16_t>(statement.ReadInteger64(1)), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
735 static_cast<uint16_t>(statement.ReadInteger64(2)), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
736 statement.ReadString(3)); |
0 | 737 statement.Next(); |
738 } | |
739 } | |
740 | |
741 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
742 std::string IndexBackend::GetPublicId(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
743 int64_t resourceId) |
0 | 744 { |
745 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
746 STATEMENT_FROM_HERE, manager, |
0 | 747 "SELECT publicId FROM Resources WHERE internalId=${id}"); |
748 | |
749 statement.SetReadOnly(true); | |
750 statement.SetParameterType("id", ValueType_Integer64); | |
751 | |
752 Dictionary args; | |
753 args.SetIntegerValue("id", resourceId); | |
754 | |
755 statement.Execute(args); | |
756 | |
757 if (statement.IsDone()) | |
758 { | |
759 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
760 } | |
761 else | |
762 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
763 return statement.ReadString(0); |
0 | 764 } |
765 } | |
766 | |
767 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
768 uint64_t IndexBackend::GetResourcesCount(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
769 OrthancPluginResourceType resourceType) |
0 | 770 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
771 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 772 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
773 switch (manager.GetDialect()) |
0 | 774 { |
775 case Dialect_MySQL: | |
776 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
777 STATEMENT_FROM_HERE, manager, |
0 | 778 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM Resources WHERE resourceType=${type}")); |
779 break; | |
780 | |
781 case Dialect_PostgreSQL: | |
782 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
783 STATEMENT_FROM_HERE, manager, |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
784 "SELECT CAST(COUNT(*) AS BIGINT) FROM Resources WHERE resourceType=${type}")); |
0 | 785 break; |
786 | |
301 | 787 case Dialect_MSSQL: |
0 | 788 case Dialect_SQLite: |
789 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
790 STATEMENT_FROM_HERE, manager, |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
791 "SELECT COUNT(*) FROM Resources WHERE resourceType=${type}")); |
0 | 792 break; |
793 | |
794 default: | |
795 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
796 } | |
797 | |
798 statement->SetReadOnly(true); | |
799 statement->SetParameterType("type", ValueType_Integer64); | |
800 | |
801 Dictionary args; | |
802 args.SetIntegerValue("type", resourceType); | |
803 | |
804 statement->Execute(args); | |
805 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
806 return static_cast<uint64_t>(statement->ReadInteger64(0)); |
0 | 807 } |
808 | |
809 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
810 OrthancPluginResourceType IndexBackend::GetResourceType(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
811 int64_t resourceId) |
0 | 812 { |
813 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
814 STATEMENT_FROM_HERE, manager, |
0 | 815 "SELECT resourceType FROM Resources WHERE internalId=${id}"); |
816 | |
817 statement.SetReadOnly(true); | |
818 statement.SetParameterType("id", ValueType_Integer64); | |
819 | |
820 Dictionary args; | |
821 args.SetIntegerValue("id", resourceId); | |
822 | |
823 statement.Execute(args); | |
824 | |
825 if (statement.IsDone()) | |
826 { | |
827 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); | |
828 } | |
829 else | |
830 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
831 return static_cast<OrthancPluginResourceType>(statement.ReadInteger32(0)); |
0 | 832 } |
833 } | |
834 | |
835 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
836 uint64_t IndexBackend::GetTotalCompressedSize(DatabaseManager& manager) |
0 | 837 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
838 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 839 |
840 // NB: "COALESCE" is used to replace "NULL" by "0" if the number of rows is empty | |
841 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
842 switch (manager.GetDialect()) |
0 | 843 { |
844 case Dialect_MySQL: | |
845 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
846 STATEMENT_FROM_HERE, manager, |
0 | 847 "SELECT CAST(COALESCE(SUM(compressedSize), 0) AS UNSIGNED INTEGER) FROM AttachedFiles")); |
848 break; | |
849 | |
850 case Dialect_PostgreSQL: | |
851 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
852 STATEMENT_FROM_HERE, manager, |
0 | 853 "SELECT CAST(COALESCE(SUM(compressedSize), 0) AS BIGINT) FROM AttachedFiles")); |
854 break; | |
855 | |
301 | 856 case Dialect_MSSQL: |
0 | 857 case Dialect_SQLite: |
858 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
859 STATEMENT_FROM_HERE, manager, |
0 | 860 "SELECT COALESCE(SUM(compressedSize), 0) FROM AttachedFiles")); |
861 break; | |
862 | |
863 default: | |
864 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
865 } | |
866 | |
867 statement->SetReadOnly(true); | |
868 statement->Execute(); | |
869 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
870 return static_cast<uint64_t>(statement->ReadInteger64(0)); |
0 | 871 } |
872 | |
873 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
874 uint64_t IndexBackend::GetTotalUncompressedSize(DatabaseManager& manager) |
0 | 875 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
876 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 877 |
878 // NB: "COALESCE" is used to replace "NULL" by "0" if the number of rows is empty | |
879 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
880 switch (manager.GetDialect()) |
0 | 881 { |
882 case Dialect_MySQL: | |
883 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
884 STATEMENT_FROM_HERE, manager, |
0 | 885 "SELECT CAST(COALESCE(SUM(uncompressedSize), 0) AS UNSIGNED INTEGER) FROM AttachedFiles")); |
886 break; | |
887 | |
888 case Dialect_PostgreSQL: | |
889 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
890 STATEMENT_FROM_HERE, manager, |
0 | 891 "SELECT CAST(COALESCE(SUM(uncompressedSize), 0) AS BIGINT) FROM AttachedFiles")); |
892 break; | |
893 | |
301 | 894 case Dialect_MSSQL: |
0 | 895 case Dialect_SQLite: |
896 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
897 STATEMENT_FROM_HERE, manager, |
0 | 898 "SELECT COALESCE(SUM(uncompressedSize), 0) FROM AttachedFiles")); |
899 break; | |
900 | |
901 default: | |
902 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
903 } | |
904 | |
905 statement->SetReadOnly(true); | |
906 statement->Execute(); | |
907 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
908 return static_cast<uint64_t>(statement->ReadInteger64(0)); |
0 | 909 } |
910 | |
911 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
912 bool IndexBackend::IsExistingResource(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
913 int64_t internalId) |
0 | 914 { |
915 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
916 STATEMENT_FROM_HERE, manager, |
0 | 917 "SELECT * FROM Resources WHERE internalId=${id}"); |
918 | |
919 statement.SetReadOnly(true); | |
920 statement.SetParameterType("id", ValueType_Integer64); | |
921 | |
922 Dictionary args; | |
923 args.SetIntegerValue("id", internalId); | |
924 | |
925 statement.Execute(args); | |
926 | |
927 return !statement.IsDone(); | |
928 } | |
929 | |
930 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
931 bool IndexBackend::IsProtectedPatient(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
932 int64_t internalId) |
0 | 933 { |
934 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
935 STATEMENT_FROM_HERE, manager, |
0 | 936 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ${id}"); |
937 | |
938 statement.SetReadOnly(true); | |
939 statement.SetParameterType("id", ValueType_Integer64); | |
940 | |
941 Dictionary args; | |
942 args.SetIntegerValue("id", internalId); | |
943 | |
944 statement.Execute(args); | |
945 | |
946 return statement.IsDone(); | |
947 } | |
948 | |
949 | |
950 void IndexBackend::ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
951 DatabaseManager& manager, |
0 | 952 int64_t id) |
953 { | |
954 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
955 STATEMENT_FROM_HERE, manager, |
0 | 956 "SELECT type FROM Metadata WHERE id=${id}"); |
957 | |
958 statement.SetReadOnly(true); | |
959 statement.SetParameterType("id", ValueType_Integer64); | |
960 | |
961 Dictionary args; | |
962 args.SetIntegerValue("id", id); | |
963 | |
964 ReadListOfIntegers<int32_t>(target, statement, args); | |
965 } | |
966 | |
967 | |
968 void IndexBackend::ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
969 DatabaseManager& manager, |
0 | 970 int64_t id) |
971 { | |
972 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
973 STATEMENT_FROM_HERE, manager, |
0 | 974 "SELECT fileType FROM AttachedFiles WHERE id=${id}"); |
975 | |
976 statement.SetReadOnly(true); | |
977 statement.SetParameterType("id", ValueType_Integer64); | |
978 | |
979 Dictionary args; | |
980 args.SetIntegerValue("id", id); | |
981 | |
982 ReadListOfIntegers<int32_t>(target, statement, args); | |
983 } | |
984 | |
985 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
986 void IndexBackend::LogChange(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
987 int32_t changeType, |
209 | 988 int64_t resourceId, |
989 OrthancPluginResourceType resourceType, | |
990 const char* date) | |
0 | 991 { |
992 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
993 STATEMENT_FROM_HERE, manager, |
302
3a52e27a2d80
in GenericFormatter, replaced ${} by ${AUTOINCREMENT}
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
301
diff
changeset
|
994 "INSERT INTO Changes VALUES(${AUTOINCREMENT} ${changeType}, ${id}, ${resourceType}, ${date})"); |
0 | 995 |
996 statement.SetParameterType("changeType", ValueType_Integer64); | |
997 statement.SetParameterType("id", ValueType_Integer64); | |
998 statement.SetParameterType("resourceType", ValueType_Integer64); | |
999 statement.SetParameterType("date", ValueType_Utf8String); | |
1000 | |
1001 Dictionary args; | |
209 | 1002 args.SetIntegerValue("changeType", changeType); |
1003 args.SetIntegerValue("id", resourceId); | |
1004 args.SetIntegerValue("resourceType", resourceType); | |
1005 args.SetUtf8Value("date", date); | |
0 | 1006 |
1007 statement.Execute(args); | |
1008 } | |
1009 | |
1010 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1011 void IndexBackend::LogExportedResource(DatabaseManager& manager, |
378
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1012 OrthancPluginResourceType resourceType, |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1013 const char* publicId, |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1014 const char* modality, |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1015 const char* date, |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1016 const char* patientId, |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1017 const char* studyInstanceUid, |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1018 const char* seriesInstanceUid, |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1019 const char* sopInstanceUid) |
0 | 1020 { |
1021 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1022 STATEMENT_FROM_HERE, manager, |
302
3a52e27a2d80
in GenericFormatter, replaced ${} by ${AUTOINCREMENT}
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
301
diff
changeset
|
1023 "INSERT INTO ExportedResources VALUES(${AUTOINCREMENT} ${type}, ${publicId}, " |
0 | 1024 "${modality}, ${patient}, ${study}, ${series}, ${instance}, ${date})"); |
1025 | |
1026 statement.SetParameterType("type", ValueType_Integer64); | |
1027 statement.SetParameterType("publicId", ValueType_Utf8String); | |
1028 statement.SetParameterType("modality", ValueType_Utf8String); | |
1029 statement.SetParameterType("patient", ValueType_Utf8String); | |
1030 statement.SetParameterType("study", ValueType_Utf8String); | |
1031 statement.SetParameterType("series", ValueType_Utf8String); | |
1032 statement.SetParameterType("instance", ValueType_Utf8String); | |
1033 statement.SetParameterType("date", ValueType_Utf8String); | |
1034 | |
1035 Dictionary args; | |
378
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1036 args.SetIntegerValue("type", resourceType); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1037 args.SetUtf8Value("publicId", publicId); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1038 args.SetUtf8Value("modality", modality); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1039 args.SetUtf8Value("patient", patientId); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1040 args.SetUtf8Value("study", studyInstanceUid); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1041 args.SetUtf8Value("series", seriesInstanceUid); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1042 args.SetUtf8Value("instance", sopInstanceUid); |
9db9e0275ec0
refactoring IndexBackend::LogExportedResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
373
diff
changeset
|
1043 args.SetUtf8Value("date", date); |
0 | 1044 |
1045 statement.Execute(args); | |
1046 } | |
1047 | |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1048 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1049 static bool ExecuteLookupAttachment(DatabaseManager::CachedStatement& statement, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1050 IDatabaseBackendOutput& output, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1051 int64_t id, |
0 | 1052 int32_t contentType) |
1053 { | |
1054 statement.SetReadOnly(true); | |
1055 statement.SetParameterType("id", ValueType_Integer64); | |
1056 statement.SetParameterType("type", ValueType_Integer64); | |
1057 | |
1058 Dictionary args; | |
1059 args.SetIntegerValue("id", id); | |
1060 args.SetIntegerValue("type", static_cast<int>(contentType)); | |
1061 | |
1062 statement.Execute(args); | |
1063 | |
1064 if (statement.IsDone()) | |
1065 { | |
1066 return false; | |
1067 } | |
1068 else | |
1069 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1070 output.AnswerAttachment(statement.ReadString(0), |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
1071 contentType, |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1072 statement.ReadInteger64(1), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1073 statement.ReadString(4), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1074 statement.ReadInteger32(2), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1075 statement.ReadInteger64(3), |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1076 statement.ReadString(5)); |
0 | 1077 return true; |
1078 } | |
1079 } | |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1080 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1081 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1082 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1083 /* Use GetOutput().AnswerAttachment() */ |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1084 bool IndexBackend::LookupAttachment(IDatabaseBackendOutput& output, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1085 int64_t& revision /*out*/, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1086 DatabaseManager& manager, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1087 int64_t id, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1088 int32_t contentType) |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1089 { |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1090 if (HasRevisionsSupport()) |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1091 { |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1092 DatabaseManager::CachedStatement statement( |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1093 STATEMENT_FROM_HERE, manager, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1094 "SELECT uuid, uncompressedSize, compressionType, compressedSize, uncompressedHash, " |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1095 "compressedHash, revision FROM AttachedFiles WHERE id=${id} AND fileType=${type}"); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1096 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1097 if (ExecuteLookupAttachment(statement, output, id, contentType)) |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1098 { |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1099 if (statement.GetResultField(6).GetType() == ValueType_Null) |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1100 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1101 // "NULL" can happen with a database created by PostgreSQL |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1102 // plugin <= 3.3 (because of "ALTER TABLE AttachedFiles") |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1103 revision = 0; |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1104 } |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1105 else |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1106 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1107 revision = statement.ReadInteger64(6); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1108 } |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1109 |
262
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1110 return true; |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1111 } |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1112 else |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1113 { |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1114 return false; |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1115 } |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1116 } |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1117 else |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1118 { |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1119 DatabaseManager::CachedStatement statement( |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1120 STATEMENT_FROM_HERE, manager, |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1121 "SELECT uuid, uncompressedSize, compressionType, compressedSize, uncompressedHash, " |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1122 "compressedHash FROM AttachedFiles WHERE id=${id} AND fileType=${type}"); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1123 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1124 revision = 0; |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1125 |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1126 return ExecuteLookupAttachment(statement, output, id, contentType); |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1127 } |
b0c65094b299
adding support for revisions in attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
261
diff
changeset
|
1128 } |
0 | 1129 |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1130 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1131 static bool ReadGlobalProperty(std::string& target, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1132 DatabaseManager::CachedStatement& statement, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1133 const Dictionary& args) |
0 | 1134 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1135 statement.Execute(args); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1136 statement.SetResultFieldType(0, ValueType_Utf8String); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1137 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1138 if (statement.IsDone()) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1139 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1140 return false; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1141 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1142 else |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1143 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1144 ValueType type = statement.GetResultField(0).GetType(); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1145 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1146 if (type == ValueType_Null) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1147 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1148 return false; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1149 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1150 else if (type != ValueType_Utf8String) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1151 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1152 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1153 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1154 else |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1155 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1156 target = dynamic_cast<const Utf8StringValue&>(statement.GetResultField(0)).GetContent(); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1157 return true; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1158 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1159 } |
0 | 1160 } |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1161 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1162 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1163 bool IndexBackend::LookupGlobalProperty(std::string& target /*out*/, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1164 DatabaseManager& manager, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1165 const char* serverIdentifier, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1166 int32_t property) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1167 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1168 if (serverIdentifier == NULL) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1169 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1170 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1171 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1172 else |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1173 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1174 if (strlen(serverIdentifier) == 0) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1175 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1176 DatabaseManager::CachedStatement statement( |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1177 STATEMENT_FROM_HERE, manager, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1178 "SELECT value FROM GlobalProperties WHERE property=${property}"); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1179 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1180 statement.SetReadOnly(true); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1181 statement.SetParameterType("property", ValueType_Integer64); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1182 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1183 Dictionary args; |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1184 args.SetIntegerValue("property", property); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1185 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1186 return ReadGlobalProperty(target, statement, args); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1187 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1188 else |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1189 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1190 DatabaseManager::CachedStatement statement( |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1191 STATEMENT_FROM_HERE, manager, |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1192 "SELECT value FROM ServerProperties WHERE server=${server} AND property=${property}"); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1193 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1194 statement.SetReadOnly(true); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1195 statement.SetParameterType("server", ValueType_Utf8String); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1196 statement.SetParameterType("property", ValueType_Integer64); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1197 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1198 Dictionary args; |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1199 args.SetUtf8Value("server", serverIdentifier); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1200 args.SetIntegerValue("property", property); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1201 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1202 return ReadGlobalProperty(target, statement, args); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1203 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1204 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1205 } |
0 | 1206 |
431 | 1207 bool IndexBackend::HasAtomicIncrementGlobalProperty() |
1208 { | |
1209 return false; // currently only implemented in Postgres | |
1210 } | |
1211 | |
1212 int64_t IndexBackend::IncrementGlobalProperty(DatabaseManager& manager, | |
1213 const char* serverIdentifier, | |
1214 int32_t property, | |
1215 int64_t increment) | |
1216 { | |
1217 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1218 } | |
0 | 1219 |
1220 void IndexBackend::LookupIdentifier(std::list<int64_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1221 DatabaseManager& manager, |
0 | 1222 OrthancPluginResourceType resourceType, |
1223 uint16_t group, | |
1224 uint16_t element, | |
1225 OrthancPluginIdentifierConstraint constraint, | |
1226 const char* value) | |
1227 { | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1228 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1229 |
1230 std::string header = | |
1231 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " | |
1232 "d.id = r.internalId AND r.resourceType=${type} AND d.tagGroup=${group} " | |
1233 "AND d.tagElement=${element} AND "; | |
1234 | |
1235 switch (constraint) | |
1236 { | |
1237 case OrthancPluginIdentifierConstraint_Equal: | |
1238 header += "d.value = ${value}"; | |
1239 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1240 STATEMENT_FROM_HERE, manager, header.c_str())); |
0 | 1241 break; |
1242 | |
1243 case OrthancPluginIdentifierConstraint_SmallerOrEqual: | |
1244 header += "d.value <= ${value}"; | |
1245 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1246 STATEMENT_FROM_HERE, manager, header.c_str())); |
0 | 1247 break; |
1248 | |
1249 case OrthancPluginIdentifierConstraint_GreaterOrEqual: | |
1250 header += "d.value >= ${value}"; | |
1251 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1252 STATEMENT_FROM_HERE, manager, header.c_str())); |
0 | 1253 break; |
1254 | |
1255 case OrthancPluginIdentifierConstraint_Wildcard: | |
1256 header += "d.value LIKE ${value}"; | |
1257 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1258 STATEMENT_FROM_HERE, manager, header.c_str())); |
0 | 1259 break; |
1260 | |
1261 default: | |
1262 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
1263 } | |
1264 | |
1265 statement->SetReadOnly(true); | |
1266 statement->SetParameterType("type", ValueType_Integer64); | |
1267 statement->SetParameterType("group", ValueType_Integer64); | |
1268 statement->SetParameterType("element", ValueType_Integer64); | |
1269 statement->SetParameterType("value", ValueType_Utf8String); | |
1270 | |
1271 Dictionary args; | |
1272 args.SetIntegerValue("type", resourceType); | |
1273 args.SetIntegerValue("group", group); | |
1274 args.SetIntegerValue("element", element); | |
1275 | |
1276 if (constraint == OrthancPluginIdentifierConstraint_Wildcard) | |
1277 { | |
1278 args.SetUtf8Value("value", ConvertWildcardToLike(value)); | |
1279 } | |
1280 else | |
1281 { | |
1282 args.SetUtf8Value("value", value); | |
1283 } | |
1284 | |
1285 statement->Execute(args); | |
1286 | |
1287 target.clear(); | |
1288 while (!statement->IsDone()) | |
1289 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1290 target.push_back(statement->ReadInteger64(0)); |
0 | 1291 statement->Next(); |
1292 } | |
1293 } | |
1294 | |
1295 | |
1296 void IndexBackend::LookupIdentifierRange(std::list<int64_t>& target /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1297 DatabaseManager& manager, |
0 | 1298 OrthancPluginResourceType resourceType, |
1299 uint16_t group, | |
1300 uint16_t element, | |
1301 const char* start, | |
1302 const char* end) | |
1303 { | |
1304 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1305 STATEMENT_FROM_HERE, manager, |
0 | 1306 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " |
1307 "d.id = r.internalId AND r.resourceType=${type} AND d.tagGroup=${group} " | |
1308 "AND d.tagElement=${element} AND d.value>=${start} AND d.value<=${end}"); | |
1309 | |
1310 statement.SetReadOnly(true); | |
1311 statement.SetParameterType("type", ValueType_Integer64); | |
1312 statement.SetParameterType("group", ValueType_Integer64); | |
1313 statement.SetParameterType("element", ValueType_Integer64); | |
1314 statement.SetParameterType("start", ValueType_Utf8String); | |
1315 statement.SetParameterType("end", ValueType_Utf8String); | |
1316 | |
1317 Dictionary args; | |
1318 args.SetIntegerValue("type", resourceType); | |
1319 args.SetIntegerValue("group", group); | |
1320 args.SetIntegerValue("element", element); | |
1321 args.SetUtf8Value("start", start); | |
1322 args.SetUtf8Value("end", end); | |
1323 | |
1324 statement.Execute(args); | |
1325 | |
1326 target.clear(); | |
1327 while (!statement.IsDone()) | |
1328 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1329 target.push_back(statement.ReadInteger64(0)); |
0 | 1330 statement.Next(); |
1331 } | |
1332 } | |
1333 | |
1334 | |
1335 bool IndexBackend::LookupMetadata(std::string& target /*out*/, | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1336 int64_t& revision /*out*/, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1337 DatabaseManager& manager, |
0 | 1338 int64_t id, |
1339 int32_t metadataType) | |
1340 { | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1341 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1342 |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1343 if (HasRevisionsSupport()) |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1344 { |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1345 statement.reset(new DatabaseManager::CachedStatement( |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1346 STATEMENT_FROM_HERE, manager, |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1347 "SELECT value, revision FROM Metadata WHERE id=${id} and type=${type}")); |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1348 } |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1349 else |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1350 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1351 statement.reset(new DatabaseManager::CachedStatement( |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1352 STATEMENT_FROM_HERE, manager, |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1353 "SELECT value FROM Metadata WHERE id=${id} and type=${type}")); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1354 } |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1355 |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1356 statement->SetReadOnly(true); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1357 statement->SetParameterType("id", ValueType_Integer64); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1358 statement->SetParameterType("type", ValueType_Integer64); |
0 | 1359 |
1360 Dictionary args; | |
1361 args.SetIntegerValue("id", id); | |
1362 args.SetIntegerValue("type", metadataType); | |
1363 | |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1364 statement->Execute(args); |
0 | 1365 |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1366 if (statement->IsDone()) |
0 | 1367 { |
1368 return false; | |
1369 } | |
1370 else | |
1371 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1372 target = statement->ReadString(0); |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1373 |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1374 if (HasRevisionsSupport()) |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1375 { |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1376 if (statement->GetResultField(1).GetType() == ValueType_Null) |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1377 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1378 // "NULL" can happen with a database created by PostgreSQL |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1379 // plugin <= 3.3 (because of "ALTER TABLE AttachedFiles") |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1380 revision = 0; |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1381 } |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1382 else |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1383 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1384 revision = statement->ReadInteger64(1); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1385 } |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1386 } |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1387 else |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1388 { |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1389 revision = 0; // No support for revisions |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1390 } |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1391 |
0 | 1392 return true; |
1393 } | |
1394 } | |
1395 | |
1396 | |
1397 bool IndexBackend::LookupParent(int64_t& parentId /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1398 DatabaseManager& manager, |
0 | 1399 int64_t resourceId) |
1400 { | |
1401 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1402 STATEMENT_FROM_HERE, manager, |
0 | 1403 "SELECT parentId FROM Resources WHERE internalId=${id}"); |
1404 | |
1405 statement.SetReadOnly(true); | |
1406 statement.SetParameterType("id", ValueType_Integer64); | |
1407 | |
1408 Dictionary args; | |
1409 args.SetIntegerValue("id", resourceId); | |
1410 | |
1411 statement.Execute(args); | |
1412 | |
1413 if (statement.IsDone() || | |
1414 statement.GetResultField(0).GetType() == ValueType_Null) | |
1415 { | |
1416 return false; | |
1417 } | |
1418 else | |
1419 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1420 parentId = statement.ReadInteger64(0); |
0 | 1421 return true; |
1422 } | |
1423 } | |
1424 | |
1425 | |
1426 bool IndexBackend::LookupResource(int64_t& id /*out*/, | |
1427 OrthancPluginResourceType& type /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1428 DatabaseManager& manager, |
0 | 1429 const char* publicId) |
1430 { | |
1431 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1432 STATEMENT_FROM_HERE, manager, |
0 | 1433 "SELECT internalId, resourceType FROM Resources WHERE publicId=${id}"); |
1434 | |
1435 statement.SetReadOnly(true); | |
1436 statement.SetParameterType("id", ValueType_Utf8String); | |
1437 | |
1438 Dictionary args; | |
1439 args.SetUtf8Value("id", publicId); | |
1440 | |
1441 statement.Execute(args); | |
1442 | |
1443 if (statement.IsDone()) | |
1444 { | |
1445 return false; | |
1446 } | |
1447 else | |
1448 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1449 id = statement.ReadInteger64(0); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1450 type = static_cast<OrthancPluginResourceType>(statement.ReadInteger32(1)); |
0 | 1451 return true; |
1452 } | |
1453 } | |
1454 | |
1455 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1456 bool IndexBackend::SelectPatientToRecycle(int64_t& internalId /*out*/, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1457 DatabaseManager& manager) |
0 | 1458 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1459 std::string suffix; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1460 if (manager.GetDialect() == Dialect_MSSQL) |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1461 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1462 suffix = "OFFSET 0 ROWS FETCH FIRST 1 ROWS ONLY"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1463 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1464 else |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1465 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1466 suffix = "LIMIT 1"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1467 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1468 |
0 | 1469 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1470 STATEMENT_FROM_HERE, manager, |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1471 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC " + suffix); |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1472 |
0 | 1473 statement.SetReadOnly(true); |
1474 statement.Execute(); | |
1475 | |
1476 if (statement.IsDone()) | |
1477 { | |
1478 return false; | |
1479 } | |
1480 else | |
1481 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1482 internalId = statement.ReadInteger64(0); |
0 | 1483 return true; |
1484 } | |
1485 } | |
1486 | |
1487 | |
1488 bool IndexBackend::SelectPatientToRecycle(int64_t& internalId /*out*/, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1489 DatabaseManager& manager, |
0 | 1490 int64_t patientIdToAvoid) |
1491 { | |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1492 std::string suffix; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1493 if (manager.GetDialect() == Dialect_MSSQL) |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1494 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1495 suffix = "OFFSET 0 ROWS FETCH FIRST 1 ROWS ONLY"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1496 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1497 else |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1498 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1499 suffix = "LIMIT 1"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1500 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1501 |
0 | 1502 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1503 STATEMENT_FROM_HERE, manager, |
0 | 1504 "SELECT patientId FROM PatientRecyclingOrder " |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
1505 "WHERE patientId != ${id} ORDER BY seq ASC " + suffix); |
0 | 1506 |
1507 statement.SetReadOnly(true); | |
1508 statement.SetParameterType("id", ValueType_Integer64); | |
1509 | |
1510 Dictionary args; | |
1511 args.SetIntegerValue("id", patientIdToAvoid); | |
1512 | |
1513 statement.Execute(args); | |
1514 | |
1515 if (statement.IsDone()) | |
1516 { | |
1517 return false; | |
1518 } | |
1519 else | |
1520 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1521 internalId = statement.ReadInteger64(0); |
0 | 1522 return true; |
1523 } | |
1524 } | |
1525 | |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1526 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1527 static void RunSetGlobalPropertyStatement(DatabaseManager::CachedStatement& statement, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1528 bool hasServer, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1529 bool hasValue, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1530 const char* serverIdentifier, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1531 int32_t property, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1532 const char* utf8) |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1533 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1534 Dictionary args; |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1535 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1536 statement.SetParameterType("property", ValueType_Integer64); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1537 args.SetIntegerValue("property", static_cast<int>(property)); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1538 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1539 if (hasValue) |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1540 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1541 assert(utf8 != NULL); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1542 statement.SetParameterType("value", ValueType_Utf8String); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1543 args.SetUtf8Value("value", utf8); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1544 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1545 else |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1546 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1547 assert(utf8 == NULL); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1548 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1549 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1550 if (hasServer) |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1551 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1552 assert(serverIdentifier != NULL && strlen(serverIdentifier) > 0); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1553 statement.SetParameterType("server", ValueType_Utf8String); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1554 args.SetUtf8Value("server", serverIdentifier); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1555 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1556 else |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1557 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1558 assert(serverIdentifier == NULL); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1559 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1560 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1561 statement.Execute(args); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1562 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1563 |
0 | 1564 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1565 void IndexBackend::SetGlobalProperty(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1566 const char* serverIdentifier, |
221
73cc85f3d9c1
implementation of the "serverIdentifier" information for global properties
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
220
diff
changeset
|
1567 int32_t property, |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1568 const char* utf8) |
0 | 1569 { |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1570 if (serverIdentifier == NULL) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1571 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1572 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1573 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1574 else if (manager.GetDialect() == Dialect_SQLite) |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1575 { |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1576 bool hasServer = (strlen(serverIdentifier) != 0); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1577 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1578 if (hasServer) |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1579 { |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1580 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1581 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1582 "INSERT OR REPLACE INTO ServerProperties VALUES (${server}, ${property}, ${value})"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1583 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1584 RunSetGlobalPropertyStatement(statement, true, true, serverIdentifier, property, utf8); |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1585 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1586 else |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1587 { |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1588 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1589 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1590 "INSERT OR REPLACE INTO GlobalProperties VALUES (${property}, ${value})"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1591 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1592 RunSetGlobalPropertyStatement(statement, false, true, NULL, property, utf8); |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1593 } |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1594 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1595 else |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1596 { |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1597 bool hasServer = (strlen(serverIdentifier) != 0); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1598 |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1599 if (hasServer) |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1600 { |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1601 { |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1602 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1603 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1604 "DELETE FROM ServerProperties WHERE server=${server} AND property=${property}"); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1605 |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1606 RunSetGlobalPropertyStatement(statement, true, false, serverIdentifier, property, NULL); |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1607 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
1608 |
239
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1609 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1610 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1611 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1612 "INSERT INTO ServerProperties VALUES (${server}, ${property}, ${value})"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1613 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1614 RunSetGlobalPropertyStatement(statement, true, true, serverIdentifier, property, utf8); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1615 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1616 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1617 else |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1618 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1619 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1620 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1621 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1622 "DELETE FROM GlobalProperties WHERE property=${property}"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1623 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1624 RunSetGlobalPropertyStatement(statement, false, false, NULL, property, NULL); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1625 } |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1626 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1627 { |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1628 DatabaseManager::CachedStatement statement( |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1629 STATEMENT_FROM_HERE, manager, |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1630 "INSERT INTO GlobalProperties VALUES (${property}, ${value})"); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1631 |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1632 RunSetGlobalPropertyStatement(statement, false, true, NULL, property, utf8); |
e9ba888f371b
fix IndexBackend::SetGlobalProperty(), lighten GlobalProperty enum
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
1633 } |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1634 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
1635 } |
0 | 1636 } |
1637 | |
1638 | |
1639 static void ExecuteSetTag(DatabaseManager::CachedStatement& statement, | |
1640 int64_t id, | |
1641 uint16_t group, | |
1642 uint16_t element, | |
1643 const char* value) | |
1644 { | |
1645 statement.SetParameterType("id", ValueType_Integer64); | |
1646 statement.SetParameterType("group", ValueType_Integer64); | |
1647 statement.SetParameterType("element", ValueType_Integer64); | |
1648 statement.SetParameterType("value", ValueType_Utf8String); | |
1649 | |
1650 Dictionary args; | |
1651 args.SetIntegerValue("id", id); | |
1652 args.SetIntegerValue("group", group); | |
1653 args.SetIntegerValue("element", element); | |
1654 args.SetUtf8Value("value", value); | |
1655 | |
1656 statement.Execute(args); | |
1657 } | |
1658 | |
1659 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1660 void IndexBackend::SetMainDicomTag(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1661 int64_t id, |
0 | 1662 uint16_t group, |
1663 uint16_t element, | |
1664 const char* value) | |
1665 { | |
1666 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1667 STATEMENT_FROM_HERE, manager, |
0 | 1668 "INSERT INTO MainDicomTags VALUES(${id}, ${group}, ${element}, ${value})"); |
1669 | |
1670 ExecuteSetTag(statement, id, group, element, value); | |
1671 } | |
1672 | |
1673 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1674 void IndexBackend::SetIdentifierTag(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1675 int64_t id, |
0 | 1676 uint16_t group, |
1677 uint16_t element, | |
1678 const char* value) | |
1679 { | |
1680 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1681 STATEMENT_FROM_HERE, manager, |
0 | 1682 "INSERT INTO DicomIdentifiers VALUES(${id}, ${group}, ${element}, ${value})"); |
1683 | |
1684 ExecuteSetTag(statement, id, group, element, value); | |
1685 } | |
1686 | |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1687 |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1688 static void ExecuteSetMetadata(DatabaseManager::CachedStatement& statement, |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1689 Dictionary& args, |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1690 int64_t id, |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1691 int32_t metadataType, |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1692 const char* value) |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1693 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1694 statement.SetParameterType("id", ValueType_Integer64); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1695 statement.SetParameterType("type", ValueType_Integer64); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1696 statement.SetParameterType("value", ValueType_Utf8String); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1697 |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1698 args.SetIntegerValue("id", id); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1699 args.SetIntegerValue("type", metadataType); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1700 args.SetUtf8Value("value", value); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1701 |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1702 statement.Execute(args); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1703 } |
0 | 1704 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1705 void IndexBackend::SetMetadata(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1706 int64_t id, |
0 | 1707 int32_t metadataType, |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1708 const char* value, |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1709 int64_t revision) |
0 | 1710 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1711 if (manager.GetDialect() == Dialect_SQLite) |
0 | 1712 { |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1713 assert(HasRevisionsSupport()); |
0 | 1714 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1715 STATEMENT_FROM_HERE, manager, |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1716 "INSERT OR REPLACE INTO Metadata VALUES (${id}, ${type}, ${value}, ${revision})"); |
0 | 1717 |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1718 Dictionary args; |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1719 statement.SetParameterType("revision", ValueType_Integer64); |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
1720 args.SetIntegerValue("revision", revision); |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1721 |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1722 ExecuteSetMetadata(statement, args, id, metadataType, value); |
0 | 1723 } |
1724 else | |
1725 { | |
1726 { | |
1727 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1728 STATEMENT_FROM_HERE, manager, |
0 | 1729 "DELETE FROM Metadata WHERE id=${id} AND type=${type}"); |
1730 | |
1731 statement.SetParameterType("id", ValueType_Integer64); | |
1732 statement.SetParameterType("type", ValueType_Integer64); | |
1733 | |
1734 Dictionary args; | |
1735 args.SetIntegerValue("id", id); | |
1736 args.SetIntegerValue("type", metadataType); | |
1737 | |
1738 statement.Execute(args); | |
1739 } | |
1740 | |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1741 if (HasRevisionsSupport()) |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1742 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1743 DatabaseManager::CachedStatement statement( |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1744 STATEMENT_FROM_HERE, manager, |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1745 "INSERT INTO Metadata VALUES (${id}, ${type}, ${value}, ${revision})"); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1746 |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1747 Dictionary args; |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1748 statement.SetParameterType("revision", ValueType_Integer64); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1749 args.SetIntegerValue("revision", revision); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1750 |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1751 ExecuteSetMetadata(statement, args, id, metadataType, value); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1752 } |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1753 else |
0 | 1754 { |
1755 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1756 STATEMENT_FROM_HERE, manager, |
0 | 1757 "INSERT INTO Metadata VALUES (${id}, ${type}, ${value})"); |
1758 | |
1759 Dictionary args; | |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
1760 ExecuteSetMetadata(statement, args, id, metadataType, value); |
0 | 1761 } |
1762 } | |
1763 } | |
1764 | |
1765 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1766 void IndexBackend::SetProtectedPatient(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1767 int64_t internalId, |
0 | 1768 bool isProtected) |
1769 { | |
1770 if (isProtected) | |
1771 { | |
1772 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1773 STATEMENT_FROM_HERE, manager, |
0 | 1774 "DELETE FROM PatientRecyclingOrder WHERE patientId=${id}"); |
1775 | |
1776 statement.SetParameterType("id", ValueType_Integer64); | |
1777 | |
1778 Dictionary args; | |
1779 args.SetIntegerValue("id", internalId); | |
1780 | |
1781 statement.Execute(args); | |
1782 } | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1783 else if (IsProtectedPatient(manager, internalId)) |
0 | 1784 { |
1785 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1786 STATEMENT_FROM_HERE, manager, |
302
3a52e27a2d80
in GenericFormatter, replaced ${} by ${AUTOINCREMENT}
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
301
diff
changeset
|
1787 "INSERT INTO PatientRecyclingOrder VALUES(${AUTOINCREMENT} ${id})"); |
0 | 1788 |
1789 statement.SetParameterType("id", ValueType_Integer64); | |
1790 | |
1791 Dictionary args; | |
1792 args.SetIntegerValue("id", internalId); | |
1793 | |
1794 statement.Execute(args); | |
1795 } | |
1796 else | |
1797 { | |
1798 // Nothing to do: The patient is already unprotected | |
1799 } | |
1800 } | |
1801 | |
1802 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1803 uint32_t IndexBackend::GetDatabaseVersion(DatabaseManager& manager) |
0 | 1804 { |
220
492aa3edf572
use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
1805 // Create a read-only, explicit transaction to read the database |
492aa3edf572
use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
1806 // version (this was a read-write, implicit transaction in |
492aa3edf572
use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
1807 // PostgreSQL plugin <= 3.3 and MySQL plugin <= 3.0) |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1808 DatabaseManager::Transaction transaction(manager, TransactionType_ReadOnly); |
220
492aa3edf572
use read-only, explicit transaction in IndexBackend::GetDatabaseVersion()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
219
diff
changeset
|
1809 |
0 | 1810 std::string version = "unknown"; |
1811 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1812 if (LookupGlobalProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion)) |
0 | 1813 { |
1814 try | |
1815 { | |
1816 return boost::lexical_cast<unsigned int>(version); | |
1817 } | |
1818 catch (boost::bad_lexical_cast&) | |
1819 { | |
1820 } | |
1821 } | |
1822 | |
1823 LOG(ERROR) << "The database is corrupted. Drop it manually for Orthanc to recreate it"; | |
1824 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
1825 } | |
1826 | |
1827 | |
1828 /** | |
1829 * Upgrade the database to the specified version of the database | |
1830 * schema. The upgrade script is allowed to make calls to | |
1831 * OrthancPluginReconstructMainDicomTags(). | |
1832 **/ | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1833 void IndexBackend::UpgradeDatabase(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1834 uint32_t targetVersion, |
0 | 1835 OrthancPluginStorageArea* storageArea) |
1836 { | |
1837 LOG(ERROR) << "Upgrading database is not implemented by this plugin"; | |
1838 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1839 } | |
1840 | |
1841 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1842 void IndexBackend::ClearMainDicomTags(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1843 int64_t internalId) |
0 | 1844 { |
1845 { | |
1846 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1847 STATEMENT_FROM_HERE, manager, |
0 | 1848 "DELETE FROM MainDicomTags WHERE id=${id}"); |
1849 | |
1850 statement.SetParameterType("id", ValueType_Integer64); | |
1851 | |
1852 Dictionary args; | |
1853 args.SetIntegerValue("id", internalId); | |
1854 | |
1855 statement.Execute(args); | |
1856 } | |
1857 | |
1858 { | |
1859 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1860 STATEMENT_FROM_HERE, manager, |
0 | 1861 "DELETE FROM DicomIdentifiers WHERE id=${id}"); |
1862 | |
1863 statement.SetParameterType("id", ValueType_Integer64); | |
1864 | |
1865 Dictionary args; | |
1866 args.SetIntegerValue("id", internalId); | |
1867 | |
1868 statement.Execute(args); | |
1869 } | |
1870 } | |
1871 | |
1872 | |
1873 // For unit testing only! | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1874 uint64_t IndexBackend::GetAllResourcesCount(DatabaseManager& manager) |
0 | 1875 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1876 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1877 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1878 switch (manager.GetDialect()) |
0 | 1879 { |
1880 case Dialect_MySQL: | |
1881 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1882 STATEMENT_FROM_HERE, manager, |
0 | 1883 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM Resources")); |
1884 break; | |
1885 | |
1886 case Dialect_PostgreSQL: | |
1887 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1888 STATEMENT_FROM_HERE, manager, |
0 | 1889 "SELECT CAST(COUNT(*) AS BIGINT) FROM Resources")); |
1890 break; | |
1891 | |
1892 case Dialect_SQLite: | |
301 | 1893 case Dialect_MSSQL: |
0 | 1894 statement.reset(new DatabaseManager::CachedStatement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1895 STATEMENT_FROM_HERE, manager, |
0 | 1896 "SELECT COUNT(*) FROM Resources")); |
1897 break; | |
1898 | |
1899 default: | |
1900 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1901 } | |
1902 | |
1903 statement->SetReadOnly(true); | |
1904 statement->Execute(); | |
1905 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1906 return static_cast<uint64_t>(statement->ReadInteger64(0)); |
0 | 1907 } |
1908 | |
1909 | |
1910 // For unit testing only! | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1911 uint64_t IndexBackend::GetUnprotectedPatientsCount(DatabaseManager& manager) |
0 | 1912 { |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
1913 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
0 | 1914 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1915 switch (manager.GetDialect()) |
0 | 1916 { |
1917 case Dialect_MySQL: | |
1918 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1919 STATEMENT_FROM_HERE, manager, |
0 | 1920 "SELECT CAST(COUNT(*) AS UNSIGNED INT) FROM PatientRecyclingOrder")); |
1921 break; | |
1922 | |
1923 case Dialect_PostgreSQL: | |
1924 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1925 STATEMENT_FROM_HERE, manager, |
0 | 1926 "SELECT CAST(COUNT(*) AS BIGINT) FROM PatientRecyclingOrder")); |
1927 break; | |
1928 | |
304
dd4b0edd1661
GenericFormatter::GetDialect()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
1929 case Dialect_MSSQL: |
0 | 1930 case Dialect_SQLite: |
1931 statement.reset(new DatabaseManager::CachedStatement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1932 STATEMENT_FROM_HERE, manager, |
0 | 1933 "SELECT COUNT(*) FROM PatientRecyclingOrder")); |
1934 break; | |
1935 | |
1936 default: | |
1937 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
1938 } | |
1939 | |
1940 statement->SetReadOnly(true); | |
1941 statement->Execute(); | |
1942 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1943 return static_cast<uint64_t>(statement->ReadInteger64(0)); |
0 | 1944 } |
1945 | |
1946 | |
1947 // For unit testing only! | |
1948 bool IndexBackend::GetParentPublicId(std::string& target, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1949 DatabaseManager& manager, |
0 | 1950 int64_t id) |
1951 { | |
1952 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1953 STATEMENT_FROM_HERE, manager, |
0 | 1954 "SELECT a.publicId FROM Resources AS a, Resources AS b " |
1955 "WHERE a.internalId = b.parentId AND b.internalId = ${id}"); | |
1956 | |
1957 statement.SetReadOnly(true); | |
1958 statement.SetParameterType("id", ValueType_Integer64); | |
1959 | |
1960 Dictionary args; | |
1961 args.SetIntegerValue("id", id); | |
1962 | |
1963 statement.Execute(args); | |
1964 | |
1965 if (statement.IsDone()) | |
1966 { | |
1967 return false; | |
1968 } | |
1969 else | |
1970 { | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
1971 target = statement.ReadString(0); |
0 | 1972 return true; |
1973 } | |
1974 } | |
1975 | |
1976 | |
1977 // For unit tests only! | |
1978 void IndexBackend::GetChildren(std::list<std::string>& childrenPublicIds, | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1979 DatabaseManager& manager, |
0 | 1980 int64_t id) |
1981 { | |
1982 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
1983 STATEMENT_FROM_HERE, manager, |
0 | 1984 "SELECT publicId FROM Resources WHERE parentId=${id}"); |
1985 | |
1986 statement.SetReadOnly(true); | |
1987 statement.SetParameterType("id", ValueType_Integer64); | |
1988 | |
1989 Dictionary args; | |
1990 args.SetIntegerValue("id", id); | |
1991 | |
1992 ReadListOfStrings(childrenPublicIds, statement, args); | |
1993 } | |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1994 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1995 |
78 | 1996 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1997 class IndexBackend::LookupFormatter : public Orthanc::ISqlLookupFormatter |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1998 { |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
1999 private: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2000 Dialect dialect_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2001 size_t count_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2002 Dictionary dictionary_; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2003 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2004 static std::string FormatParameter(size_t index) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2005 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2006 return "p" + boost::lexical_cast<std::string>(index); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2007 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2008 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2009 public: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2010 LookupFormatter(Dialect dialect) : |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2011 dialect_(dialect), |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2012 count_(0) |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2013 { |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2014 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2015 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2016 virtual std::string GenerateParameter(const std::string& value) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2017 { |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2018 const std::string key = FormatParameter(count_); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2019 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2020 count_ ++; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2021 dictionary_.SetUtf8Value(key, value); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2022 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2023 return "${" + key + "}"; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2024 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2025 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2026 virtual std::string FormatResourceType(Orthanc::ResourceType level) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2027 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2028 return boost::lexical_cast<std::string>(Orthanc::Plugins::Convert(level)); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2029 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2030 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2031 virtual std::string FormatWildcardEscape() |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2032 { |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2033 switch (dialect_) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2034 { |
310
f3eac614b32e
fixed two DatabaseManager::CachedStatement in the same scope
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
307
diff
changeset
|
2035 case Dialect_MSSQL: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2036 case Dialect_SQLite: |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2037 case Dialect_PostgreSQL: |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2038 return "ESCAPE '\\'"; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2039 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2040 case Dialect_MySQL: |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2041 return "ESCAPE '\\\\'"; |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2042 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2043 default: |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2044 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2045 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2046 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2047 |
354
2a3bbb4104fa
fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
326
diff
changeset
|
2048 virtual bool IsEscapeBrackets() const |
2a3bbb4104fa
fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
326
diff
changeset
|
2049 { |
2a3bbb4104fa
fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
326
diff
changeset
|
2050 // This was initially done at a bad location by the following changeset: |
426
d700c8f9fc24
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
415
diff
changeset
|
2051 // https://orthanc.uclouvain.be/hg/orthanc-databases/rev/389c037387ea |
354
2a3bbb4104fa
fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
326
diff
changeset
|
2052 return (dialect_ == Dialect_MSSQL); |
2a3bbb4104fa
fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
326
diff
changeset
|
2053 } |
2a3bbb4104fa
fix changeset 389c037387ea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
326
diff
changeset
|
2054 |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2055 void PrepareStatement(DatabaseManager::StandaloneStatement& statement) const |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2056 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2057 statement.SetReadOnly(true); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2058 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2059 for (size_t i = 0; i < count_; i++) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2060 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2061 statement.SetParameterType(FormatParameter(i), ValueType_Utf8String); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2062 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2063 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2064 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2065 const Dictionary& GetDictionary() const |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2066 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2067 return dictionary_; |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2068 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2069 }; |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2070 #endif |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2071 |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2072 |
78 | 2073 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2074 // New primitive since Orthanc 1.5.2 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2075 void IndexBackend::LookupResources(IDatabaseBackendOutput& output, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2076 DatabaseManager& manager, |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
2077 const std::vector<Orthanc::DatabaseConstraint>& lookup, |
415
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2078 OrthancPluginResourceType queryLevel_, |
401
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
400
diff
changeset
|
2079 const std::set<std::string>& labels, |
a8774581adfc
replaced "WithLabels" and "WithoutLabels", by "Labels" and "LabelsConstraint"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
400
diff
changeset
|
2080 Orthanc::LabelsConstraint labelsConstraint, |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2081 uint32_t limit, |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2082 bool requestSomeInstance) |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2083 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2084 LookupFormatter formatter(manager.GetDialect()); |
415
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2085 Orthanc::ResourceType queryLevel = Orthanc::Plugins::Convert(queryLevel_); |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2086 Orthanc::ResourceType lowerLevel, upperLevel; |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2087 Orthanc::ISqlLookupFormatter::GetLookupLevels(lowerLevel, upperLevel, queryLevel, lookup); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2088 |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2089 std::string sql; |
414
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2090 bool enableNewStudyCode = true; |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2091 |
415
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2092 if (enableNewStudyCode && lowerLevel == queryLevel && upperLevel == queryLevel) |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2093 { |
415
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2094 Orthanc::ISqlLookupFormatter::ApplySingleLevel(sql, formatter, lookup, queryLevel, labels, labelsConstraint, limit); |
414
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2095 |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2096 if (requestSomeInstance) |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2097 { |
414
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2098 // Composite query to find some instance if requested |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2099 switch (queryLevel) |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2100 { |
415
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2101 case Orthanc::ResourceType_Patient: |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2102 sql = ("SELECT patients_studies.patients_public_id, MIN(instances.publicId) AS instances_public_id " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2103 "FROM (SELECT patients.publicId AS patients_public_id, MIN(studies.internalId) AS studies_internal_id " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2104 "FROM (" + sql + |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2105 ") AS patients " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2106 "INNER JOIN Resources studies ON studies.parentId = patients.internalId " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2107 "GROUP BY patients.publicId " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2108 ") AS patients_studies " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2109 "INNER JOIN Resources series ON series.parentId = patients_studies.studies_internal_id " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2110 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2111 "GROUP BY patients_studies.patients_public_id"); |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2112 break; |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2113 case Orthanc::ResourceType_Study: |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2114 sql = ("SELECT studies_series.studies_public_id, MIN(instances.publicId) AS instances_public_id " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2115 "FROM (SELECT studies.publicId AS studies_public_id, MIN(series.internalId) AS series_internal_id " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2116 "FROM (" + sql + |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2117 ") AS studies " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2118 "INNER JOIN Resources series ON series.parentId = studies.internalId " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2119 "GROUP BY studies.publicId " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2120 ") AS studies_series " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2121 "INNER JOIN Resources instances ON instances.parentId = studies_series.series_internal_id " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2122 "GROUP BY studies_series.studies_public_id"); |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2123 break; |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2124 case Orthanc::ResourceType_Series: |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2125 sql = ("SELECT series.publicId AS series_public_id, MIN(instances.publicId) AS instances_public_id " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2126 "FROM (" + sql + |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2127 ") AS series " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2128 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2129 "GROUP BY series.publicId "); |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2130 break; |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2131 |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2132 case Orthanc::ResourceType_Instance: |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2133 sql = ("SELECT instances.publicId, instances.publicId FROM (" + sql + ") instances"); |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2134 break; |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2135 |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2136 default: |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2137 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2138 } |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2139 } |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2140 } |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2141 else |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2142 { |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2143 Orthanc::ISqlLookupFormatter::Apply(sql, formatter, lookup, queryLevel, labels, labelsConstraint, limit); |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2144 |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2145 if (requestSomeInstance) |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2146 { |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2147 // Composite query to find some instance if requested |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2148 switch (queryLevel) |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2149 { |
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2150 case Orthanc::ResourceType_Patient: |
414
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2151 sql = ("SELECT patients.publicId, MIN(instances.publicId) FROM (" + sql + ") patients " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2152 "INNER JOIN Resources studies ON studies.parentId = patients.internalId " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2153 "INNER JOIN Resources series ON series.parentId = studies.internalId " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2154 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2155 "GROUP BY patients.publicId"); |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2156 break; |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2157 |
415
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2158 case Orthanc::ResourceType_Study: |
414
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2159 sql = ("SELECT studies.publicId, MIN(instances.publicId) FROM (" + sql + ") studies " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2160 "INNER JOIN Resources series ON series.parentId = studies.internalId " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2161 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2162 "GROUP BY studies.publicId"); |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2163 break; |
415
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2164 case Orthanc::ResourceType_Series: |
414
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2165 sql = ("SELECT series.publicId, MIN(instances.publicId) FROM (" + sql + ") series " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2166 "INNER JOIN Resources instances ON instances.parentId = series.internalId " |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2167 "GROUP BY series.publicId"); |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2168 break; |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2169 |
415
7e123f047771
LookupResources optimization continued
Alain Mazy <am@osimis.io>
parents:
414
diff
changeset
|
2170 case Orthanc::ResourceType_Instance: |
414
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2171 sql = ("SELECT instances.publicId, instances.publicId FROM (" + sql + ") instances"); |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2172 break; |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2173 |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2174 default: |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2175 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
f2d3b5c5a68d
Optimizing tools/find at studies level only. Integ Tests are ok with PG
Alain Mazy <am@osimis.io>
parents:
410
diff
changeset
|
2176 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2177 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2178 } |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2179 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2180 DatabaseManager::StandaloneStatement statement(manager, sql); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2181 formatter.PrepareStatement(statement); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2182 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2183 statement.Execute(formatter.GetDictionary()); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2184 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2185 while (!statement.IsDone()) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2186 { |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2187 if (requestSomeInstance) |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2188 { |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
2189 output.AnswerMatchingResource(statement.ReadString(0), statement.ReadString(1)); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2190 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2191 else |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2192 { |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
2193 output.AnswerMatchingResource(statement.ReadString(0)); |
70
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2194 } |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2195 |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2196 statement.Next(); |
e6c13ddd26d9
all integration tests passing with LookupResources extension
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
69
diff
changeset
|
2197 } |
69
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2198 } |
19764fc60ade
compatibility with Orthanc SDDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
2199 #endif |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2200 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2201 |
78 | 2202 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2203 static void ExecuteSetResourcesContentTags( |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2204 DatabaseManager& manager, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2205 const std::string& table, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2206 const std::string& variablePrefix, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2207 uint32_t count, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2208 const OrthancPluginResourcesContentTags* tags) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2209 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2210 std::string sql; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2211 Dictionary args; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2212 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2213 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2214 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2215 std::string name = variablePrefix + boost::lexical_cast<std::string>(i); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2216 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2217 args.SetUtf8Value(name, tags[i].value); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2218 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2219 std::string insert = ("(" + boost::lexical_cast<std::string>(tags[i].resource) + ", " + |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2220 boost::lexical_cast<std::string>(tags[i].group) + ", " + |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2221 boost::lexical_cast<std::string>(tags[i].element) + ", " + |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2222 "${" + name + "})"); |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2223 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2224 if (sql.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2225 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2226 sql = "INSERT INTO " + table + " VALUES " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2227 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2228 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2229 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2230 sql += ", " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2231 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2232 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2233 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2234 if (!sql.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2235 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2236 DatabaseManager::StandaloneStatement statement(manager, sql); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2237 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2238 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2239 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2240 statement.SetParameterType(variablePrefix + boost::lexical_cast<std::string>(i), |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2241 ValueType_Utf8String); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2242 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2243 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2244 statement.Execute(args); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2245 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2246 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2247 #endif |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2248 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2249 |
78 | 2250 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2251 static void ExecuteSetResourcesContentMetadata( |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2252 DatabaseManager& manager, |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
2253 bool hasRevisionsSupport, |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2254 uint32_t count, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2255 const OrthancPluginResourcesContentMetadata* metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2256 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2257 std::string sqlRemove; // To overwrite |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2258 std::string sqlInsert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2259 Dictionary args; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2260 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2261 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2262 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2263 std::string name = "m" + boost::lexical_cast<std::string>(i); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2264 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2265 args.SetUtf8Value(name, metadata[i].value); |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2266 |
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2267 std::string revisionSuffix; |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
2268 if (hasRevisionsSupport) |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2269 { |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
2270 revisionSuffix = ", 0"; |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2271 } |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2272 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2273 std::string insert = ("(" + boost::lexical_cast<std::string>(metadata[i].resource) + ", " + |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2274 boost::lexical_cast<std::string>(metadata[i].metadata) + ", " + |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2275 "${" + name + "}" + revisionSuffix + ")"); |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2276 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2277 std::string remove = ("(id=" + boost::lexical_cast<std::string>(metadata[i].resource) + |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2278 " AND type=" + boost::lexical_cast<std::string>(metadata[i].metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2279 + ")"); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2280 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2281 if (sqlInsert.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2282 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2283 sqlInsert = "INSERT INTO Metadata VALUES " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2284 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2285 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2286 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2287 sqlInsert += ", " + insert; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2288 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2289 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2290 if (sqlRemove.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2291 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2292 sqlRemove = "DELETE FROM Metadata WHERE " + remove; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2293 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2294 else |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2295 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2296 sqlRemove += " OR " + remove; |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2297 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2298 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2299 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2300 if (!sqlRemove.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2301 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2302 DatabaseManager::StandaloneStatement statement(manager, sqlRemove); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2303 statement.Execute(); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2304 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2305 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2306 if (!sqlInsert.empty()) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2307 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2308 DatabaseManager::StandaloneStatement statement(manager, sqlInsert); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2309 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2310 for (uint32_t i = 0; i < count; i++) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2311 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2312 statement.SetParameterType("m" + boost::lexical_cast<std::string>(i), |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2313 ValueType_Utf8String); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2314 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2315 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2316 statement.Execute(args); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2317 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2318 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2319 #endif |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2320 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2321 |
78 | 2322 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2323 // New primitive since Orthanc 1.5.2 |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2324 void IndexBackend::SetResourcesContent( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2325 DatabaseManager& manager, |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2326 uint32_t countIdentifierTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2327 const OrthancPluginResourcesContentTags* identifierTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2328 uint32_t countMainDicomTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2329 const OrthancPluginResourcesContentTags* mainDicomTags, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2330 uint32_t countMetadata, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2331 const OrthancPluginResourcesContentMetadata* metadata) |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2332 { |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2333 /** |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2334 * TODO - PostgreSQL doesn't allow multiple commands in a prepared |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2335 * statement, so we execute 3 separate commands (for identifiers, |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2336 * main tags and metadata). Maybe MySQL does not suffer from the |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2337 * same limitation, to check. |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2338 **/ |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2339 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2340 ExecuteSetResourcesContentTags(manager, "DicomIdentifiers", "i", |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2341 countIdentifierTags, identifierTags); |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2342 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2343 ExecuteSetResourcesContentTags(manager, "MainDicomTags", "t", |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2344 countMainDicomTags, mainDicomTags); |
256
e184dcadf163
handling of revisions in metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
2345 |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
265
diff
changeset
|
2346 ExecuteSetResourcesContentMetadata(manager, HasRevisionsSupport(), countMetadata, metadata); |
75
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2347 } |
52c70007bb87
new extension implemented for PostgreSQL: SetResourcesContent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
2348 #endif |
76
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2349 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2350 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2351 // New primitive since Orthanc 1.5.2 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2352 void IndexBackend::GetChildrenMetadata(std::list<std::string>& target, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2353 DatabaseManager& manager, |
76
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2354 int64_t resourceId, |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2355 int32_t metadata) |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2356 { |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2357 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2358 STATEMENT_FROM_HERE, manager, |
76
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2359 "SELECT value FROM Metadata WHERE type=${metadata} AND " |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2360 "id IN (SELECT internalId FROM Resources WHERE parentId=${id})"); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2361 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2362 statement.SetReadOnly(true); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2363 statement.SetParameterType("id", ValueType_Integer64); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2364 statement.SetParameterType("metadata", ValueType_Integer64); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2365 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2366 Dictionary args; |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2367 args.SetIntegerValue("id", static_cast<int>(resourceId)); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2368 args.SetIntegerValue("metadata", static_cast<int>(metadata)); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2369 |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2370 ReadListOfStrings(target, statement, args); |
a1c6238b26f8
new extension implemented for PostgreSQL: GetChildrenMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
75
diff
changeset
|
2371 } |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2372 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2373 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2374 // New primitive since Orthanc 1.5.2 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2375 void IndexBackend::TagMostRecentPatient(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2376 int64_t patient) |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2377 { |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2378 std::string suffix; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2379 if (manager.GetDialect() == Dialect_MSSQL) |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2380 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2381 suffix = "OFFSET 0 ROWS FETCH FIRST 2 ROWS ONLY"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2382 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2383 else |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2384 { |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2385 suffix = "LIMIT 2"; |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2386 } |
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2387 |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2388 int64_t seq; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2389 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2390 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2391 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2392 STATEMENT_FROM_HERE, manager, |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2393 "SELECT * FROM PatientRecyclingOrder WHERE seq >= " |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2394 "(SELECT seq FROM PatientRecyclingOrder WHERE patientid=${id}) ORDER BY seq " + suffix); |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2395 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2396 statement.SetReadOnly(true); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2397 statement.SetParameterType("id", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2398 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2399 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2400 args.SetIntegerValue("id", patient); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2401 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2402 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2403 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2404 if (statement.IsDone()) |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2405 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2406 // The patient is protected, don't add it to the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2407 return; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2408 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2409 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
2410 seq = statement.ReadInteger64(0); |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2411 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2412 statement.Next(); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2413 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2414 if (statement.IsDone()) |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2415 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2416 // The patient is already at the end of the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2417 // (because of the "LIMIT 2" above), no need to modify the table |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2418 return; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2419 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2420 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2421 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2422 // Delete the old position of the patient in the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2423 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2424 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2425 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2426 STATEMENT_FROM_HERE, manager, |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2427 "DELETE FROM PatientRecyclingOrder WHERE seq=${seq}"); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2428 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2429 statement.SetParameterType("seq", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2430 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2431 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2432 args.SetIntegerValue("seq", seq); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2433 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2434 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2435 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2436 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2437 // Add the patient to the end of the recycling order |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2438 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2439 { |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2440 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2441 STATEMENT_FROM_HERE, manager, |
306
544e0c943b40
added transact-sql dialect for LIMIT and OFFSET
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
304
diff
changeset
|
2442 "INSERT INTO PatientRecyclingOrder VALUES(${AUTOINCREMENT} ${id})"); |
88
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2443 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2444 statement.SetParameterType("id", ValueType_Integer64); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2445 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2446 Dictionary args; |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2447 args.SetIntegerValue("id", patient); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2448 |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2449 statement.Execute(args); |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2450 } |
eb08ec14fb04
new extension implemented: TagMostRecentPatient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
85
diff
changeset
|
2451 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2452 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2453 |
410
614031f7a16d
OrthancPostgreSQL-5.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
406
diff
changeset
|
2454 // New primitive since Orthanc 1.5.4 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2455 bool IndexBackend::LookupResourceAndParent(int64_t& id, |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2456 OrthancPluginResourceType& type, |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2457 std::string& parentPublicId, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2458 DatabaseManager& manager, |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2459 const char* publicId) |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2460 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2461 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2462 STATEMENT_FROM_HERE, manager, |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2463 "SELECT resource.internalId, resource.resourceType, parent.publicId " |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2464 "FROM Resources AS resource LEFT JOIN Resources parent ON parent.internalId=resource.parentId " |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2465 "WHERE resource.publicId=${id}"); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2466 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2467 statement.SetParameterType("id", ValueType_Utf8String); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2468 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2469 Dictionary args; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2470 args.SetUtf8Value("id", publicId); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2471 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2472 statement.Execute(args); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2473 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2474 if (statement.IsDone()) |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2475 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2476 return false; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2477 } |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2478 else |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2479 { |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2480 if (statement.GetResultFieldsCount() != 3) |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2481 { |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2482 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2483 } |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2484 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2485 statement.SetResultFieldType(0, ValueType_Integer64); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2486 statement.SetResultFieldType(1, ValueType_Integer64); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2487 statement.SetResultFieldType(2, ValueType_Utf8String); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2488 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
2489 id = statement.ReadInteger64(0); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
2490 type = static_cast<OrthancPluginResourceType>(statement.ReadInteger32(1)); |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2491 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2492 const IValue& value = statement.GetResultField(2); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2493 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2494 switch (value.GetType()) |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2495 { |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2496 case ValueType_Null: |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2497 parentPublicId.clear(); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2498 break; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2499 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2500 case ValueType_Utf8String: |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2501 parentPublicId = dynamic_cast<const Utf8StringValue&>(value).GetContent(); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2502 break; |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2503 |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2504 default: |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2505 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2506 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2507 |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2508 assert((statement.Next(), statement.IsDone())); |
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2509 return true; |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2510 } |
203
2089d4071408
moving classes out of OrthancPlugins namespace, to OrthancDatabases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
2511 } |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2512 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2513 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2514 // New primitive since Orthanc 1.5.4 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2515 void IndexBackend::GetAllMetadata(std::map<int32_t, std::string>& result, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2516 DatabaseManager& manager, |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2517 int64_t id) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2518 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2519 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2520 STATEMENT_FROM_HERE, manager, |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2521 "SELECT type, value FROM Metadata WHERE id=${id}"); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2522 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2523 statement.SetReadOnly(true); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2524 statement.SetParameterType("id", ValueType_Integer64); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2525 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2526 Dictionary args; |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2527 args.SetIntegerValue("id", id); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2528 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2529 statement.Execute(args); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2530 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2531 result.clear(); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2532 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2533 if (!statement.IsDone()) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2534 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2535 if (statement.GetResultFieldsCount() != 2) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2536 { |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2537 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2538 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2539 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2540 statement.SetResultFieldType(0, ValueType_Integer64); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2541 statement.SetResultFieldType(1, ValueType_Utf8String); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2542 |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2543 while (!statement.IsDone()) |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2544 { |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
262
diff
changeset
|
2545 result[statement.ReadInteger32(0)] = statement.ReadString(1); |
117
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2546 statement.Next(); |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2547 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2548 } |
ca0ecd412988
Implementation of new extensions: LookupResourceAndParent and GetAllMetadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
2549 } |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2550 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2551 |
271
6b18d3fbee82
backward compatibility with Orthanc SDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
266
diff
changeset
|
2552 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2553 void IndexBackend::CreateInstanceGeneric(OrthancPluginCreateInstanceResult& result, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2554 DatabaseManager& manager, |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2555 const char* hashPatient, |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2556 const char* hashStudy, |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2557 const char* hashSeries, |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2558 const char* hashInstance) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2559 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2560 // Check out "OrthancServer/Sources/Database/Compatibility/ICreateInstance.cpp" |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2561 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2562 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2563 OrthancPluginResourceType type; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2564 int64_t tmp; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2565 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2566 if (LookupResource(tmp, type, manager, hashInstance)) |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2567 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2568 // The instance already exists |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2569 assert(type == OrthancPluginResourceType_Instance); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2570 result.instanceId = tmp; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2571 result.isNewInstance = false; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2572 return; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2573 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2574 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2575 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2576 result.instanceId = CreateResource(manager, hashInstance, OrthancPluginResourceType_Instance); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2577 result.isNewInstance = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2578 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2579 result.isNewPatient = false; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2580 result.isNewStudy = false; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2581 result.isNewSeries = false; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2582 result.patientId = -1; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2583 result.studyId = -1; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2584 result.seriesId = -1; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2585 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2586 // Detect up to which level the patient/study/series/instance |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2587 // hierarchy must be created |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2588 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2589 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2590 OrthancPluginResourceType dummy; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2591 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2592 if (LookupResource(result.seriesId, dummy, manager, hashSeries)) |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2593 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2594 assert(dummy == OrthancPluginResourceType_Series); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2595 // The patient, the study and the series already exist |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2596 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2597 bool ok = (LookupResource(result.patientId, dummy, manager, hashPatient) && |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2598 LookupResource(result.studyId, dummy, manager, hashStudy)); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2599 (void) ok; // Remove warning about unused variable in release builds |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2600 assert(ok); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2601 } |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2602 else if (LookupResource(result.studyId, dummy, manager, hashStudy)) |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2603 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2604 assert(dummy == OrthancPluginResourceType_Study); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2605 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2606 // New series: The patient and the study already exist |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2607 result.isNewSeries = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2608 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2609 bool ok = LookupResource(result.patientId, dummy, manager, hashPatient); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2610 (void) ok; // Remove warning about unused variable in release builds |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2611 assert(ok); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2612 } |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2613 else if (LookupResource(result.patientId, dummy, manager, hashPatient)) |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2614 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2615 assert(dummy == OrthancPluginResourceType_Patient); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2616 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2617 // New study and series: The patient already exist |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2618 result.isNewStudy = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2619 result.isNewSeries = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2620 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2621 else |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2622 { |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2623 // New patient, study and series: Nothing exists |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2624 result.isNewPatient = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2625 result.isNewStudy = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2626 result.isNewSeries = true; |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2627 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2628 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2629 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2630 // Create the series if needed |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2631 if (result.isNewSeries) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2632 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2633 result.seriesId = CreateResource(manager, hashSeries, OrthancPluginResourceType_Series); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2634 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2635 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2636 // Create the study if needed |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2637 if (result.isNewStudy) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2638 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2639 result.studyId = CreateResource(manager, hashStudy, OrthancPluginResourceType_Study); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2640 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2641 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2642 // Create the patient if needed |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2643 if (result.isNewPatient) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2644 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2645 result.patientId = CreateResource(manager, hashPatient, OrthancPluginResourceType_Patient); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2646 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2647 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2648 // Create the parent-to-child links |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2649 AttachChild(manager, result.seriesId, result.instanceId); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2650 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2651 if (result.isNewSeries) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2652 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2653 AttachChild(manager, result.studyId, result.seriesId); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2654 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2655 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2656 if (result.isNewStudy) |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2657 { |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2658 AttachChild(manager, result.patientId, result.studyId); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2659 } |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2660 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
2661 TagMostRecentPatient(manager, result.patientId); |
210
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2662 |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2663 // Sanity checks |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2664 assert(result.patientId != -1); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2665 assert(result.studyId != -1); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2666 assert(result.seriesId != -1); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2667 assert(result.instanceId != -1); |
a0c095a4ba7d
all the integration tests pass on SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
209
diff
changeset
|
2668 } |
271
6b18d3fbee82
backward compatibility with Orthanc SDK 0.9.5
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
266
diff
changeset
|
2669 #endif |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2670 |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2671 |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2672 void IndexBackend::AddLabel(DatabaseManager& manager, |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2673 int64_t resource, |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2674 const std::string& label) |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2675 { |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2676 std::unique_ptr<DatabaseManager::CachedStatement> statement; |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2677 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2678 switch (manager.GetDialect()) |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2679 { |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2680 case Dialect_PostgreSQL: |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2681 statement.reset(new DatabaseManager::CachedStatement( |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2682 STATEMENT_FROM_HERE, manager, |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2683 "INSERT INTO Labels VALUES(${id}, ${label}) ON CONFLICT DO NOTHING")); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2684 break; |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2685 |
399
19bd3ee1f0b3
support for labels in sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2686 case Dialect_SQLite: |
19bd3ee1f0b3
support for labels in sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2687 statement.reset(new DatabaseManager::CachedStatement( |
19bd3ee1f0b3
support for labels in sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2688 STATEMENT_FROM_HERE, manager, |
19bd3ee1f0b3
support for labels in sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2689 "INSERT OR IGNORE INTO Labels VALUES(${id}, ${label})")); |
19bd3ee1f0b3
support for labels in sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2690 break; |
19bd3ee1f0b3
support for labels in sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
2691 |
400
897253c21208
support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
2692 case Dialect_MySQL: |
897253c21208
support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
2693 statement.reset(new DatabaseManager::CachedStatement( |
897253c21208
support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
2694 STATEMENT_FROM_HERE, manager, |
897253c21208
support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
2695 "INSERT IGNORE INTO Labels VALUES(${id}, ${label})")); |
897253c21208
support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
2696 break; |
897253c21208
support for labels in mysql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
2697 |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2698 default: |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2699 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2700 } |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2701 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2702 statement->SetParameterType("id", ValueType_Integer64); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2703 statement->SetParameterType("label", ValueType_Utf8String); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2704 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2705 Dictionary args; |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2706 args.SetIntegerValue("id", resource); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2707 args.SetUtf8Value("label", label); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2708 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2709 statement->Execute(args); |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2710 } |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2711 |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2712 |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2713 void IndexBackend::RemoveLabel(DatabaseManager& manager, |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2714 int64_t resource, |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2715 const std::string& label) |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2716 { |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2717 DatabaseManager::CachedStatement statement( |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2718 STATEMENT_FROM_HERE, manager, |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2719 "DELETE FROM Labels WHERE id=${id} AND label=${label}"); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2720 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2721 statement.SetParameterType("id", ValueType_Integer64); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2722 statement.SetParameterType("label", ValueType_Utf8String); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2723 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2724 Dictionary args; |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2725 args.SetIntegerValue("id", resource); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2726 args.SetUtf8Value("label", label); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2727 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2728 statement.Execute(args); |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2729 } |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2730 |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2731 |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2732 void IndexBackend::ListLabels(std::list<std::string>& target, |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2733 DatabaseManager& manager, |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2734 int64_t resource) |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2735 { |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2736 DatabaseManager::CachedStatement statement( |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2737 STATEMENT_FROM_HERE, manager, |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2738 "SELECT label FROM Labels WHERE id=${id}"); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2739 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2740 statement.SetReadOnly(true); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2741 statement.SetParameterType("id", ValueType_Integer64); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2742 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2743 Dictionary args; |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2744 args.SetIntegerValue("id", resource); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2745 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2746 ReadListOfStrings(target, statement, args); |
391
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2747 } |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2748 |
d14e6ff04a5c
added primitives to handle labels
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
2749 |
402
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2750 void IndexBackend::ListAllLabels(std::list<std::string>& target, |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2751 DatabaseManager& manager) |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2752 { |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2753 DatabaseManager::CachedStatement statement( |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2754 STATEMENT_FROM_HERE, manager, |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2755 "SELECT DISTINCT label FROM Labels"); |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2756 |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2757 Dictionary args; |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2758 ReadListOfStrings(target, statement, args); |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2759 } |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2760 |
82921a29349a
implemented IDatabaseBackend::ListAllLabels()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
2761 |
234
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
232
diff
changeset
|
2762 void IndexBackend::Register(IndexBackend* backend, |
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
232
diff
changeset
|
2763 size_t countConnections, |
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
232
diff
changeset
|
2764 unsigned int maxDatabaseRetries) |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2765 { |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2766 if (backend == NULL) |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2767 { |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2768 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2769 } |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2770 |
373
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2771 LOG(WARNING) << "The index plugin will use " << countConnections << " connection(s) to the database, " |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2772 << "and will retry up to " << maxDatabaseRetries << " time(s) in the case of a collision"; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2773 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2774 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2775 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2776 if (OrthancPluginCheckVersionAdvanced(backend->GetContext(), 1, 12, 0) == 1) |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2777 { |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2778 OrthancDatabases::DatabaseBackendAdapterV4::Register(backend, countConnections, maxDatabaseRetries); |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2779 return; |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2780 } |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2781 # endif |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2782 #endif |
be7de633695c
started DatabaseBackendAdapterV4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
372
diff
changeset
|
2783 |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2784 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2785 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2) |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2786 if (OrthancPluginCheckVersionAdvanced(backend->GetContext(), 1, 9, 2) == 1) |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2787 { |
234
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
232
diff
changeset
|
2788 OrthancDatabases::DatabaseBackendAdapterV3::Register(backend, countConnections, maxDatabaseRetries); |
372
b5e2c1e48828
created branch db-protobuf to take advantage of OrthancPluginRegisterDatabaseBackendV4()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
2789 return; |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2790 } |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2791 # endif |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2792 #endif |
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2793 |
372
b5e2c1e48828
created branch db-protobuf to take advantage of OrthancPluginRegisterDatabaseBackendV4()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
2794 LOG(WARNING) << "Performance warning: Your version of the Orthanc core or SDK doesn't support multiple readers/writers"; |
b5e2c1e48828
created branch db-protobuf to take advantage of OrthancPluginRegisterDatabaseBackendV4()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
2795 OrthancDatabases::DatabaseBackendAdapterV2::Register(backend); |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
210
diff
changeset
|
2796 } |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2797 |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2798 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2799 bool IndexBackend::LookupGlobalIntegerProperty(int& target, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2800 DatabaseManager& manager, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2801 const char* serverIdentifier, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2802 int32_t property) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2803 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2804 std::string value; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2805 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2806 if (LookupGlobalProperty(value, manager, serverIdentifier, property)) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2807 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2808 try |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2809 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2810 target = boost::lexical_cast<int>(value); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2811 return true; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2812 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2813 catch (boost::bad_lexical_cast&) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2814 { |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
391
diff
changeset
|
2815 LOG(ERROR) << "Corrupted database"; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2816 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2817 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2818 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2819 else |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2820 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2821 return false; |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2822 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2823 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2824 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2825 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2826 void IndexBackend::SetGlobalIntegerProperty(DatabaseManager& manager, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2827 const char* serverIdentifier, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2828 int32_t property, |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2829 int value) |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2830 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2831 std::string s = boost::lexical_cast<std::string>(value); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2832 SetGlobalProperty(manager, serverIdentifier, property, s.c_str()); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2833 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2834 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2835 |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2836 void IndexBackend::Finalize() |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2837 { |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2838 OrthancDatabases::DatabaseBackendAdapterV2::Finalize(); |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2839 |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2840 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2841 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 9, 2) |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2842 OrthancDatabases::DatabaseBackendAdapterV3::Finalize(); |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2843 # endif |
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2844 #endif |
381
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
2845 |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
2846 #if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) // Macro introduced in Orthanc 1.3.1 |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
2847 # if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 0) |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
2848 OrthancDatabases::DatabaseBackendAdapterV4::Finalize(); |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
2849 # endif |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
378
diff
changeset
|
2850 #endif |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
2851 } |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2852 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2853 |
403
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
2854 DatabaseManager* IndexBackend::CreateSingleDatabaseManager(IDatabaseBackend& backend, |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
2855 bool hasIdentifierTags, |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
2856 const std::list<IdentifierTag>& identifierTags) |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2857 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
253
diff
changeset
|
2858 std::unique_ptr<DatabaseManager> manager(new DatabaseManager(backend.CreateDatabaseFactory())); |
403
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
2859 backend.ConfigureDatabase(*manager, hasIdentifierTags, identifierTags); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
234
diff
changeset
|
2860 return manager.release(); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
2861 } |
0 | 2862 } |