annotate Framework/Plugins/IndexBackend.cpp @ 304:dd4b0edd1661

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