annotate Framework/Plugins/IndexBackend.cpp @ 354:2a3bbb4104fa

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