Mercurial > hg > orthanc
annotate OrthancServer/Database/SQLiteDatabaseWrapper.cpp @ 3553:1a2d0316e8ec
new tag
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 26 Oct 2019 19:37:52 +0200 |
parents | 4bbadcd03966 |
children | 94f4a18a79cc |
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 |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
5 * Copyright (C) 2017-2019 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 | |
3093
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3080
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 |
3093
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3080
diff
changeset
|
37 #include "../../Core/DicomFormat/DicomArray.h" |
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3080
diff
changeset
|
38 #include "../../Core/Logging.h" |
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3080
diff
changeset
|
39 #include "../../Core/SQLite/Transaction.h" |
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3080
diff
changeset
|
40 #include "../Search/ISqlLookupFormatter.h" |
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3080
diff
changeset
|
41 #include "../ServerToolbox.h" |
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3080
diff
changeset
|
42 |
2e1808b6146a
reorganization of folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3080
diff
changeset
|
43 #include <EmbeddedResources.h> |
183 | 44 |
45 #include <stdio.h> | |
1247 | 46 #include <boost/lexical_cast.hpp> |
183 | 47 |
48 namespace Orthanc | |
49 { | |
50 namespace Internals | |
51 { | |
52 class SignalFileDeleted : public SQLite::IScalarFunction | |
53 { | |
54 private: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1407
diff
changeset
|
55 IDatabaseListener& listener_; |
183 | 56 |
57 public: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1407
diff
changeset
|
58 SignalFileDeleted(IDatabaseListener& listener) : |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
59 listener_(listener) |
183 | 60 { |
61 } | |
62 | |
63 virtual const char* GetName() const | |
64 { | |
65 return "SignalFileDeleted"; | |
66 } | |
67 | |
68 virtual unsigned int GetCardinality() const | |
69 { | |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
70 return 7; |
183 | 71 } |
72 | |
73 virtual void Compute(SQLite::FunctionContext& context) | |
74 { | |
694
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
75 std::string uncompressedMD5, compressedMD5; |
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 if (!context.IsNullValue(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 uncompressedMD5 = context.GetStringValue(5); |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
80 } |
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 if (!context.IsNullValue(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 compressedMD5 = context.GetStringValue(6); |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
85 } |
72dc919a028c
upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
86 |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
87 FileInfo info(context.GetStringValue(0), |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
88 static_cast<FileContentType>(context.GetIntValue(1)), |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
89 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
|
90 uncompressedMD5, |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
91 static_cast<CompressionType>(context.GetIntValue(3)), |
693
01d8611c4a60
md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
92 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
|
93 compressedMD5); |
273
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
94 |
d384af918264
more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
268
diff
changeset
|
95 listener_.SignalFileDeleted(info); |
183 | 96 } |
97 }; | |
98 | |
1158 | 99 class SignalResourceDeleted : public SQLite::IScalarFunction |
100 { | |
101 private: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1407
diff
changeset
|
102 IDatabaseListener& listener_; |
1158 | 103 |
104 public: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1407
diff
changeset
|
105 SignalResourceDeleted(IDatabaseListener& listener) : |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
106 listener_(listener) |
1158 | 107 { |
108 } | |
109 | |
110 virtual const char* GetName() const | |
111 { | |
112 return "SignalResourceDeleted"; | |
113 } | |
114 | |
115 virtual unsigned int GetCardinality() const | |
116 { | |
117 return 2; | |
118 } | |
119 | |
120 virtual void Compute(SQLite::FunctionContext& context) | |
121 { | |
122 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1)); | |
1198 | 123 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0)); |
124 listener_.SignalChange(change); | |
1158 | 125 } |
126 }; | |
127 | |
183 | 128 class SignalRemainingAncestor : public SQLite::IScalarFunction |
129 { | |
130 private: | |
131 bool hasRemainingAncestor_; | |
132 std::string remainingPublicId_; | |
133 ResourceType remainingType_; | |
134 | |
135 public: | |
660 | 136 SignalRemainingAncestor() : |
137 hasRemainingAncestor_(false) | |
138 { | |
139 } | |
140 | |
183 | 141 void Reset() |
142 { | |
143 hasRemainingAncestor_ = false; | |
144 } | |
145 | |
146 virtual const char* GetName() const | |
147 { | |
148 return "SignalRemainingAncestor"; | |
149 } | |
150 | |
151 virtual unsigned int GetCardinality() const | |
152 { | |
153 return 2; | |
154 } | |
155 | |
156 virtual void Compute(SQLite::FunctionContext& context) | |
157 { | |
158 VLOG(1) << "There exists a remaining ancestor with public ID \"" | |
159 << context.GetStringValue(0) | |
160 << "\" of type " | |
161 << context.GetIntValue(1); | |
162 | |
163 if (!hasRemainingAncestor_ || | |
164 remainingType_ >= context.GetIntValue(1)) | |
165 { | |
166 hasRemainingAncestor_ = true; | |
167 remainingPublicId_ = context.GetStringValue(0); | |
168 remainingType_ = static_cast<ResourceType>(context.GetIntValue(1)); | |
169 } | |
170 } | |
171 | |
172 bool HasRemainingAncestor() const | |
173 { | |
174 return hasRemainingAncestor_; | |
175 } | |
176 | |
177 const std::string& GetRemainingAncestorId() const | |
178 { | |
179 assert(hasRemainingAncestor_); | |
180 return remainingPublicId_; | |
181 } | |
182 | |
183 ResourceType GetRemainingAncestorType() const | |
184 { | |
185 assert(hasRemainingAncestor_); | |
186 return remainingType_; | |
187 } | |
188 }; | |
189 } | |
190 | |
191 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
192 void SQLiteDatabaseWrapper::GetChangesInternal(std::list<ServerIndexChange>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
193 bool& done, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
194 SQLite::Statement& s, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
195 uint32_t maxResults) |
2773
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 target.clear(); |
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 while (target.size() < maxResults && s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
200 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
201 int64_t seq = s.ColumnInt64(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
202 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
203 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
204 const std::string& date = s.ColumnString(4); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
205 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
206 int64_t internalId = s.ColumnInt64(2); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
207 std::string publicId = GetPublicId(internalId); |
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 target.push_back(ServerIndexChange(seq, changeType, resourceType, publicId, date)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
210 } |
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 done = !(target.size() == maxResults && s.Step()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
213 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
214 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
215 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
216 void SQLiteDatabaseWrapper::GetExportedResourcesInternal(std::list<ExportedResource>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
217 bool& done, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
218 SQLite::Statement& s, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
219 uint32_t maxResults) |
2773
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 target.clear(); |
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 while (target.size() < maxResults && s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
224 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
225 int64_t seq = s.ColumnInt64(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
226 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
227 std::string publicId = s.ColumnString(2); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
228 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
229 ExportedResource resource(seq, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
230 resourceType, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
231 publicId, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
232 s.ColumnString(3), // modality |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
233 s.ColumnString(8), // date |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
234 s.ColumnString(4), // patient ID |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
235 s.ColumnString(5), // study instance UID |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
236 s.ColumnString(6), // series instance UID |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
237 s.ColumnString(7)); // sop instance UID |
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 target.push_back(resource); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
240 } |
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 done = !(target.size() == maxResults && s.Step()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
243 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
244 |
1241 | 245 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
246 void SQLiteDatabaseWrapper::GetChildren(std::list<std::string>& childrenPublicIds, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
247 int64_t id) |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
248 { |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
249 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE parentId=?"); |
585 | 250 s.BindInt64(0, id); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
251 |
1241 | 252 childrenPublicIds.clear(); |
193
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
253 while (s.Step()) |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
254 { |
1241 | 255 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
|
256 } |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
257 } |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
258 |
a1b9d1e1497b
failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
259 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
260 void SQLiteDatabaseWrapper::DeleteResource(int64_t id) |
183 | 261 { |
262 signalRemainingAncestor_->Reset(); | |
263 | |
264 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Resources WHERE internalId=?"); | |
585 | 265 s.BindInt64(0, id); |
183 | 266 s.Run(); |
267 | |
1247 | 268 if (signalRemainingAncestor_->HasRemainingAncestor() && |
269 listener_ != NULL) | |
183 | 270 { |
1247 | 271 listener_->SignalRemainingAncestor(signalRemainingAncestor_->GetRemainingAncestorType(), |
272 signalRemainingAncestor_->GetRemainingAncestorId()); | |
183 | 273 } |
274 } | |
275 | |
276 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
277 bool SQLiteDatabaseWrapper::GetParentPublicId(std::string& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
278 int64_t id) |
183 | 279 { |
280 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.publicId FROM Resources AS a, Resources AS b " | |
281 "WHERE a.internalId = b.parentId AND b.internalId = ?"); | |
585 | 282 s.BindInt64(0, id); |
183 | 283 |
284 if (s.Step()) | |
285 { | |
1301 | 286 target = s.ColumnString(0); |
183 | 287 return true; |
288 } | |
289 else | |
290 { | |
291 return false; | |
292 } | |
293 } | |
294 | |
295 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
296 int64_t SQLiteDatabaseWrapper::GetTableRecordCount(const std::string& table) |
183 | 297 { |
298 char buf[128]; | |
299 sprintf(buf, "SELECT COUNT(*) FROM %s", table.c_str()); | |
300 SQLite::Statement s(db_, buf); | |
301 | |
218 | 302 if (!s.Step()) |
303 { | |
304 throw OrthancException(ErrorCode_InternalError); | |
305 } | |
306 | |
183 | 307 int64_t c = s.ColumnInt(0); |
308 assert(!s.Step()); | |
309 | |
310 return c; | |
311 } | |
312 | |
313 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
314 SQLiteDatabaseWrapper::SQLiteDatabaseWrapper(const std::string& path) : |
1847 | 315 listener_(NULL), |
316 signalRemainingAncestor_(NULL), | |
317 version_(0) | |
183 | 318 { |
319 db_.Open(path); | |
320 } | |
321 | |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
322 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
323 SQLiteDatabaseWrapper::SQLiteDatabaseWrapper() : |
1847 | 324 listener_(NULL), |
325 signalRemainingAncestor_(NULL), | |
326 version_(0) | |
183 | 327 { |
328 db_.OpenInMemory(); | |
329 } | |
330 | |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
331 |
3116 | 332 int SQLiteDatabaseWrapper::GetGlobalIntegerProperty(GlobalProperty property, |
3121 | 333 int defaultValue) |
3116 | 334 { |
335 std::string tmp; | |
336 | |
337 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabasePatchLevel)) | |
338 { | |
339 return defaultValue; | |
340 } | |
341 else | |
342 { | |
343 try | |
344 { | |
345 return boost::lexical_cast<int>(tmp); | |
346 } | |
347 catch (boost::bad_lexical_cast&) | |
348 { | |
349 throw OrthancException(ErrorCode_ParameterOutOfRange, | |
350 "Global property " + boost::lexical_cast<std::string>(property) + | |
351 " should be an integer, but found: " + tmp); | |
352 } | |
353 } | |
354 } | |
355 | |
356 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
357 void SQLiteDatabaseWrapper::Open() |
183 | 358 { |
1717
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1712
diff
changeset
|
359 db_.Execute("PRAGMA ENCODING=\"UTF-8\";"); |
3926e6317a43
SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1712
diff
changeset
|
360 |
374 | 361 // Performance tuning of SQLite with PRAGMAs |
362 // http://www.sqlite.org/pragma.html | |
363 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;"); | |
364 db_.Execute("PRAGMA JOURNAL_MODE=WAL;"); | |
365 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); | |
366 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); | |
367 //db_.Execute("PRAGMA TEMP_STORE=memory"); | |
368 | |
3027 | 369 // Make "LIKE" case-sensitive in SQLite |
370 db_.Execute("PRAGMA case_sensitive_like = true;"); | |
371 | |
183 | 372 { |
3116 | 373 SQLite::Transaction t(db_); |
374 t.Begin(); | |
1239 | 375 |
3116 | 376 if (!db_.DoesTableExist("GlobalProperties")) |
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 { |
3116 | 378 LOG(INFO) << "Creating the database"; |
3018
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
379 std::string query; |
3116 | 380 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE); |
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 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
|
382 } |
3116 | 383 |
384 // Check the version of the database | |
385 std::string tmp; | |
386 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabaseSchemaVersion)) | |
387 { | |
388 tmp = "Unknown"; | |
389 } | |
390 | |
391 bool ok = false; | |
392 try | |
393 { | |
394 LOG(INFO) << "Version of the Orthanc database: " << tmp; | |
395 version_ = boost::lexical_cast<unsigned int>(tmp); | |
396 ok = true; | |
397 } | |
398 catch (boost::bad_lexical_cast&) | |
399 { | |
400 } | |
401 | |
402 if (!ok) | |
403 { | |
404 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion, | |
405 "Incompatible version of the Orthanc database: " + tmp); | |
406 } | |
407 | |
408 // New in Orthanc 1.5.1 | |
409 if (version_ == 6) | |
410 { | |
411 if (!LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast) || | |
412 tmp != "1") | |
413 { | |
414 LOG(INFO) << "Installing the SQLite triggers to track the size of the attachments"; | |
415 std::string query; | |
416 EmbeddedResources::GetFileResource(query, EmbeddedResources::INSTALL_TRACK_ATTACHMENTS_SIZE); | |
417 db_.Execute(query); | |
418 } | |
419 } | |
420 | |
421 t.Commit(); | |
3018
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
422 } |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
423 |
183 | 424 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor; |
425 db_.Register(signalRemainingAncestor_); | |
1247 | 426 } |
427 | |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
428 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
429 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
|
430 EmbeddedResources::FileResourceId script) |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
431 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
432 std::string upgrade; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
433 EmbeddedResources::GetFileResource(upgrade, script); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
434 db.BeginTransaction(); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
435 db.Execute(upgrade); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
436 db.CommitTransaction(); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
437 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
438 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
439 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
440 void SQLiteDatabaseWrapper::Upgrade(unsigned int targetVersion, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
441 IStorageArea& storageArea) |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
442 { |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
443 if (targetVersion != 6) |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
444 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
445 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
446 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
447 |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
448 // 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
|
449 // 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
|
450 if (version_ != 3 && |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
451 version_ != 4 && |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
452 version_ != 5 && |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
453 version_ != 6) |
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 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
456 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
457 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
458 if (version_ == 3) |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
459 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
460 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
|
461 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
|
462 version_ = 4; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
463 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
464 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
465 if (version_ == 4) |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
466 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
467 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
|
468 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
|
469 version_ = 5; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
470 } |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
471 |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
472 if (version_ == 5) |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
473 { |
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
474 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
|
475 // No change in the DB schema, the step from version 5 to 6 only |
1710 | 476 // consists in reconstructing the main DICOM tags information |
477 // (as more tags got included). | |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1665
diff
changeset
|
478 db_.BeginTransaction(); |
2120 | 479 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Patient); |
480 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Study); | |
481 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Series); | |
482 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Instance); | |
1710 | 483 db_.Execute("UPDATE GlobalProperties SET value=\"6\" WHERE property=" + |
484 boost::lexical_cast<std::string>(GlobalProperty_DatabaseSchemaVersion) + ";"); | |
1668
de1413733c97
reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1665
diff
changeset
|
485 db_.CommitTransaction(); |
1664
0c58f189782d
prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1615
diff
changeset
|
486 version_ = 6; |
1729 | 487 } |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
488 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
489 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
490 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
491 void SQLiteDatabaseWrapper::SetListener(IDatabaseListener& listener) |
1247 | 492 { |
493 listener_ = &listener; | |
494 db_.Register(new Internals::SignalFileDeleted(listener)); | |
495 db_.Register(new Internals::SignalResourceDeleted(listener)); | |
183 | 496 } |
238 | 497 |
413
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
498 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
499 void SQLiteDatabaseWrapper::ClearTable(const std::string& tableName) |
413
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
500 { |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
501 db_.Execute("DELETE FROM " + tableName); |
47d63c941902
clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
399
diff
changeset
|
502 } |
513 | 503 |
504 | |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
505 bool SQLiteDatabaseWrapper::LookupParent(int64_t& parentId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
506 int64_t resourceId) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
507 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
508 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
509 "SELECT parentId FROM Resources WHERE internalId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
510 s.BindInt64(0, resourceId); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
511 |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
512 if (!s.Step()) |
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 throw OrthancException(ErrorCode_UnknownResource); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
515 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
516 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
517 if (s.ColumnIsNull(0)) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
518 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
519 return false; |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
520 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
521 else |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
522 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
523 parentId = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
524 return true; |
1671
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 ResourceType SQLiteDatabaseWrapper::GetResourceType(int64_t resourceId) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
530 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
531 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
532 "SELECT resourceType FROM Resources WHERE internalId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
533 s.BindInt64(0, resourceId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
534 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
535 if (s.Step()) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
536 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
537 return static_cast<ResourceType>(s.ColumnInt(0)); |
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 else |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
540 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
541 throw OrthancException(ErrorCode_UnknownResource); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
542 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
543 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
544 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
545 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
546 std::string SQLiteDatabaseWrapper::GetPublicId(int64_t resourceId) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
547 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
548 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
549 "SELECT publicId FROM Resources WHERE internalId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
550 s.BindInt64(0, resourceId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
551 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
552 if (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
553 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
554 return s.ColumnString(0); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
555 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
556 else |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
557 { |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
558 throw OrthancException(ErrorCode_UnknownResource); |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
559 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
560 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
561 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
562 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
563 void SQLiteDatabaseWrapper::GetChanges(std::list<ServerIndexChange>& target /*out*/, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
564 bool& done /*out*/, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
565 int64_t since, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
566 uint32_t maxResults) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
567 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
568 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
|
569 s.BindInt64(0, since); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
570 s.BindInt(1, maxResults + 1); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
571 GetChangesInternal(target, done, s, maxResults); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
572 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
573 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
574 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
575 void SQLiteDatabaseWrapper::GetLastChange(std::list<ServerIndexChange>& target /*out*/) |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
576 { |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
577 bool done; // Ignored |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
578 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
|
579 GetChangesInternal(target, done, s, 1); |
1671
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
580 } |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
581 |
2f2e2ec17bc4
sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1670
diff
changeset
|
582 |
3019
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
583 class SQLiteDatabaseWrapper::Transaction : public IDatabaseWrapper::ITransaction |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
584 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
585 private: |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
586 SQLiteDatabaseWrapper& that_; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
587 std::auto_ptr<SQLite::Transaction> transaction_; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
588 int64_t initialDiskSize_; |
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 public: |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
591 Transaction(SQLiteDatabaseWrapper& that) : |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
592 that_(that), |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
593 transaction_(new SQLite::Transaction(that_.db_)) |
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 #if defined(NDEBUG) |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
596 // Release mode |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
597 initialDiskSize_ = 0; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
598 #else |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
599 // Debug mode |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
600 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
|
601 #endif |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
602 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
603 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
604 virtual void Begin() |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
605 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
606 transaction_->Begin(); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
607 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
608 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
609 virtual void Rollback() |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
610 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
611 transaction_->Rollback(); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
612 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
613 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
614 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
|
615 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
616 transaction_->Commit(); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
617 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
618 assert(initialDiskSize_ + fileSizeDelta >= 0 && |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
619 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
|
620 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
621 }; |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
622 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
623 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
624 IDatabaseWrapper::ITransaction* SQLiteDatabaseWrapper::StartTransaction() |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
625 { |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
626 return new Transaction(*this); |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
627 } |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
628 |
8336204d95dc
refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3018
diff
changeset
|
629 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
630 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
|
631 int64_t id) |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
632 { |
1301 | 633 target.clear(); |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
634 |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
635 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
|
636 s.BindInt64(0, id); |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
637 |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
638 while (s.Step()) |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
639 { |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
640 MetadataType key = static_cast<MetadataType>(s.ColumnInt(0)); |
1301 | 641 target[key] = s.ColumnString(1); |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
642 } |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
643 } |
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
644 |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
645 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
646 void SQLiteDatabaseWrapper::SetGlobalProperty(GlobalProperty property, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
647 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
648 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
649 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
|
650 s.BindInt(0, property); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
651 s.BindString(1, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
652 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
653 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
654 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
655 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
656 bool SQLiteDatabaseWrapper::LookupGlobalProperty(std::string& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
657 GlobalProperty property) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
658 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
659 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
660 "SELECT value FROM GlobalProperties WHERE property=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
661 s.BindInt(0, property); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
662 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
663 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
664 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
665 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
666 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
667 else |
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 target = s.ColumnString(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
670 return true; |
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 } |
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 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
675 int64_t SQLiteDatabaseWrapper::CreateResource(const std::string& publicId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
676 ResourceType type) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
677 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
678 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
|
679 s.BindInt(0, type); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
680 s.BindString(1, publicId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
681 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
682 return db_.GetLastInsertRowId(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
683 } |
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 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
686 bool SQLiteDatabaseWrapper::LookupResource(int64_t& id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
687 ResourceType& type, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
688 const std::string& publicId) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
689 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
690 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
691 "SELECT internalId, resourceType FROM Resources WHERE publicId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
692 s.BindString(0, publicId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
693 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
694 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
695 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
696 return false; |
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 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
699 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
700 id = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
701 type = static_cast<ResourceType>(s.ColumnInt(1)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
702 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
703 // 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
|
704 assert(!s.Step()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
705 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
706 return true; |
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 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
709 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
710 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
711 void SQLiteDatabaseWrapper::AttachChild(int64_t parent, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
712 int64_t child) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
713 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
714 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
|
715 s.BindInt64(0, parent); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
716 s.BindInt64(1, child); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
717 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
718 } |
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 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
721 void SQLiteDatabaseWrapper::SetMetadata(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
722 MetadataType type, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
723 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
724 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
725 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
|
726 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
727 s.BindInt(1, type); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
728 s.BindString(2, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
729 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
730 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
731 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
732 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
733 void SQLiteDatabaseWrapper::DeleteMetadata(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
734 MetadataType type) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
735 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
736 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
|
737 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
738 s.BindInt(1, type); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
739 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
740 } |
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 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
743 bool SQLiteDatabaseWrapper::LookupMetadata(std::string& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
744 int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
745 MetadataType type) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
746 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
747 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
748 "SELECT value FROM Metadata WHERE id=? AND type=?"); |
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, type); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
751 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
752 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
753 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
754 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
755 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
756 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
757 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
758 target = s.ColumnString(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
759 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
760 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
761 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
762 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
763 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
764 void SQLiteDatabaseWrapper::AddAttachment(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
765 const FileInfo& attachment) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
766 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
767 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
|
768 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
769 s.BindInt(1, attachment.GetContentType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
770 s.BindString(2, attachment.GetUuid()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
771 s.BindInt64(3, attachment.GetCompressedSize()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
772 s.BindInt64(4, attachment.GetUncompressedSize()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
773 s.BindInt(5, attachment.GetCompressionType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
774 s.BindString(6, attachment.GetUncompressedMD5()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
775 s.BindString(7, attachment.GetCompressedMD5()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
776 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
777 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
778 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
779 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
780 void SQLiteDatabaseWrapper::DeleteAttachment(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
781 FileContentType attachment) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
782 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
783 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
|
784 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
785 s.BindInt(1, attachment); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
786 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
787 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
788 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
789 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
790 void SQLiteDatabaseWrapper::ListAvailableAttachments(std::list<FileContentType>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
791 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
792 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
793 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
794 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
795 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
796 "SELECT fileType FROM AttachedFiles WHERE id=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
797 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
798 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
799 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
800 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
801 target.push_back(static_cast<FileContentType>(s.ColumnInt(0))); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
802 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
803 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
804 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
805 bool SQLiteDatabaseWrapper::LookupAttachment(FileInfo& attachment, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
806 int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
807 FileContentType contentType) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
808 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
809 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
810 "SELECT uuid, uncompressedSize, compressionType, compressedSize, " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
811 "uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
812 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
813 s.BindInt(1, contentType); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
814 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
815 if (!s.Step()) |
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 return false; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
818 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
819 else |
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 attachment = FileInfo(s.ColumnString(0), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
822 contentType, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
823 s.ColumnInt64(1), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
824 s.ColumnString(4), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
825 static_cast<CompressionType>(s.ColumnInt(2)), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
826 s.ColumnInt64(3), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
827 s.ColumnString(5)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
828 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
829 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
830 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
831 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
832 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
833 void SQLiteDatabaseWrapper::ClearMainDicomTags(int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
834 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
835 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
836 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
|
837 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
838 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
839 } |
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 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
|
843 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
844 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
845 } |
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 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
848 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
849 void SQLiteDatabaseWrapper::SetMainDicomTag(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
850 const DicomTag& tag, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
851 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
852 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
853 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
|
854 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
855 s.BindInt(1, tag.GetGroup()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
856 s.BindInt(2, tag.GetElement()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
857 s.BindString(3, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
858 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
859 } |
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 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
862 void SQLiteDatabaseWrapper::SetIdentifierTag(int64_t id, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
863 const DicomTag& tag, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
864 const std::string& value) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
865 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
866 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
|
867 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
868 s.BindInt(1, tag.GetGroup()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
869 s.BindInt(2, tag.GetElement()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
870 s.BindString(3, value); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
871 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
872 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
873 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
874 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
875 void SQLiteDatabaseWrapper::GetMainDicomTags(DicomMap& map, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
876 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
877 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
878 map.Clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
879 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
880 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
|
881 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
882 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
883 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
884 map.SetValue(s.ColumnInt(1), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
885 s.ColumnInt(2), |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
886 s.ColumnString(3), false); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
887 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
888 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
889 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
890 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
891 void SQLiteDatabaseWrapper::GetChildrenPublicId(std::list<std::string>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
892 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
893 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
894 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
|
895 "WHERE a.parentId = b.internalId AND b.internalId = ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
896 s.BindInt64(0, id); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
897 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
898 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
899 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
900 while (s.Step()) |
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 target.push_back(s.ColumnString(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
903 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
904 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
905 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
906 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
907 void SQLiteDatabaseWrapper::GetChildrenInternalId(std::list<int64_t>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
908 int64_t id) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
909 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
910 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
|
911 "WHERE a.parentId = b.internalId AND b.internalId = ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
912 s.BindInt64(0, id); |
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 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
915 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
916 while (s.Step()) |
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 target.push_back(s.ColumnInt64(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
919 } |
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 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
922 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
923 void SQLiteDatabaseWrapper::LogChange(int64_t internalId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
924 const ServerIndexChange& change) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
925 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
926 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
|
927 s.BindInt(0, change.GetChangeType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
928 s.BindInt64(1, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
929 s.BindInt(2, change.GetResourceType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
930 s.BindString(3, change.GetDate()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
931 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
932 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
933 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
934 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
935 void SQLiteDatabaseWrapper::LogExportedResource(const ExportedResource& resource) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
936 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
937 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
938 "INSERT INTO ExportedResources VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
939 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
940 s.BindInt(0, resource.GetResourceType()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
941 s.BindString(1, resource.GetPublicId()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
942 s.BindString(2, resource.GetModality()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
943 s.BindString(3, resource.GetPatientId()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
944 s.BindString(4, resource.GetStudyInstanceUid()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
945 s.BindString(5, resource.GetSeriesInstanceUid()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
946 s.BindString(6, resource.GetSopInstanceUid()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
947 s.BindString(7, resource.GetDate()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
948 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
949 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
950 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
951 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
952 void SQLiteDatabaseWrapper::GetExportedResources(std::list<ExportedResource>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
953 bool& done, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
954 int64_t since, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
955 uint32_t maxResults) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
956 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
957 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
958 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
959 s.BindInt64(0, since); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
960 s.BindInt(1, maxResults + 1); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
961 GetExportedResourcesInternal(target, done, s, maxResults); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
962 } |
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 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
965 void SQLiteDatabaseWrapper::GetLastExportedResource(std::list<ExportedResource>& target) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
966 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
967 bool done; // Ignored |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
968 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
969 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
970 GetExportedResourcesInternal(target, done, s, 1); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
971 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
972 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
973 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
974 uint64_t SQLiteDatabaseWrapper::GetTotalCompressedSize() |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
975 { |
3018
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
976 // 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
|
977 // 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
|
978 |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
979 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
|
980 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
981 return static_cast<uint64_t>(s.ColumnInt64(0)); |
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 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
984 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
985 uint64_t SQLiteDatabaseWrapper::GetTotalUncompressedSize() |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
986 { |
3018
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
987 // 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
|
988 // 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
|
989 |
e3b5c07146a3
speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3017
diff
changeset
|
990 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
|
991 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
992 return static_cast<uint64_t>(s.ColumnInt64(0)); |
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 uint64_t SQLiteDatabaseWrapper::GetResourceCount(ResourceType resourceType) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
997 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
998 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
999 "SELECT COUNT(*) 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 if (!s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1003 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1004 return 0; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1005 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1006 else |
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 int64_t c = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1009 assert(!s.Step()); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1010 return c; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1011 } |
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 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1014 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1015 void SQLiteDatabaseWrapper::GetAllPublicIds(std::list<std::string>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1016 ResourceType resourceType) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1017 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1018 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
|
1019 s.BindInt(0, resourceType); |
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 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1022 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1023 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1024 target.push_back(s.ColumnString(0)); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1025 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1026 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1027 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1028 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1029 void SQLiteDatabaseWrapper::GetAllPublicIds(std::list<std::string>& target, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1030 ResourceType resourceType, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1031 size_t since, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1032 size_t limit) |
2773
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 if (limit == 0) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1035 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1036 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1037 return; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1038 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1039 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1040 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1041 "SELECT publicId FROM Resources WHERE " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1042 "resourceType=? LIMIT ? OFFSET ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1043 s.BindInt(0, resourceType); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1044 s.BindInt64(1, limit); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1045 s.BindInt64(2, since); |
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 target.clear(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1048 while (s.Step()) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1049 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1050 target.push_back(s.ColumnString(0)); |
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 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1053 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1054 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1055 bool SQLiteDatabaseWrapper::SelectPatientToRecycle(int64_t& internalId) |
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1058 "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
|
1059 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1060 if (!s.Step()) |
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 // No patient remaining or all the patients are protected |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1063 return false; |
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 else |
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 internalId = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1068 return true; |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1069 } |
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 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1072 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1073 bool SQLiteDatabaseWrapper::SelectPatientToRecycle(int64_t& internalId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1074 int64_t patientIdToAvoid) |
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1077 "SELECT patientId FROM PatientRecyclingOrder " |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1078 "WHERE patientId != ? ORDER BY seq ASC LIMIT 1"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1079 s.BindInt64(0, patientIdToAvoid); |
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 if (!s.Step()) |
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 // No patient remaining or all the patients are protected |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1084 return false; |
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 else |
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 internalId = s.ColumnInt(0); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1089 return true; |
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 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1092 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1093 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1094 bool SQLiteDatabaseWrapper::IsProtectedPatient(int64_t internalId) |
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1097 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1098 s.BindInt64(0, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1099 return !s.Step(); |
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 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1102 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1103 void SQLiteDatabaseWrapper::SetProtectedPatient(int64_t internalId, |
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1104 bool isProtected) |
2773
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1105 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1106 if (isProtected) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1107 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1108 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
|
1109 s.BindInt64(0, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1110 s.Run(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1111 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1112 else if (IsProtectedPatient(internalId)) |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1113 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1114 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
|
1115 s.BindInt64(0, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1116 s.Run(); |
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 else |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1119 { |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1120 // Nothing to do: The patient is already unprotected |
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 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1123 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1124 |
3017
517fc4767ae0
renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2955
diff
changeset
|
1125 bool SQLiteDatabaseWrapper::IsExistingResource(int64_t internalId) |
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1128 "SELECT * FROM Resources WHERE internalId=?"); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1129 s.BindInt64(0, internalId); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1130 return s.Step(); |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1131 } |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1132 |
bb63068844ae
moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1133 |
3020
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
1134 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
|
1135 { |
d207f6ac1f86
tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3019
diff
changeset
|
1136 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
|
1137 } |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1138 |
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1139 |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1140 |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1141 class SQLiteDatabaseWrapper::LookupFormatter : public ISqlLookupFormatter |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1142 { |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1143 private: |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1144 std::list<std::string> values_; |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1145 |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1146 public: |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1147 virtual std::string GenerateParameter(const std::string& value) |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1148 { |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1149 values_.push_back(value); |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1150 return "?"; |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1151 } |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1152 |
3078 | 1153 virtual std::string FormatResourceType(ResourceType level) |
1154 { | |
1155 return boost::lexical_cast<std::string>(level); | |
1156 } | |
1157 | |
3079
65e2bfa953ef
ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3078
diff
changeset
|
1158 virtual std::string FormatWildcardEscape() |
65e2bfa953ef
ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3078
diff
changeset
|
1159 { |
65e2bfa953ef
ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3078
diff
changeset
|
1160 return "ESCAPE '\\'"; |
65e2bfa953ef
ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3078
diff
changeset
|
1161 } |
65e2bfa953ef
ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3078
diff
changeset
|
1162 |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1163 void Bind(SQLite::Statement& statement) const |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1164 { |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1165 size_t pos = 0; |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1166 |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1167 for (std::list<std::string>::const_iterator |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1168 it = values_.begin(); it != values_.end(); ++it, pos++) |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1169 { |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1170 statement.BindString(pos, *it); |
3029
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1171 } |
ea653ec47f31
new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3027
diff
changeset
|
1172 } |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1173 }; |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1174 |
3031 | 1175 |
3075
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1176 static void AnswerLookup(std::list<std::string>& resourcesId, |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1177 std::list<std::string>& instancesId, |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1178 SQLite::Connection& db, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1179 ResourceType level) |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1180 { |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1181 resourcesId.clear(); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1182 instancesId.clear(); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1183 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1184 std::auto_ptr<SQLite::Statement> statement; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1185 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1186 switch (level) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1187 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1188 case ResourceType_Patient: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1189 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1190 statement.reset( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1191 new SQLite::Statement( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1192 db, SQLITE_FROM_HERE, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1193 "SELECT patients.publicId, instances.publicID FROM Lookup AS patients " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1194 "INNER JOIN Resources studies ON patients.internalId=studies.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1195 "INNER JOIN Resources series ON studies.internalId=series.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1196 "INNER JOIN Resources instances ON series.internalId=instances.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1197 "GROUP BY patients.publicId")); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1198 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1199 break; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1200 } |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1201 |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1202 case ResourceType_Study: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1203 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1204 statement.reset( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1205 new SQLite::Statement( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1206 db, SQLITE_FROM_HERE, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1207 "SELECT studies.publicId, instances.publicID FROM Lookup AS studies " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1208 "INNER JOIN Resources series ON studies.internalId=series.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1209 "INNER JOIN Resources instances ON series.internalId=instances.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1210 "GROUP BY studies.publicId")); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1211 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1212 break; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1213 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1214 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1215 case ResourceType_Series: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1216 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1217 statement.reset( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1218 new SQLite::Statement( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1219 db, SQLITE_FROM_HERE, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1220 "SELECT series.publicId, instances.publicID FROM Lookup AS series " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1221 "INNER JOIN Resources instances ON series.internalId=instances.parentId " |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1222 "GROUP BY series.publicId")); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1223 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1224 break; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1225 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1226 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1227 case ResourceType_Instance: |
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 statement.reset( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1230 new SQLite::Statement( |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1231 db, SQLITE_FROM_HERE, "SELECT publicId, publicId FROM Lookup")); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1232 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1233 break; |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1234 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1235 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1236 default: |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1237 throw OrthancException(ErrorCode_InternalError); |
3027 | 1238 } |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1239 |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1240 assert(statement.get() != NULL); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1241 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1242 while (statement->Step()) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1243 { |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1244 resourcesId.push_back(statement->ColumnString(0)); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1245 instancesId.push_back(statement->ColumnString(1)); |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1246 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1247 } |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1248 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1249 |
3075
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1250 void SQLiteDatabaseWrapper::ApplyLookupResources(std::list<std::string>& resourcesId, |
ead8576a02ef
IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1251 std::list<std::string>* instancesId, |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1252 const std::vector<DatabaseConstraint>& lookup, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1253 ResourceType queryLevel, |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1254 size_t limit) |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1255 { |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1256 LookupFormatter formatter; |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1257 |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1258 std::string sql; |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1259 LookupFormatter::Apply(sql, formatter, lookup, queryLevel, limit); |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1260 |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1261 sql = "CREATE TEMPORARY TABLE Lookup AS " + sql; |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1262 |
3031 | 1263 { |
1264 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DROP TABLE IF EXISTS Lookup"); | |
1265 s.Run(); | |
1266 } | |
3030
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1267 |
25afa7b8cb51
SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3029
diff
changeset
|
1268 { |
3058
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1269 SQLite::Statement statement(db_, sql); |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1270 formatter.Bind(statement); |
6faf575ba9cc
refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3056
diff
changeset
|
1271 statement.Run(); |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1272 } |
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1273 |
3036
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1274 if (instancesId != NULL) |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1275 { |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1276 AnswerLookup(resourcesId, *instancesId, db_, queryLevel); |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1277 } |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1278 else |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1279 { |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1280 resourcesId.clear(); |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1281 |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1282 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Lookup"); |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1283 |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1284 while (s.Step()) |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1285 { |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1286 resourcesId.push_back(s.ColumnString(0)); |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1287 } |
8fd203510d8b
moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3033
diff
changeset
|
1288 } |
3025
039a9d262d64
preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3020
diff
changeset
|
1289 } |
3105
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1290 |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1291 |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1292 int64_t SQLiteDatabaseWrapper::GetLastChangeIndex() |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1293 { |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1294 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1295 "SELECT seq FROM sqlite_sequence WHERE name='Changes'"); |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1296 |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1297 if (s.Step()) |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1298 { |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1299 int64_t c = s.ColumnInt(0); |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1300 assert(!s.Step()); |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1301 return c; |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1302 } |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1303 else |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1304 { |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1305 // No change has been recorded so far in the database |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1306 return 0; |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1307 } |
2e1711f80f74
More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3093
diff
changeset
|
1308 } |
3121 | 1309 |
1310 | |
3124
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1311 void SQLiteDatabaseWrapper::TagMostRecentPatient(int64_t patient) |
3121 | 1312 { |
3124
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1313 { |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1314 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1315 "DELETE FROM PatientRecyclingOrder WHERE patientId=?"); |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1316 s.BindInt64(0, patient); |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1317 s.Run(); |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1318 |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1319 assert(db_.GetLastChangeCount() == 0 || |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1320 db_.GetLastChangeCount() == 1); |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1321 |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1322 if (db_.GetLastChangeCount() == 0) |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1323 { |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1324 // The patient was protected, there was nothing to delete from the recycling order |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1325 return; |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1326 } |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1327 } |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1328 |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1329 { |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1330 SQLite::Statement s(db_, SQLITE_FROM_HERE, |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1331 "INSERT INTO PatientRecyclingOrder VALUES(NULL, ?)"); |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1332 s.BindInt64(0, patient); |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1333 s.Run(); |
c0d7aee8c3f8
Fix issue #58 (Patient recycling order should be defined by their received last instance)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3121
diff
changeset
|
1334 } |
3121 | 1335 } |
183 | 1336 } |