Mercurial > hg > orthanc
annotate OrthancServer/SQLiteDatabaseWrapper.cpp @ 3031:18a2d196414b db-changes
simplification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 19 Dec 2018 13:08:04 +0100 |
parents | 25afa7b8cb51 |
children | 5da6d1063d8f |
rev | line source |
---|---|
183 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1286
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2447
878b59270859
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
183 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
34 #include "PrecompiledHeadersServer.h" |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
35 #include "SQLiteDatabaseWrapper.h" |
183 | 36 |
37 #include "../Core/DicomFormat/DicomArray.h" | |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
38 #include "../Core/Logging.h" |
3019
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
39 #include "../Core/SQLite/Transaction.h" |
183 | 40 #include "EmbeddedResources.h" |
1669
a412ad57f0f9
refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1668
diff
changeset
|
41 #include "ServerToolbox.h" |
183 | 42 |
43 #include <stdio.h> | |
1247 | 44 #include <boost/lexical_cast.hpp> |
183 | 45 |
46 namespace Orthanc | |
47 { | |
48 namespace Internals | |
49 { | |
50 class SignalFileDeleted : public SQLite::IScalarFunction | |
51 { | |
52 private: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1407
diff
changeset
|
53 IDatabaseListener& listener_; |
183 | 54 |
55 public: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1407
diff
changeset
|
56 SignalFileDeleted(IDatabaseListener& listener) : |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
57 listener_(listener) |
183 | 58 { |
59 } | |
60 | |
61 virtual const char* GetName() const | |
62 { | |
63 return "SignalFileDeleted"; | |
64 } | |
65 | |
66 virtual unsigned int GetCardinality() const | |
67 { | |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
68 return 7; |
183 | 69 } |
70 | |
71 virtual void Compute(SQLite::FunctionContext& context) | |
72 { | |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
73 std::string uncompressedMD5, compressedMD5; |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
74 |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
75 if (!context.IsNullValue(5)) |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
76 { |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
77 uncompressedMD5 = context.GetStringValue(5); |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
78 } |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
79 |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
80 if (!context.IsNullValue(6)) |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
81 { |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
82 compressedMD5 = context.GetStringValue(6); |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
83 } |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
84 |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
85 FileInfo info(context.GetStringValue(0), |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
86 static_cast<FileContentType>(context.GetIntValue(1)), |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
87 static_cast<uint64_t>(context.GetInt64Value(2)), |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
88 uncompressedMD5, |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
89 static_cast<CompressionType>(context.GetIntValue(3)), |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
90 static_cast<uint64_t>(context.GetInt64Value(4)), |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
91 compressedMD5); |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
92 |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
93 listener_.SignalFileDeleted(info); |
183 | 94 } |
95 }; | |
96 | |
1158 | 97 class SignalResourceDeleted : public SQLite::IScalarFunction |
98 { | |
99 private: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1407
diff
changeset
|
100 IDatabaseListener& listener_; |
1158 | 101 |
102 public: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1407
diff
changeset
|
103 SignalResourceDeleted(IDatabaseListener& listener) : |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
104 listener_(listener) |
1158 | 105 { |
106 } | |
107 | |
108 virtual const char* GetName() const | |
109 { | |
110 return "SignalResourceDeleted"; | |
111 } | |
112 | |
113 virtual unsigned int GetCardinality() const | |
114 { | |
115 return 2; | |
116 } | |
117 | |
118 virtual void Compute(SQLite::FunctionContext& context) | |
119 { | |
120 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1)); | |
1198 | 121 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0)); |
122 listener_.SignalChange(change); | |
1158 | 123 } |
124 }; | |
125 | |
183 | 126 class SignalRemainingAncestor : public SQLite::IScalarFunction |
127 { | |
128 private: | |
129 bool hasRemainingAncestor_; | |
130 std::string remainingPublicId_; | |
131 ResourceType remainingType_; | |
132 | |
133 public: | |
660 | 134 SignalRemainingAncestor() : |
135 hasRemainingAncestor_(false) | |
136 { | |
137 } | |
138 | |
183 | 139 void Reset() |
140 { | |
141 hasRemainingAncestor_ = false; | |
142 } | |
143 | |
144 virtual const char* GetName() const | |
145 { | |
146 return "SignalRemainingAncestor"; | |
147 } | |
148 | |
149 virtual unsigned int GetCardinality() const | |
150 { | |
151 return 2; | |
152 } | |
153 | |
154 virtual void Compute(SQLite::FunctionContext& context) | |
155 { | |
156 VLOG(1) << "There exists a remaining ancestor with public ID \"" | |
157 << context.GetStringValue(0) | |
158 << "\" of type " | |
159 << context.GetIntValue(1); | |
160 | |
161 if (!hasRemainingAncestor_ || | |
162 remainingType_ >= context.GetIntValue(1)) | |
163 { | |
164 hasRemainingAncestor_ = true; | |
165 remainingPublicId_ = context.GetStringValue(0); | |
166 remainingType_ = static_cast<ResourceType>(context.GetIntValue(1)); | |
167 } | |
168 } | |
169 | |
170 bool HasRemainingAncestor() const | |
171 { | |
172 return hasRemainingAncestor_; | |
173 } | |
174 | |
175 const std::string& GetRemainingAncestorId() const | |
176 { | |
177 assert(hasRemainingAncestor_); | |
178 return remainingPublicId_; | |
179 } | |
180 | |
181 ResourceType GetRemainingAncestorType() const | |
182 { | |
183 assert(hasRemainingAncestor_); | |
184 return remainingType_; | |
185 } | |
186 }; | |
187 } | |
188 | |
189 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
190 void SQLiteDatabaseWrapper::GetChangesInternal(std::list<ServerIndexChange>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
191 bool& done, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
192 SQLite::Statement& s, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
193 uint32_t maxResults) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
194 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
195 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
196 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
197 while (target.size() < maxResults && s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
198 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
199 int64_t seq = s.ColumnInt64(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
200 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
201 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
202 const std::string& date = s.ColumnString(4); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
203 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
204 int64_t internalId = s.ColumnInt64(2); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
205 std::string publicId = GetPublicId(internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
206 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
207 target.push_back(ServerIndexChange(seq, changeType, resourceType, publicId, date)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
208 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
209 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
210 done = !(target.size() == maxResults && s.Step()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
211 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
212 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
213 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
214 void SQLiteDatabaseWrapper::GetExportedResourcesInternal(std::list<ExportedResource>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
215 bool& done, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
216 SQLite::Statement& s, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
217 uint32_t maxResults) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
218 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
219 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
220 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
221 while (target.size() < maxResults && s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
222 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
223 int64_t seq = s.ColumnInt64(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
224 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
225 std::string publicId = s.ColumnString(2); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
226 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
227 ExportedResource resource(seq, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
228 resourceType, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
229 publicId, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
230 s.ColumnString(3), // modality |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
231 s.ColumnString(8), // date |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
232 s.ColumnString(4), // patient ID |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
233 s.ColumnString(5), // study instance UID |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
234 s.ColumnString(6), // series instance UID |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
235 s.ColumnString(7)); // sop instance UID |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
236 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
237 target.push_back(resource); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
238 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
239 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
240 done = !(target.size() == maxResults && s.Step()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
241 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
242 |
1241 | 243 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
244 void SQLiteDatabaseWrapper::GetChildren(std::list<std::string>& childrenPublicIds, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
245 int64_t id) |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
246 { |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
247 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE parentId=?"); |
585 | 248 s.BindInt64(0, id); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
249 |
1241 | 250 childrenPublicIds.clear(); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
251 while (s.Step()) |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
252 { |
1241 | 253 childrenPublicIds.push_back(s.ColumnString(0)); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
254 } |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
255 } |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
256 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
257 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
258 void SQLiteDatabaseWrapper::DeleteResource(int64_t id) |
183 | 259 { |
260 signalRemainingAncestor_->Reset(); | |
261 | |
262 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Resources WHERE internalId=?"); | |
585 | 263 s.BindInt64(0, id); |
183 | 264 s.Run(); |
265 | |
1247 | 266 if (signalRemainingAncestor_->HasRemainingAncestor() && |
267 listener_ != NULL) | |
183 | 268 { |
1247 | 269 listener_->SignalRemainingAncestor(signalRemainingAncestor_->GetRemainingAncestorType(), |
270 signalRemainingAncestor_->GetRemainingAncestorId()); | |
183 | 271 } |
272 } | |
273 | |
274 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
275 bool SQLiteDatabaseWrapper::GetParentPublicId(std::string& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
276 int64_t id) |
183 | 277 { |
278 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.publicId FROM Resources AS a, Resources AS b " | |
279 "WHERE a.internalId = b.parentId AND b.internalId = ?"); | |
585 | 280 s.BindInt64(0, id); |
183 | 281 |
282 if (s.Step()) | |
283 { | |
1301 | 284 target = s.ColumnString(0); |
183 | 285 return true; |
286 } | |
287 else | |
288 { | |
289 return false; | |
290 } | |
291 } | |
292 | |
293 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
294 int64_t SQLiteDatabaseWrapper::GetTableRecordCount(const std::string& table) |
183 | 295 { |
296 char buf[128]; | |
297 sprintf(buf, "SELECT COUNT(*) FROM %s", table.c_str()); | |
298 SQLite::Statement s(db_, buf); | |
299 | |
218 | 300 if (!s.Step()) |
301 { | |
302 throw OrthancException(ErrorCode_InternalError); | |
303 } | |
304 | |
183 | 305 int64_t c = s.ColumnInt(0); |
306 assert(!s.Step()); | |
307 | |
308 return c; | |
309 } | |
310 | |
311 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
312 SQLiteDatabaseWrapper::SQLiteDatabaseWrapper(const std::string& path) : |
1847 | 313 listener_(NULL), |
314 signalRemainingAncestor_(NULL), | |
315 version_(0) | |
183 | 316 { |
317 db_.Open(path); | |
318 } | |
319 | |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
320 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
321 SQLiteDatabaseWrapper::SQLiteDatabaseWrapper() : |
1847 | 322 listener_(NULL), |
323 signalRemainingAncestor_(NULL), | |
324 version_(0) | |
183 | 325 { |
326 db_.OpenInMemory(); | |
327 } | |
328 | |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
329 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
330 void SQLiteDatabaseWrapper::Open() |
183 | 331 { |
1717
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1712
diff
changeset
|
332 db_.Execute("PRAGMA ENCODING=\"UTF-8\";"); |
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1712
diff
changeset
|
333 |
374 | 334 // Performance tuning of SQLite with PRAGMAs |
335 // http://www.sqlite.org/pragma.html | |
336 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;"); | |
337 db_.Execute("PRAGMA JOURNAL_MODE=WAL;"); | |
338 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); | |
339 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); | |
340 //db_.Execute("PRAGMA TEMP_STORE=memory"); | |
341 | |
3027 | 342 // Make "LIKE" case-sensitive in SQLite |
343 db_.Execute("PRAGMA case_sensitive_like = true;"); | |
344 | |
183 | 345 if (!db_.DoesTableExist("GlobalProperties")) |
346 { | |
347 LOG(INFO) << "Creating the database"; | |
348 std::string query; | |
203
9283552c25df
db refactoring done
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
349 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE); |
183 | 350 db_.Execute(query); |
351 } | |
352 | |
567 | 353 // Check the version of the database |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
354 std::string tmp; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
355 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabaseSchemaVersion)) |
1239 | 356 { |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
357 tmp = "Unknown"; |
1239 | 358 } |
359 | |
252 | 360 bool ok = false; |
361 try | |
362 { | |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
363 LOG(INFO) << "Version of the Orthanc database: " << tmp; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
364 version_ = boost::lexical_cast<unsigned int>(tmp); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
365 ok = true; |
252 | 366 } |
367 catch (boost::bad_lexical_cast&) | |
368 { | |
369 } | |
370 | |
371 if (!ok) | |
372 { | |
2955 | 373 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion, |
374 "Incompatible version of the Orthanc database: " + tmp); | |
252 | 375 } |
376 | |
3018
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
377 // New in Orthanc 1.5.1 |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
378 if (version_ == 6) |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
379 { |
3019
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
380 if (!LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast) || |
3018
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
381 tmp != "1") |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
382 { |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
383 LOG(INFO) << "Installing the SQLite triggers to track the size of the attachments"; |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
384 std::string query; |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
385 EmbeddedResources::GetFileResource(query, EmbeddedResources::INSTALL_TRACK_ATTACHMENTS_SIZE); |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
386 db_.Execute(query); |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
387 } |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
388 } |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
389 |
183 | 390 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor; |
391 db_.Register(signalRemainingAncestor_); | |
1247 | 392 } |
393 | |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
394 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
395 static void ExecuteUpgradeScript(SQLite::Connection& db, |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
396 EmbeddedResources::FileResourceId script) |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
397 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
398 std::string upgrade; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
399 EmbeddedResources::GetFileResource(upgrade, script); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
400 db.BeginTransaction(); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
401 db.Execute(upgrade); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
402 db.CommitTransaction(); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
403 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
404 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
405 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
406 void SQLiteDatabaseWrapper::Upgrade(unsigned int targetVersion, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
407 IStorageArea& storageArea) |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
408 { |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
409 if (targetVersion != 6) |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
410 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
411 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
412 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
413 |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
414 // This version of Orthanc is only compatible with versions 3, 4, |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
415 // 5 and 6 of the DB schema |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
416 if (version_ != 3 && |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
417 version_ != 4 && |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
418 version_ != 5 && |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
419 version_ != 6) |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
420 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
421 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
422 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
423 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
424 if (version_ == 3) |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
425 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
426 LOG(WARNING) << "Upgrading database version from 3 to 4"; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
427 ExecuteUpgradeScript(db_, EmbeddedResources::UPGRADE_DATABASE_3_TO_4); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
428 version_ = 4; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
429 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
430 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
431 if (version_ == 4) |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
432 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
433 LOG(WARNING) << "Upgrading database version from 4 to 5"; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
434 ExecuteUpgradeScript(db_, EmbeddedResources::UPGRADE_DATABASE_4_TO_5); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
435 version_ = 5; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
436 } |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
437 |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
438 if (version_ == 5) |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
439 { |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
440 LOG(WARNING) << "Upgrading database version from 5 to 6"; |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1665
diff
changeset
|
441 // No change in the DB schema, the step from version 5 to 6 only |
1710 | 442 // consists in reconstructing the main DICOM tags information |
443 // (as more tags got included). | |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1665
diff
changeset
|
444 db_.BeginTransaction(); |
2120 | 445 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Patient); |
446 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Study); | |
447 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Series); | |
448 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Instance); | |
1710 | 449 db_.Execute("UPDATE GlobalProperties SET value=\"6\" WHERE property=" + |
450 boost::lexical_cast<std::string>(GlobalProperty_DatabaseSchemaVersion) + ";"); | |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1665
diff
changeset
|
451 db_.CommitTransaction(); |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
452 version_ = 6; |
1729 | 453 } |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
454 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
455 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
456 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
457 void SQLiteDatabaseWrapper::SetListener(IDatabaseListener& listener) |
1247 | 458 { |
459 listener_ = &listener; | |
460 db_.Register(new Internals::SignalFileDeleted(listener)); | |
461 db_.Register(new Internals::SignalResourceDeleted(listener)); | |
183 | 462 } |
238 | 463 |
413
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
464 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
465 void SQLiteDatabaseWrapper::ClearTable(const std::string& tableName) |
413
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
466 { |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
467 db_.Execute("DELETE FROM " + tableName); |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
468 } |
513 | 469 |
470 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
471 bool SQLiteDatabaseWrapper::LookupParent(int64_t& parentId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
472 int64_t resourceId) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
473 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
474 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
475 "SELECT parentId FROM Resources WHERE internalId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
476 s.BindInt64(0, resourceId); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
477 |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
478 if (!s.Step()) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
479 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
480 throw OrthancException(ErrorCode_UnknownResource); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
481 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
482 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
483 if (s.ColumnIsNull(0)) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
484 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
485 return false; |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
486 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
487 else |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
488 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
489 parentId = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
490 return true; |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
491 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
492 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
493 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
494 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
495 ResourceType SQLiteDatabaseWrapper::GetResourceType(int64_t resourceId) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
496 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
497 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
498 "SELECT resourceType FROM Resources WHERE internalId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
499 s.BindInt64(0, resourceId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
500 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
501 if (s.Step()) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
502 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
503 return static_cast<ResourceType>(s.ColumnInt(0)); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
504 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
505 else |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
506 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
507 throw OrthancException(ErrorCode_UnknownResource); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
508 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
509 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
510 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
511 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
512 std::string SQLiteDatabaseWrapper::GetPublicId(int64_t resourceId) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
513 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
514 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
515 "SELECT publicId FROM Resources WHERE internalId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
516 s.BindInt64(0, resourceId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
517 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
518 if (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
519 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
520 return s.ColumnString(0); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
521 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
522 else |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
523 { |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
524 throw OrthancException(ErrorCode_UnknownResource); |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
525 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
526 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
527 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
528 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
529 void SQLiteDatabaseWrapper::GetChanges(std::list<ServerIndexChange>& target /*out*/, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
530 bool& done /*out*/, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
531 int64_t since, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
532 uint32_t maxResults) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
533 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
534 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes WHERE seq>? ORDER BY seq LIMIT ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
535 s.BindInt64(0, since); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
536 s.BindInt(1, maxResults + 1); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
537 GetChangesInternal(target, done, s, maxResults); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
538 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
539 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
540 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
541 void SQLiteDatabaseWrapper::GetLastChange(std::list<ServerIndexChange>& target /*out*/) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
542 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
543 bool done; // Ignored |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
544 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
545 GetChangesInternal(target, done, s, 1); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
546 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
547 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
548 |
3019
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
549 class SQLiteDatabaseWrapper::Transaction : public IDatabaseWrapper::ITransaction |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
550 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
551 private: |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
552 SQLiteDatabaseWrapper& that_; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
553 std::auto_ptr<SQLite::Transaction> transaction_; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
554 int64_t initialDiskSize_; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
555 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
556 public: |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
557 Transaction(SQLiteDatabaseWrapper& that) : |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
558 that_(that), |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
559 transaction_(new SQLite::Transaction(that_.db_)) |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
560 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
561 #if defined(NDEBUG) |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
562 // Release mode |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
563 initialDiskSize_ = 0; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
564 #else |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
565 // Debug mode |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
566 initialDiskSize_ = static_cast<int64_t>(that_.GetTotalCompressedSize()); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
567 #endif |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
568 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
569 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
570 virtual void Begin() |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
571 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
572 transaction_->Begin(); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
573 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
574 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
575 virtual void Rollback() |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
576 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
577 transaction_->Rollback(); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
578 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
579 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
580 virtual void Commit(int64_t fileSizeDelta /* only used in debug */) |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
581 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
582 transaction_->Commit(); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
583 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
584 assert(initialDiskSize_ + fileSizeDelta >= 0 && |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
585 initialDiskSize_ + fileSizeDelta == static_cast<int64_t>(that_.GetTotalCompressedSize())); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
586 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
587 }; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
588 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
589 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
590 IDatabaseWrapper::ITransaction* SQLiteDatabaseWrapper::StartTransaction() |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
591 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
592 return new Transaction(*this); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
593 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
594 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
595 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
596 void SQLiteDatabaseWrapper::GetAllMetadata(std::map<MetadataType, std::string>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
597 int64_t id) |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
598 { |
1301 | 599 target.clear(); |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
600 |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
601 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT type, value FROM Metadata WHERE id=?"); |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
602 s.BindInt64(0, id); |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
603 |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
604 while (s.Step()) |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
605 { |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
606 MetadataType key = static_cast<MetadataType>(s.ColumnInt(0)); |
1301 | 607 target[key] = s.ColumnString(1); |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
608 } |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
609 } |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
610 |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
611 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
612 void SQLiteDatabaseWrapper::SetGlobalProperty(GlobalProperty property, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
613 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
614 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
615 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO GlobalProperties VALUES(?, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
616 s.BindInt(0, property); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
617 s.BindString(1, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
618 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
619 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
620 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
621 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
622 bool SQLiteDatabaseWrapper::LookupGlobalProperty(std::string& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
623 GlobalProperty property) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
624 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
625 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
626 "SELECT value FROM GlobalProperties WHERE property=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
627 s.BindInt(0, property); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
628 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
629 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
630 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
631 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
632 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
633 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
634 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
635 target = s.ColumnString(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
636 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
637 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
638 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
639 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
640 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
641 int64_t SQLiteDatabaseWrapper::CreateResource(const std::string& publicId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
642 ResourceType type) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
643 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
644 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Resources VALUES(NULL, ?, ?, NULL)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
645 s.BindInt(0, type); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
646 s.BindString(1, publicId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
647 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
648 return db_.GetLastInsertRowId(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
649 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
650 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
651 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
652 bool SQLiteDatabaseWrapper::LookupResource(int64_t& id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
653 ResourceType& type, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
654 const std::string& publicId) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
655 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
656 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
657 "SELECT internalId, resourceType FROM Resources WHERE publicId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
658 s.BindString(0, publicId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
659 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
660 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
661 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
662 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
663 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
664 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
665 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
666 id = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
667 type = static_cast<ResourceType>(s.ColumnInt(1)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
668 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
669 // Check whether there is a single resource with this public id |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
670 assert(!s.Step()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
671 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
672 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
673 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
674 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
675 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
676 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
677 void SQLiteDatabaseWrapper::AttachChild(int64_t parent, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
678 int64_t child) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
679 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
680 SQLite::Statement s(db_, SQLITE_FROM_HERE, "UPDATE Resources SET parentId = ? WHERE internalId = ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
681 s.BindInt64(0, parent); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
682 s.BindInt64(1, child); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
683 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
684 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
685 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
686 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
687 void SQLiteDatabaseWrapper::SetMetadata(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
688 MetadataType type, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
689 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
690 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
691 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO Metadata VALUES(?, ?, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
692 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
693 s.BindInt(1, type); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
694 s.BindString(2, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
695 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
696 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
697 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
698 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
699 void SQLiteDatabaseWrapper::DeleteMetadata(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
700 MetadataType type) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
701 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
702 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Metadata WHERE id=? and type=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
703 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
704 s.BindInt(1, type); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
705 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
706 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
707 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
708 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
709 bool SQLiteDatabaseWrapper::LookupMetadata(std::string& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
710 int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
711 MetadataType type) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
712 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
713 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
714 "SELECT value FROM Metadata WHERE id=? AND type=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
715 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
716 s.BindInt(1, type); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
717 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
718 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
719 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
720 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
721 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
722 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
723 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
724 target = s.ColumnString(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
725 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
726 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
727 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
728 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
729 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
730 void SQLiteDatabaseWrapper::ListAvailableMetadata(std::list<MetadataType>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
731 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
732 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
733 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
734 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
735 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT type FROM Metadata WHERE id=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
736 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
737 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
738 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
739 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
740 target.push_back(static_cast<MetadataType>(s.ColumnInt(0))); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
741 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
742 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
743 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
744 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
745 void SQLiteDatabaseWrapper::AddAttachment(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
746 const FileInfo& attachment) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
747 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
748 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
749 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
750 s.BindInt(1, attachment.GetContentType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
751 s.BindString(2, attachment.GetUuid()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
752 s.BindInt64(3, attachment.GetCompressedSize()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
753 s.BindInt64(4, attachment.GetUncompressedSize()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
754 s.BindInt(5, attachment.GetCompressionType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
755 s.BindString(6, attachment.GetUncompressedMD5()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
756 s.BindString(7, attachment.GetCompressedMD5()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
757 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
758 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
759 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
760 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
761 void SQLiteDatabaseWrapper::DeleteAttachment(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
762 FileContentType attachment) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
763 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
764 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM AttachedFiles WHERE id=? AND fileType=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
765 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
766 s.BindInt(1, attachment); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
767 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
768 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
769 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
770 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
771 void SQLiteDatabaseWrapper::ListAvailableAttachments(std::list<FileContentType>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
772 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
773 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
774 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
775 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
776 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
777 "SELECT fileType FROM AttachedFiles WHERE id=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
778 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
779 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
780 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
781 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
782 target.push_back(static_cast<FileContentType>(s.ColumnInt(0))); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
783 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
784 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
785 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
786 bool SQLiteDatabaseWrapper::LookupAttachment(FileInfo& attachment, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
787 int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
788 FileContentType contentType) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
789 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
790 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
791 "SELECT uuid, uncompressedSize, compressionType, compressedSize, " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
792 "uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
793 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
794 s.BindInt(1, contentType); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
795 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
796 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
797 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
798 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
799 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
800 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
801 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
802 attachment = FileInfo(s.ColumnString(0), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
803 contentType, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
804 s.ColumnInt64(1), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
805 s.ColumnString(4), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
806 static_cast<CompressionType>(s.ColumnInt(2)), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
807 s.ColumnInt64(3), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
808 s.ColumnString(5)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
809 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
810 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
811 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
812 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
813 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
814 void SQLiteDatabaseWrapper::ClearMainDicomTags(int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
815 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
816 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
817 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM DicomIdentifiers WHERE id=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
818 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
819 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
820 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
821 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
822 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
823 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM MainDicomTags WHERE id=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
824 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
825 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
826 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
827 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
828 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
829 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
830 void SQLiteDatabaseWrapper::SetMainDicomTag(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
831 const DicomTag& tag, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
832 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
833 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
834 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
835 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
836 s.BindInt(1, tag.GetGroup()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
837 s.BindInt(2, tag.GetElement()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
838 s.BindString(3, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
839 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
840 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
841 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
842 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
843 void SQLiteDatabaseWrapper::SetIdentifierTag(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
844 const DicomTag& tag, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
845 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
846 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
847 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifiers VALUES(?, ?, ?, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
848 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
849 s.BindInt(1, tag.GetGroup()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
850 s.BindInt(2, tag.GetElement()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
851 s.BindString(3, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
852 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
853 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
854 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
855 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
856 void SQLiteDatabaseWrapper::GetMainDicomTags(DicomMap& map, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
857 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
858 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
859 map.Clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
860 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
861 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM MainDicomTags WHERE id=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
862 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
863 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
864 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
865 map.SetValue(s.ColumnInt(1), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
866 s.ColumnInt(2), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
867 s.ColumnString(3), false); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
868 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
869 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
870 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
871 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
872 void SQLiteDatabaseWrapper::GetChildrenPublicId(std::list<std::string>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
873 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
874 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
875 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.publicId FROM Resources AS a, Resources AS b " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
876 "WHERE a.parentId = b.internalId AND b.internalId = ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
877 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
878 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
879 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
880 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
881 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
882 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
883 target.push_back(s.ColumnString(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
884 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
885 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
886 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
887 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
888 void SQLiteDatabaseWrapper::GetChildrenInternalId(std::list<int64_t>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
889 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
890 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
891 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.internalId FROM Resources AS a, Resources AS b " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
892 "WHERE a.parentId = b.internalId AND b.internalId = ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
893 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
894 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
895 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
896 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
897 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
898 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
899 target.push_back(s.ColumnInt64(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
900 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
901 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
902 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
903 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
904 void SQLiteDatabaseWrapper::LogChange(int64_t internalId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
905 const ServerIndexChange& change) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
906 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
907 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
908 s.BindInt(0, change.GetChangeType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
909 s.BindInt64(1, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
910 s.BindInt(2, change.GetResourceType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
911 s.BindString(3, change.GetDate()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
912 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
913 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
914 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
915 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
916 void SQLiteDatabaseWrapper::LogExportedResource(const ExportedResource& resource) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
917 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
918 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
919 "INSERT INTO ExportedResources VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
920 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
921 s.BindInt(0, resource.GetResourceType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
922 s.BindString(1, resource.GetPublicId()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
923 s.BindString(2, resource.GetModality()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
924 s.BindString(3, resource.GetPatientId()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
925 s.BindString(4, resource.GetStudyInstanceUid()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
926 s.BindString(5, resource.GetSeriesInstanceUid()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
927 s.BindString(6, resource.GetSopInstanceUid()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
928 s.BindString(7, resource.GetDate()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
929 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
930 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
931 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
932 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
933 void SQLiteDatabaseWrapper::GetExportedResources(std::list<ExportedResource>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
934 bool& done, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
935 int64_t since, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
936 uint32_t maxResults) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
937 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
938 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
939 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
940 s.BindInt64(0, since); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
941 s.BindInt(1, maxResults + 1); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
942 GetExportedResourcesInternal(target, done, s, maxResults); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
943 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
944 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
945 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
946 void SQLiteDatabaseWrapper::GetLastExportedResource(std::list<ExportedResource>& target) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
947 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
948 bool done; // Ignored |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
949 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
950 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
951 GetExportedResourcesInternal(target, done, s, 1); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
952 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
953 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
954 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
955 uint64_t SQLiteDatabaseWrapper::GetTotalCompressedSize() |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
956 { |
3018
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
957 // Old SQL query that was used in Orthanc <= 1.5.0: |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
958 // SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(compressedSize) FROM AttachedFiles"); |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
959 |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
960 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT value FROM GlobalIntegers WHERE key=0"); |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
961 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
962 return static_cast<uint64_t>(s.ColumnInt64(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
963 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
964 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
965 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
966 uint64_t SQLiteDatabaseWrapper::GetTotalUncompressedSize() |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
967 { |
3018
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
968 // Old SQL query that was used in Orthanc <= 1.5.0: |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
969 // SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(uncompressedSize) FROM AttachedFiles"); |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
970 |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
971 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT value FROM GlobalIntegers WHERE key=1"); |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
972 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
973 return static_cast<uint64_t>(s.ColumnInt64(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
974 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
975 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
976 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
977 uint64_t SQLiteDatabaseWrapper::GetResourceCount(ResourceType resourceType) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
978 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
979 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
980 "SELECT COUNT(*) FROM Resources WHERE resourceType=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
981 s.BindInt(0, resourceType); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
982 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
983 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
984 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
985 return 0; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
986 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
987 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
988 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
989 int64_t c = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
990 assert(!s.Step()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
991 return c; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
992 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
993 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
994 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
995 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
996 void SQLiteDatabaseWrapper::GetAllInternalIds(std::list<int64_t>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
997 ResourceType resourceType) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
998 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
999 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT internalId FROM Resources WHERE resourceType=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1000 s.BindInt(0, resourceType); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1001 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1002 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1003 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1004 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1005 target.push_back(s.ColumnInt64(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1006 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1007 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1008 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1009 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1010 void SQLiteDatabaseWrapper::GetAllPublicIds(std::list<std::string>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1011 ResourceType resourceType) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1012 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1013 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE resourceType=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1014 s.BindInt(0, resourceType); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1015 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1016 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1017 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1018 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1019 target.push_back(s.ColumnString(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1020 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1021 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1022 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1023 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1024 void SQLiteDatabaseWrapper::GetAllPublicIds(std::list<std::string>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1025 ResourceType resourceType, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1026 size_t since, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1027 size_t limit) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1028 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1029 if (limit == 0) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1030 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1031 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1032 return; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1033 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1034 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1035 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1036 "SELECT publicId FROM Resources WHERE " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1037 "resourceType=? LIMIT ? OFFSET ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1038 s.BindInt(0, resourceType); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1039 s.BindInt64(1, limit); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1040 s.BindInt64(2, since); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1041 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1042 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1043 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1044 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1045 target.push_back(s.ColumnString(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1046 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1047 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1048 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1049 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1050 bool SQLiteDatabaseWrapper::SelectPatientToRecycle(int64_t& internalId) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1051 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1052 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1053 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1054 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1055 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1056 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1057 // No patient remaining or all the patients are protected |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1058 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1059 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1060 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1061 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1062 internalId = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1063 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1064 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1065 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1066 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1067 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1068 bool SQLiteDatabaseWrapper::SelectPatientToRecycle(int64_t& internalId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1069 int64_t patientIdToAvoid) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1070 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1071 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1072 "SELECT patientId FROM PatientRecyclingOrder " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1073 "WHERE patientId != ? ORDER BY seq ASC LIMIT 1"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1074 s.BindInt64(0, patientIdToAvoid); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1075 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1076 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1077 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1078 // No patient remaining or all the patients are protected |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1079 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1080 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1081 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1082 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1083 internalId = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1084 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1085 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1086 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1087 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1088 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1089 bool SQLiteDatabaseWrapper::IsProtectedPatient(int64_t internalId) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1090 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1091 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1092 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1093 s.BindInt64(0, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1094 return !s.Step(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1095 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1096 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1097 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1098 void SQLiteDatabaseWrapper::SetProtectedPatient(int64_t internalId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1099 bool isProtected) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1100 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1101 if (isProtected) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1102 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1103 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM PatientRecyclingOrder WHERE patientId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1104 s.BindInt64(0, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1105 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1106 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1107 else if (IsProtectedPatient(internalId)) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1108 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1109 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO PatientRecyclingOrder VALUES(NULL, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1110 s.BindInt64(0, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1111 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1112 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1113 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1114 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1115 // Nothing to do: The patient is already unprotected |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1116 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1117 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1118 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1119 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1120 bool SQLiteDatabaseWrapper::IsExistingResource(int64_t internalId) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1121 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1122 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1123 "SELECT * FROM Resources WHERE internalId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1124 s.BindInt64(0, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1125 return s.Step(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1126 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1127 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1128 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1129 void SQLiteDatabaseWrapper::LookupIdentifier(std::list<int64_t>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1130 ResourceType level, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1131 const DicomTag& tag, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1132 IdentifierConstraintType type, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1133 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1134 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1135 static const char* COMMON = ("SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1136 "d.id = r.internalId AND r.resourceType=? AND " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1137 "d.tagGroup=? AND d.tagElement=? AND "); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1138 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1139 std::auto_ptr<SQLite::Statement> s; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1140 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1141 switch (type) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1142 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1143 case IdentifierConstraintType_GreaterOrEqual: |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1144 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value>=?")); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1145 break; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1146 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1147 case IdentifierConstraintType_SmallerOrEqual: |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1148 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value<=?")); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1149 break; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1150 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1151 case IdentifierConstraintType_Wildcard: |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1152 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value GLOB ?")); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1153 break; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1154 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1155 case IdentifierConstraintType_Equal: |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1156 default: |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1157 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value=?")); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1158 break; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1159 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1160 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1161 assert(s.get() != NULL); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1162 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1163 s->BindInt(0, level); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1164 s->BindInt(1, tag.GetGroup()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1165 s->BindInt(2, tag.GetElement()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1166 s->BindString(3, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1167 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1168 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1169 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1170 while (s->Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1171 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1172 target.push_back(s->ColumnInt64(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1173 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1174 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1175 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1176 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1177 void SQLiteDatabaseWrapper::LookupIdentifierRange(std::list<int64_t>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1178 ResourceType level, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1179 const DicomTag& tag, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1180 const std::string& start, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1181 const std::string& end) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1182 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1183 SQLite::Statement statement(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1184 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1185 "d.id = r.internalId AND r.resourceType=? AND " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1186 "d.tagGroup=? AND d.tagElement=? AND d.value>=? AND d.value<=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1187 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1188 statement.BindInt(0, level); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1189 statement.BindInt(1, tag.GetGroup()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1190 statement.BindInt(2, tag.GetElement()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1191 statement.BindString(3, start); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1192 statement.BindString(4, end); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1193 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1194 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1195 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1196 while (statement.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1197 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1198 target.push_back(statement.ColumnInt64(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1199 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1200 } |
3020
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
1201 |
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
1202 |
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
1203 bool SQLiteDatabaseWrapper::IsDiskSizeAbove(uint64_t threshold) |
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
1204 { |
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
1205 return GetTotalCompressedSize() > threshold; |
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
1206 } |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1207 |
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1208 |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1209 static std::string FormatLevel(ResourceType level) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1210 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1211 switch (level) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1212 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1213 case ResourceType_Patient: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1214 return "patients"; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1215 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1216 case ResourceType_Study: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1217 return "studies"; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1218 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1219 case ResourceType_Series: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1220 return "series"; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1221 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1222 case ResourceType_Instance: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1223 return "instances"; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1224 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1225 default: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1226 throw OrthancException(ErrorCode_InternalError); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1227 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1228 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1229 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1230 |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1231 static bool FormatComparison(std::string& target, |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1232 const DatabaseConstraint& constraint, |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1233 size_t index, |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1234 std::vector<std::string>& parameters) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1235 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1236 std::string tag = "t" + boost::lexical_cast<std::string>(index); |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1237 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1238 std::string comparison; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1239 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1240 switch (constraint.GetConstraintType()) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1241 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1242 case ConstraintType_Equal: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1243 case ConstraintType_SmallerOrEqual: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1244 case ConstraintType_GreaterOrEqual: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1245 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1246 std::string op; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1247 switch (constraint.GetConstraintType()) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1248 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1249 case ConstraintType_Equal: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1250 op = "="; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1251 break; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1252 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1253 case ConstraintType_SmallerOrEqual: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1254 op = "<="; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1255 break; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1256 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1257 case ConstraintType_GreaterOrEqual: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1258 op = ">="; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1259 break; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1260 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1261 default: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1262 throw OrthancException(ErrorCode_InternalError); |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1263 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1264 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1265 parameters.push_back(constraint.GetSingleValue()); |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1266 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1267 if (constraint.IsCaseSensitive()) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1268 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1269 comparison = tag + ".value " + op + " ?"; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1270 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1271 else |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1272 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1273 comparison = "lower(" + tag + ".value) " + op + " lower(?)"; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1274 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1275 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1276 break; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1277 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1278 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1279 case ConstraintType_List: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1280 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1281 for (size_t i = 0; i < constraint.GetValuesCount(); i++) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1282 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1283 parameters.push_back(constraint.GetValue(i)); |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1284 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1285 if (!comparison.empty()) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1286 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1287 comparison += ", "; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1288 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1289 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1290 if (constraint.IsCaseSensitive()) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1291 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1292 comparison += "?"; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1293 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1294 else |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1295 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1296 comparison += "lower(?)"; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1297 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1298 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1299 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1300 if (constraint.IsCaseSensitive()) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1301 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1302 comparison = tag + ".value IN (" + comparison + ")"; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1303 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1304 else |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1305 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1306 comparison = "lower(" + tag + ".value) IN (" + comparison + ")"; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1307 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1308 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1309 break; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1310 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1311 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1312 case ConstraintType_Wildcard: |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1313 { |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1314 const std::string value = constraint.GetSingleValue(); |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1315 |
3031 | 1316 if (value == "*") |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1317 { |
3031 | 1318 if (!constraint.IsMandatory()) |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1319 { |
3031 | 1320 // Universal constraint on an optional tag, ignore it |
1321 return false; | |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1322 } |
3031 | 1323 } |
1324 else | |
1325 { | |
1326 std::string escaped; | |
1327 escaped.reserve(value.size()); | |
1328 | |
1329 for (size_t i = 0; i < value.size(); i++) | |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1330 { |
3031 | 1331 if (value[i] == '*') |
1332 { | |
1333 escaped += "%"; | |
1334 } | |
1335 else if (value[i] == '?') | |
1336 { | |
1337 escaped += "_"; | |
1338 } | |
1339 else if (value[i] == '%') | |
1340 { | |
1341 escaped += "\\%"; | |
1342 } | |
1343 else if (value[i] == '_') | |
1344 { | |
1345 escaped += "\\_"; | |
1346 } | |
1347 else if (value[i] == '\\') | |
1348 { | |
1349 escaped += "\\\\"; | |
1350 } | |
1351 else | |
1352 { | |
1353 escaped += value[i]; | |
1354 } | |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1355 } |
3031 | 1356 |
1357 parameters.push_back(escaped); | |
1358 | |
1359 if (constraint.IsCaseSensitive()) | |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1360 { |
3031 | 1361 comparison = tag + ".value LIKE ? ESCAPE '\\'"; |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1362 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1363 else |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1364 { |
3031 | 1365 comparison = "lower(" + tag + ".value) LIKE lower(?) ESCAPE '\\'"; |
1366 } | |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1367 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1368 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1369 break; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1370 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1371 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1372 default: |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1373 // Don't modify "parameters" in this case! |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1374 return false; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1375 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1376 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1377 if (constraint.IsMandatory()) |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1378 { |
3031 | 1379 target = comparison; |
1380 } | |
1381 else if (comparison.empty()) | |
1382 { | |
1383 target = tag + ".value IS NULL"; | |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1384 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1385 else |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1386 { |
3031 | 1387 target = tag + ".value IS NULL OR " + comparison; |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1388 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1389 |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1390 return true; |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1391 } |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1392 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1393 |
3031 | 1394 static void FormatJoin(std::string& target, |
1395 const DatabaseConstraint& constraint, | |
1396 size_t index) | |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1397 { |
3031 | 1398 std::string tag = "t" + boost::lexical_cast<std::string>(index); |
1399 | |
1400 if (constraint.IsMandatory()) | |
1401 { | |
1402 target = " INNER JOIN "; | |
1403 } | |
1404 else | |
1405 { | |
1406 target = " LEFT JOIN "; | |
1407 } | |
1408 | |
1409 if (constraint.IsIdentifier()) | |
1410 { | |
1411 target += "DicomIdentifiers "; | |
1412 } | |
1413 else | |
1414 { | |
1415 target += "MainDicomTags "; | |
1416 } | |
1417 | |
1418 target += (tag + " ON " + tag + ".id = " + FormatLevel(constraint.GetLevel()) + | |
1419 ".internalId AND " + tag + ".tagGroup = " + | |
1420 boost::lexical_cast<std::string>(constraint.GetTag().GetGroup()) + | |
1421 " AND " + tag + ".tagElement = " + | |
1422 boost::lexical_cast<std::string>(constraint.GetTag().GetElement())); | |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1423 } |
3031 | 1424 |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1425 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1426 static void AnswerLookup(std::vector<std::string>& resourcesId, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1427 std::vector<std::string>& instancesId, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1428 SQLite::Connection& db, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1429 ResourceType level) |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1430 { |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1431 resourcesId.clear(); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1432 instancesId.clear(); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1433 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1434 std::auto_ptr<SQLite::Statement> statement; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1435 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1436 switch (level) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1437 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1438 case ResourceType_Patient: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1439 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1440 statement.reset( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1441 new SQLite::Statement( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1442 db, SQLITE_FROM_HERE, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1443 "SELECT patients.publicId, instances.publicID FROM Lookup AS patients " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1444 "INNER JOIN Resources studies ON patients.internalId=studies.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1445 "INNER JOIN Resources series ON studies.internalId=series.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1446 "INNER JOIN Resources instances ON series.internalId=instances.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1447 "GROUP BY patients.publicId")); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1448 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1449 break; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1450 } |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1451 |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1452 case ResourceType_Study: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1453 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1454 statement.reset( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1455 new SQLite::Statement( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1456 db, SQLITE_FROM_HERE, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1457 "SELECT studies.publicId, instances.publicID FROM Lookup AS studies " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1458 "INNER JOIN Resources series ON studies.internalId=series.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1459 "INNER JOIN Resources instances ON series.internalId=instances.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1460 "GROUP BY studies.publicId")); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1461 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1462 break; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1463 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1464 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1465 case ResourceType_Series: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1466 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1467 statement.reset( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1468 new SQLite::Statement( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1469 db, SQLITE_FROM_HERE, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1470 "SELECT series.publicId, instances.publicID FROM Lookup AS series " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1471 "INNER JOIN Resources instances ON series.internalId=instances.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1472 "GROUP BY series.publicId")); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1473 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1474 break; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1475 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1476 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1477 case ResourceType_Instance: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1478 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1479 statement.reset( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1480 new SQLite::Statement( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1481 db, SQLITE_FROM_HERE, "SELECT publicId, publicId FROM Lookup")); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1482 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1483 break; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1484 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1485 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1486 default: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1487 throw OrthancException(ErrorCode_InternalError); |
3027 | 1488 } |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1489 |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1490 assert(statement.get() != NULL); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1491 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1492 while (statement->Step()) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1493 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1494 resourcesId.push_back(statement->ColumnString(0)); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1495 instancesId.push_back(statement->ColumnString(1)); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1496 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1497 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1498 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1499 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1500 void SQLiteDatabaseWrapper::ApplyLookupResources(std::vector<std::string>& resourcesId, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1501 std::vector<std::string>& instancesId, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1502 const std::vector<DatabaseConstraint>& lookup, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1503 ResourceType queryLevel, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1504 size_t limit) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1505 { |
3031 | 1506 for (size_t i = 0; i < lookup.size(); i++) |
1507 { | |
1508 std::cout << i << ": " << lookup[i].GetTag() << " - " << EnumerationToString(lookup[i].GetLevel()); | |
1509 std::cout << std::endl; | |
1510 } | |
1511 | |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1512 assert(ResourceType_Patient < ResourceType_Study && |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1513 ResourceType_Study < ResourceType_Series && |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1514 ResourceType_Series < ResourceType_Instance); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1515 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1516 ResourceType upperLevel = queryLevel; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1517 ResourceType lowerLevel = queryLevel; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1518 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1519 for (size_t i = 0; i < lookup.size(); i++) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1520 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1521 ResourceType level = lookup[i].GetLevel(); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1522 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1523 if (level < upperLevel) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1524 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1525 upperLevel = level; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1526 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1527 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1528 if (level > lowerLevel) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1529 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1530 lowerLevel = level; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1531 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1532 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1533 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1534 printf("ICI 2: [%s] -> [%s]\n", EnumerationToString(upperLevel), EnumerationToString(lowerLevel)); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1535 |
3031 | 1536 { |
1537 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DROP TABLE IF EXISTS Lookup"); | |
1538 s.Run(); | |
1539 } | |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1540 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1541 std::string joins, comparisons; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1542 std::vector<std::string> parameters; |
3031 | 1543 |
1544 size_t count = 0; | |
1545 | |
1546 for (size_t i = 0; i < lookup.size(); i++) | |
1547 { | |
1548 std::string comparison; | |
1549 | |
1550 if (FormatComparison(comparison, lookup[i], count, parameters)) | |
1551 { | |
1552 std::string join; | |
1553 FormatJoin(join, lookup[i], count); | |
1554 joins += join; | |
1555 | |
1556 if (!comparison.empty()) | |
1557 { | |
1558 comparisons += " AND " + comparison; | |
1559 } | |
1560 | |
1561 count ++; | |
1562 } | |
1563 } | |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1564 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1565 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1566 std::string sql = ("CREATE TEMPORARY TABLE Lookup AS SELECT " + |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1567 FormatLevel(queryLevel) + ".publicId, " + |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1568 FormatLevel(queryLevel) + ".internalId" + |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1569 " FROM Resources AS " + FormatLevel(queryLevel)); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1570 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1571 for (int level = queryLevel - 1; level >= upperLevel; level--) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1572 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1573 sql += (" INNER JOIN Resources " + |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1574 FormatLevel(static_cast<ResourceType>(level)) + " ON " + |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1575 FormatLevel(static_cast<ResourceType>(level)) + ".internalId=" + |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1576 FormatLevel(static_cast<ResourceType>(level + 1)) + ".parentId"); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1577 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1578 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1579 for (int level = queryLevel + 1; level <= lowerLevel; level++) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1580 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1581 sql += (" INNER JOIN Resources " + |
3031 | 1582 FormatLevel(static_cast<ResourceType>(level)) + " ON " + |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1583 FormatLevel(static_cast<ResourceType>(level - 1)) + ".internalId=" + |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1584 FormatLevel(static_cast<ResourceType>(level)) + ".parentId"); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1585 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1586 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1587 sql += (joins + " WHERE " + FormatLevel(queryLevel) + ".resourceType = " + |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1588 boost::lexical_cast<std::string>(queryLevel) + comparisons); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1589 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1590 if (limit != 0) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1591 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1592 sql += " LIMIT " + boost::lexical_cast<std::string>(limit); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1593 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1594 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1595 printf("[%s]\n", sql.c_str()); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1596 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1597 SQLite::Statement s(db_, sql); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1598 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1599 for (size_t i = 0; i < parameters.size(); i++) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1600 { |
3027 | 1601 printf(" %lu = '%s'\n", i, parameters[i].c_str()); |
1602 s.BindString(i, parameters[i]); | |
1603 } | |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1604 |
3027 | 1605 s.Run(); |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1606 } |
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1607 |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1608 AnswerLookup(resourcesId, instancesId, db_, queryLevel); |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1609 } |
183 | 1610 } |