annotate Framework/Plugins/IndexBackend.cpp @ 401:a8774581adfc db-protobuf

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