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