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