annotate OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp @ 4384:7e0d015ad109

new configuration options IngestTranscodingOfUncompressed and IngestTranscodingOfCompressed
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Dec 2020 11:13:00 +0100
parents c7bd2f21ccc3
children d9473bd5ed43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
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
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3187
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
37 #include "../../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
38 #include "../../../OrthancFramework/Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
39 #include "../../../OrthancFramework/Sources/SQLite/Transaction.h"
3093
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
4032
058b5ade8acd renaming embedded resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4031
diff changeset
43 #include <OrthancServerResources.h>
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 #include <stdio.h>
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
46 #include <boost/lexical_cast.hpp>
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 namespace Orthanc
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 namespace Internals
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 class SignalFileDeleted : public SQLite::IScalarFunction
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 private:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
55 IDatabaseListener& listener_;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 virtual const char* GetName() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 return "SignalFileDeleted";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 virtual unsigned int GetCardinality() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
70 return 7;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 virtual void Compute(SQLite::FunctionContext& context)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 };
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
99 class SignalResourceDeleted : public SQLite::IScalarFunction
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
100 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
101 private:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
102 IDatabaseListener& listener_;
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
103
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
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
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
107 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
108 }
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
109
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
110 virtual const char* GetName() const
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
111 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
112 return "SignalResourceDeleted";
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
113 }
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
114
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
115 virtual unsigned int GetCardinality() const
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
116 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
117 return 2;
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
118 }
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
119
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
120 virtual void Compute(SQLite::FunctionContext& context)
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
121 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
122 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1));
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
123 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
124 listener_.SignalChange(change);
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
125 }
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
126 };
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
127
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 class SignalRemainingAncestor : public SQLite::IScalarFunction
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 private:
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 bool hasRemainingAncestor_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 std::string remainingPublicId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 ResourceType remainingType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 public:
660
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
136 SignalRemainingAncestor() :
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
137 hasRemainingAncestor_(false)
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
138 {
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
139 }
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
140
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 void Reset()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 hasRemainingAncestor_ = false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 virtual const char* GetName() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 return "SignalRemainingAncestor";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 virtual unsigned int GetCardinality() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 return 2;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 virtual void Compute(SQLite::FunctionContext& context)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
158 CLOG(TRACE, SQLITE) << "There exists a remaining ancestor with public ID \""
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
159 << context.GetStringValue(0) << "\" of type "
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
160 << context.GetIntValue(1);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 if (!hasRemainingAncestor_ ||
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 remainingType_ >= context.GetIntValue(1))
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 hasRemainingAncestor_ = true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 remainingPublicId_ = context.GetStringValue(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 remainingType_ = static_cast<ResourceType>(context.GetIntValue(1));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 bool HasRemainingAncestor() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 return hasRemainingAncestor_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 const std::string& GetRemainingAncestorId() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 assert(hasRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 return remainingPublicId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 ResourceType GetRemainingAncestorType() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 assert(hasRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return remainingType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 };
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
191 void SQLiteDatabaseWrapper::GetChangesInternal(std::list<ServerIndexChange>& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
192 bool& done,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
193 SQLite::Statement& s,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
194 uint32_t maxResults)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
195 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
196 target.clear();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
197
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
198 while (target.size() < maxResults && s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
199 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
200 int64_t seq = s.ColumnInt64(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
201 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
202 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
203 const std::string& date = s.ColumnString(4);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
204
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
205 int64_t internalId = s.ColumnInt64(2);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
206 std::string publicId = GetPublicId(internalId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
207
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
208 target.push_back(ServerIndexChange(seq, changeType, resourceType, publicId, date));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
209 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
210
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
211 done = !(target.size() == maxResults && s.Step());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
212 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
213
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
214
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
215 void SQLiteDatabaseWrapper::GetExportedResourcesInternal(std::list<ExportedResource>& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
216 bool& done,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
217 SQLite::Statement& s,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
218 uint32_t maxResults)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
219 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
220 target.clear();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
221
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
222 while (target.size() < maxResults && s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
223 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
224 int64_t seq = s.ColumnInt64(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
225 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
226 std::string publicId = s.ColumnString(2);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
227
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
228 ExportedResource resource(seq,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
229 resourceType,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
230 publicId,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
231 s.ColumnString(3), // modality
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
232 s.ColumnString(8), // date
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
233 s.ColumnString(4), // patient ID
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
234 s.ColumnString(5), // study instance UID
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
235 s.ColumnString(6), // series instance UID
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
236 s.ColumnString(7)); // sop instance UID
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
237
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
238 target.push_back(resource);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
239 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
240
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
241 done = !(target.size() == maxResults && s.Step());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
242 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
243
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
244
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
245 void SQLiteDatabaseWrapper::GetChildren(std::list<std::string>& childrenPublicIds,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
246 int64_t id)
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
247 {
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
248 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE parentId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
249 s.BindInt64(0, id);
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
250
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
251 childrenPublicIds.clear();
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
252 while (s.Step())
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
253 {
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
254 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
255 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
256 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
257
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
258
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
259 void SQLiteDatabaseWrapper::DeleteResource(int64_t id)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 signalRemainingAncestor_->Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
264 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
267 if (signalRemainingAncestor_->HasRemainingAncestor() &&
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
268 listener_ != NULL)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
270 listener_->SignalRemainingAncestor(signalRemainingAncestor_->GetRemainingAncestorType(),
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
271 signalRemainingAncestor_->GetRemainingAncestorId());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
276 bool SQLiteDatabaseWrapper::GetParentPublicId(std::string& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
277 int64_t id)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.publicId FROM Resources AS a, Resources AS b "
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 "WHERE a.internalId = b.parentId AND b.internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
281 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 if (s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
285 target = s.ColumnString(0);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
295 int64_t SQLiteDatabaseWrapper::GetTableRecordCount(const std::string& table)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 {
3809
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
297 /**
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
298 * "Generally one cannot use SQL parameters/placeholders for
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
299 * database identifiers (tables, columns, views, schemas, etc.) or
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
300 * database functions (e.g., CURRENT_DATE), but instead only for
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
301 * binding literal values." => To avoid any SQL injection, we
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
302 * check that the "table" parameter has only alphabetic
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
303 * characters.
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
304 * https://stackoverflow.com/a/1274764/881731
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
305 **/
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
306 for (size_t i = 0; i < table.size(); i++)
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
307 {
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
308 if (!isalpha(table[i]))
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
309 {
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
310 throw OrthancException(ErrorCode_ParameterOutOfRange);
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
311 }
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
312 }
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
3809
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
314 // Don't use "SQLITE_FROM_HERE", otherwise "table" would be cached
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
315 SQLite::Statement s(db_, "SELECT COUNT(*) FROM " + table);
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
316
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
317 if (s.Step())
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
318 {
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
319 int64_t c = s.ColumnInt(0);
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
320 assert(!s.Step());
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
321 return c;
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
322 }
2bf30ef727e3 enforcing SQLiteDatabaseWrapper::GetTableRecordCount() against SQL injection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
323 else
218
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
324 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
325 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
326 }
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
330 SQLiteDatabaseWrapper::SQLiteDatabaseWrapper(const std::string& path) :
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
331 listener_(NULL),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
332 signalRemainingAncestor_(NULL),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
333 version_(0)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 db_.Open(path);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
338
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
339 SQLiteDatabaseWrapper::SQLiteDatabaseWrapper() :
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
340 listener_(NULL),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
341 signalRemainingAncestor_(NULL),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
342 version_(0)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 db_.OpenInMemory();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
347
3116
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
348 int SQLiteDatabaseWrapper::GetGlobalIntegerProperty(GlobalProperty property,
3121
f86ebf971a72 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3116
diff changeset
349 int defaultValue)
3116
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
350 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
351 std::string tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
352
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
353 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabasePatchLevel))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
354 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
355 return defaultValue;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
356 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
357 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
358 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
359 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
360 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
361 return boost::lexical_cast<int>(tmp);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
362 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
363 catch (boost::bad_lexical_cast&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
364 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
365 throw OrthancException(ErrorCode_ParameterOutOfRange,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
366 "Global property " + boost::lexical_cast<std::string>(property) +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
367 " should be an integer, but found: " + tmp);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
368 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
369 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
370 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
371
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
372
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
373 void SQLiteDatabaseWrapper::Open()
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 {
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1712
diff changeset
375 db_.Execute("PRAGMA ENCODING=\"UTF-8\";");
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1712
diff changeset
376
374
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
377 // Performance tuning of SQLite with PRAGMAs
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
378 // http://www.sqlite.org/pragma.html
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
379 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
380 db_.Execute("PRAGMA JOURNAL_MODE=WAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
381 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
382 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
383 //db_.Execute("PRAGMA TEMP_STORE=memory");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
384
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
385 // Make "LIKE" case-sensitive in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
386 db_.Execute("PRAGMA case_sensitive_like = true;");
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
387
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
3116
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
389 SQLite::Transaction t(db_);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
390 t.Begin();
1239
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
391
3116
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
392 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
393 {
3116
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
394 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
395 std::string query;
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4030
diff changeset
396 ServerResources::GetFileResource(query, ServerResources::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
397 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
398 }
3116
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
399
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
400 // Check the version of the database
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
401 std::string tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
402 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabaseSchemaVersion))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
403 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
404 tmp = "Unknown";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
405 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
406
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
407 bool ok = false;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
408 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
409 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
410 LOG(INFO) << "Version of the Orthanc database: " << tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
411 version_ = boost::lexical_cast<unsigned int>(tmp);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
412 ok = true;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
413 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
414 catch (boost::bad_lexical_cast&)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
415 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
416 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
417
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
418 if (!ok)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
419 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
420 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
421 "Incompatible version of the Orthanc database: " + tmp);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
422 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
423
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
424 // New in Orthanc 1.5.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
425 if (version_ == 6)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
426 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
427 if (!LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
428 tmp != "1")
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
429 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
430 LOG(INFO) << "Installing the SQLite triggers to track the size of the attachments";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
431 std::string query;
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4030
diff changeset
432 ServerResources::GetFileResource(query, ServerResources::INSTALL_TRACK_ATTACHMENTS_SIZE);
3116
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
433 db_.Execute(query);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
434 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
435 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
436
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3105
diff changeset
437 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
438 }
e3b5c07146a3 speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3017
diff changeset
439
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 db_.Register(signalRemainingAncestor_);
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
442 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
443
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 static void ExecuteUpgradeScript(SQLite::Connection& db,
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4030
diff changeset
446 ServerResources::FileResourceId script)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
447 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
448 std::string upgrade;
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4030
diff changeset
449 ServerResources::GetFileResource(upgrade, script);
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
450 db.BeginTransaction();
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
451 db.Execute(upgrade);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
452 db.CommitTransaction();
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
453 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
456 void SQLiteDatabaseWrapper::Upgrade(unsigned int targetVersion,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
457 IStorageArea& storageArea)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
458 {
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
459 if (targetVersion != 6)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
460 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
461 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
462 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
463
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
464 // 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
465 // 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
466 if (version_ != 3 &&
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
467 version_ != 4 &&
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
468 version_ != 5 &&
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
469 version_ != 6)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
470 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
471 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
472 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
473
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
474 if (version_ == 3)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
475 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
476 LOG(WARNING) << "Upgrading database version from 3 to 4";
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4030
diff changeset
477 ExecuteUpgradeScript(db_, ServerResources::UPGRADE_DATABASE_3_TO_4);
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
478 version_ = 4;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
479 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
480
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
481 if (version_ == 4)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
482 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
483 LOG(WARNING) << "Upgrading database version from 4 to 5";
4031
e3b3af80732d ServerResources, and moving EmbeddedResourceHttpHandler from Core to OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4030
diff changeset
484 ExecuteUpgradeScript(db_, ServerResources::UPGRADE_DATABASE_4_TO_5);
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
485 version_ = 5;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
486 }
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
487
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
488 if (version_ == 5)
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
489 {
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
490 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
491 // No change in the DB schema, the step from version 5 to 6 only
1710
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
492 // consists in reconstructing the main DICOM tags information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
493 // (as more tags got included).
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
494 db_.BeginTransaction();
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
495 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Patient);
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
496 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Study);
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
497 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Series);
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
498 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Instance);
1710
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
499 db_.Execute("UPDATE GlobalProperties SET value=\"6\" WHERE property=" +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
500 boost::lexical_cast<std::string>(GlobalProperty_DatabaseSchemaVersion) + ";");
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
501 db_.CommitTransaction();
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
502 version_ = 6;
1729
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
503 }
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
504 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
505
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
506
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
507 void SQLiteDatabaseWrapper::SetListener(IDatabaseListener& listener)
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
508 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
509 listener_ = &listener;
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
510 db_.Register(new Internals::SignalFileDeleted(listener));
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
511 db_.Register(new Internals::SignalResourceDeleted(listener));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 }
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
513
413
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
514
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
515 void SQLiteDatabaseWrapper::ClearTable(const std::string& tableName)
413
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
516 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
517 db_.Execute("DELETE FROM " + tableName);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
518 }
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
519
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
520
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
521 bool SQLiteDatabaseWrapper::LookupParent(int64_t& parentId,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
522 int64_t resourceId)
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
523 {
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
524 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
525 "SELECT parentId FROM Resources WHERE internalId=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
526 s.BindInt64(0, resourceId);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
527
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
528 if (!s.Step())
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
529 {
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
530 throw OrthancException(ErrorCode_UnknownResource);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
531 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
532
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
533 if (s.ColumnIsNull(0))
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 return false;
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
536 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
537 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
538 {
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
539 parentId = s.ColumnInt(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
540 return true;
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
541 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
545 ResourceType SQLiteDatabaseWrapper::GetResourceType(int64_t resourceId)
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
546 {
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
547 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
548 "SELECT resourceType FROM Resources WHERE internalId=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
549 s.BindInt64(0, resourceId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
550
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
551 if (s.Step())
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
552 {
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
553 return static_cast<ResourceType>(s.ColumnInt(0));
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
554 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
555 else
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
556 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
557 throw OrthancException(ErrorCode_UnknownResource);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
558 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
562 std::string SQLiteDatabaseWrapper::GetPublicId(int64_t resourceId)
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
563 {
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
564 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
565 "SELECT publicId FROM Resources WHERE internalId=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
566 s.BindInt64(0, resourceId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
567
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
568 if (s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
569 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
570 return s.ColumnString(0);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
571 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
572 else
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 throw OrthancException(ErrorCode_UnknownResource);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
575 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
576 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
577
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
578
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
579 void SQLiteDatabaseWrapper::GetChanges(std::list<ServerIndexChange>& target /*out*/,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
580 bool& done /*out*/,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
581 int64_t since,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
582 uint32_t maxResults)
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
583 {
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
584 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
585 s.BindInt64(0, since);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
586 s.BindInt(1, maxResults + 1);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
587 GetChangesInternal(target, done, s, maxResults);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
588 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
589
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
590
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
591 void SQLiteDatabaseWrapper::GetLastChange(std::list<ServerIndexChange>& target /*out*/)
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
592 {
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
593 bool done; // Ignored
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
594 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
595 GetChangesInternal(target, done, s, 1);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
596 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
597
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
598
3019
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
599 class SQLiteDatabaseWrapper::Transaction : public IDatabaseWrapper::ITransaction
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
600 {
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
601 private:
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
602 SQLiteDatabaseWrapper& that_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
603 std::unique_ptr<SQLite::Transaction> transaction_;
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
604 int64_t initialDiskSize_;
3019
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 public:
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
607 Transaction(SQLiteDatabaseWrapper& that) :
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
608 that_(that),
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
609 transaction_(new SQLite::Transaction(that_.db_))
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 #if defined(NDEBUG)
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
612 // Release mode
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
613 initialDiskSize_ = 0;
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
614 #else
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
615 // Debug mode
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
616 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
617 #endif
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
618 }
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
619
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
620 virtual void Begin()
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 transaction_->Begin();
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
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
625 virtual void Rollback()
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
626 {
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
627 transaction_->Rollback();
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
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
630 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
631 {
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
632 transaction_->Commit();
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
633
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
634 assert(initialDiskSize_ + fileSizeDelta >= 0 &&
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
635 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
636 }
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
637 };
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
638
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
639
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
640 IDatabaseWrapper::ITransaction* SQLiteDatabaseWrapper::StartTransaction()
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
641 {
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
642 return new Transaction(*this);
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
643 }
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
644
8336204d95dc refactoring computation of disk size for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3018
diff changeset
645
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
646 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
647 int64_t id)
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
648 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
649 target.clear();
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
650
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
651 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
652 s.BindInt64(0, id);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
653
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
654 while (s.Step())
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
655 {
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
656 MetadataType key = static_cast<MetadataType>(s.ColumnInt(0));
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
657 target[key] = s.ColumnString(1);
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
658 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
659 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
660
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
661
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
662 void SQLiteDatabaseWrapper::SetGlobalProperty(GlobalProperty property,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
663 const std::string& value)
2773
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 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
666 s.BindInt(0, property);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
667 s.BindString(1, value);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
668 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
669 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
670
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
671
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
672 bool SQLiteDatabaseWrapper::LookupGlobalProperty(std::string& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
673 GlobalProperty property)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
674 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
675 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
676 "SELECT value FROM GlobalProperties WHERE property=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
677 s.BindInt(0, property);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
678
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
679 if (!s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
680 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
681 return false;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
682 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
683 else
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 target = s.ColumnString(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
686 return true;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
687 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
688 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
691 int64_t SQLiteDatabaseWrapper::CreateResource(const std::string& publicId,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
692 ResourceType type)
2773
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 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
695 s.BindInt(0, type);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
696 s.BindString(1, publicId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
697 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
698 return db_.GetLastInsertRowId();
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
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
701
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
702 bool SQLiteDatabaseWrapper::LookupResource(int64_t& id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
703 ResourceType& type,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
704 const std::string& publicId)
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
707 "SELECT internalId, resourceType FROM Resources WHERE publicId=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
708 s.BindString(0, publicId);
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 if (!s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
711 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
712 return false;
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 else
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
715 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
716 id = s.ColumnInt(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
717 type = static_cast<ResourceType>(s.ColumnInt(1));
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 // 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
720 assert(!s.Step());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
721
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
722 return true;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
723 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
724 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
725
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
726
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
727 void SQLiteDatabaseWrapper::AttachChild(int64_t parent,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
728 int64_t child)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
729 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
730 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
731 s.BindInt64(0, parent);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
732 s.BindInt64(1, child);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
733 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
734 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
735
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
736
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
737 void SQLiteDatabaseWrapper::SetMetadata(int64_t id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
738 MetadataType type,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
739 const std::string& value)
2773
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 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
742 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
743 s.BindInt(1, type);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
744 s.BindString(2, value);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
745 s.Run();
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
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
748
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
749 void SQLiteDatabaseWrapper::DeleteMetadata(int64_t id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
750 MetadataType type)
2773
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 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
753 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
754 s.BindInt(1, type);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
755 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
756 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
759 bool SQLiteDatabaseWrapper::LookupMetadata(std::string& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
760 int64_t id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
761 MetadataType type)
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
764 "SELECT value FROM Metadata WHERE id=? AND type=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
765 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
766 s.BindInt(1, type);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
767
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
768 if (!s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
769 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
770 return false;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
771 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
772 else
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
773 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
774 target = s.ColumnString(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
775 return true;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
776 }
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::AddAttachment(int64_t id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
781 const FileInfo& 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, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
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.GetContentType());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
786 s.BindString(2, attachment.GetUuid());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
787 s.BindInt64(3, attachment.GetCompressedSize());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
788 s.BindInt64(4, attachment.GetUncompressedSize());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
789 s.BindInt(5, attachment.GetCompressionType());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
790 s.BindString(6, attachment.GetUncompressedMD5());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
791 s.BindString(7, attachment.GetCompressedMD5());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
792 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
793 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
796 void SQLiteDatabaseWrapper::DeleteAttachment(int64_t id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
797 FileContentType attachment)
2773
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 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
800 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
801 s.BindInt(1, attachment);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
802 s.Run();
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
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
805
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
806 void SQLiteDatabaseWrapper::ListAvailableAttachments(std::list<FileContentType>& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
807 int64_t id)
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 target.clear();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
810
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
811 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
812 "SELECT fileType FROM AttachedFiles WHERE id=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
813 s.BindInt64(0, id);
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 while (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 target.push_back(static_cast<FileContentType>(s.ColumnInt(0)));
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 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
820
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
821 bool SQLiteDatabaseWrapper::LookupAttachment(FileInfo& attachment,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
822 int64_t id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
823 FileContentType contentType)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
824 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
825 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
826 "SELECT uuid, uncompressedSize, compressionType, compressedSize, "
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
827 "uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
828 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
829 s.BindInt(1, contentType);
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 if (!s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
832 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
833 return false;
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 else
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
836 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
837 attachment = FileInfo(s.ColumnString(0),
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
838 contentType,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
839 s.ColumnInt64(1),
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
840 s.ColumnString(4),
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
841 static_cast<CompressionType>(s.ColumnInt(2)),
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
842 s.ColumnInt64(3),
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
843 s.ColumnString(5));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
844 return true;
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::ClearMainDicomTags(int64_t id)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
850 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
851 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
852 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
853 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
854 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
855 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
856
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
857 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
858 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
859 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
860 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
861 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
862 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
863
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
864
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
865 void SQLiteDatabaseWrapper::SetMainDicomTag(int64_t id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
866 const DicomTag& tag,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
867 const std::string& value)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
868 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
869 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
870 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
871 s.BindInt(1, tag.GetGroup());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
872 s.BindInt(2, tag.GetElement());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
873 s.BindString(3, value);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
874 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
875 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
876
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
877
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
878 void SQLiteDatabaseWrapper::SetIdentifierTag(int64_t id,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
879 const DicomTag& tag,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
880 const std::string& value)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
881 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
882 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
883 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
884 s.BindInt(1, tag.GetGroup());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
885 s.BindInt(2, tag.GetElement());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
886 s.BindString(3, value);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
887 s.Run();
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::GetMainDicomTags(DicomMap& map,
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 map.Clear();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
895
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
896 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
897 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
898 while (s.Step())
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 map.SetValue(s.ColumnInt(1),
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
901 s.ColumnInt(2),
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
902 s.ColumnString(3), false);
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::GetChildrenPublicId(std::list<std::string>& 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.publicId 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.ColumnString(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::GetChildrenInternalId(std::list<int64_t>& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
924 int64_t id)
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, "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
927 "WHERE a.parentId = b.internalId AND b.internalId = ?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
928 s.BindInt64(0, id);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
929
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
930 target.clear();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
931
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
932 while (s.Step())
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 target.push_back(s.ColumnInt64(0));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
935 }
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
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
938
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
939 void SQLiteDatabaseWrapper::LogChange(int64_t internalId,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
940 const ServerIndexChange& change)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
941 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
942 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
943 s.BindInt(0, change.GetChangeType());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
944 s.BindInt64(1, internalId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
945 s.BindInt(2, change.GetResourceType());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
946 s.BindString(3, change.GetDate());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
947 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
948 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
951 void SQLiteDatabaseWrapper::LogExportedResource(const ExportedResource& resource)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
952 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
953 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
954 "INSERT INTO ExportedResources VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
955
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
956 s.BindInt(0, resource.GetResourceType());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
957 s.BindString(1, resource.GetPublicId());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
958 s.BindString(2, resource.GetModality());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
959 s.BindString(3, resource.GetPatientId());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
960 s.BindString(4, resource.GetStudyInstanceUid());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
961 s.BindString(5, resource.GetSeriesInstanceUid());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
962 s.BindString(6, resource.GetSopInstanceUid());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
963 s.BindString(7, resource.GetDate());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
964 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
965 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
968 void SQLiteDatabaseWrapper::GetExportedResources(std::list<ExportedResource>& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
969 bool& done,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
970 int64_t since,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
971 uint32_t maxResults)
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
974 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
975 s.BindInt64(0, since);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
976 s.BindInt(1, maxResults + 1);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
977 GetExportedResourcesInternal(target, done, s, maxResults);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
978 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
979
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
980
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
981 void SQLiteDatabaseWrapper::GetLastExportedResource(std::list<ExportedResource>& target)
2773
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 bool done; // Ignored
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
984 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
985 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
986 GetExportedResourcesInternal(target, done, s, 1);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
987 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
988
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
989
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
990 uint64_t SQLiteDatabaseWrapper::GetTotalCompressedSize()
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
991 {
3018
e3b5c07146a3 speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3017
diff changeset
992 // 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
993 // 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
994
e3b5c07146a3 speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3017
diff changeset
995 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
996 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
997 return static_cast<uint64_t>(s.ColumnInt64(0));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
998 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
999
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1000
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1001 uint64_t SQLiteDatabaseWrapper::GetTotalUncompressedSize()
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1002 {
3018
e3b5c07146a3 speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3017
diff changeset
1003 // 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
1004 // 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
1005
e3b5c07146a3 speeding up the computation of the size of the attachments in SQLite
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3017
diff changeset
1006 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
1007 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1008 return static_cast<uint64_t>(s.ColumnInt64(0));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1009 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1010
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1011
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1012 uint64_t SQLiteDatabaseWrapper::GetResourceCount(ResourceType resourceType)
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1015 "SELECT COUNT(*) FROM Resources WHERE resourceType=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1016 s.BindInt(0, resourceType);
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 if (!s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1019 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1020 return 0;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1021 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1022 else
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 int64_t c = s.ColumnInt(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1025 assert(!s.Step());
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1026 return c;
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 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1029
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1030
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1031 void SQLiteDatabaseWrapper::GetAllPublicIds(std::list<std::string>& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1032 ResourceType resourceType)
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 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
1035 s.BindInt(0, resourceType);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1036
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1037 target.clear();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1038 while (s.Step())
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 target.push_back(s.ColumnString(0));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1041 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1042 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1043
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1044
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1045 void SQLiteDatabaseWrapper::GetAllPublicIds(std::list<std::string>& target,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1046 ResourceType resourceType,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1047 size_t since,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1048 size_t limit)
2773
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 if (limit == 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 target.clear();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1053 return;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1054 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1055
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1056 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1057 "SELECT publicId FROM Resources WHERE "
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1058 "resourceType=? LIMIT ? OFFSET ?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1059 s.BindInt(0, resourceType);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1060 s.BindInt64(1, limit);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1061 s.BindInt64(2, since);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1062
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1063 target.clear();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1064 while (s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1065 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1066 target.push_back(s.ColumnString(0));
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1067 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1068 }
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
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1071 bool SQLiteDatabaseWrapper::SelectPatientToRecycle(int64_t& internalId)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1072 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1073 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1074 "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
1075
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1076 if (!s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1077 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1078 // No patient remaining or all the patients are protected
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1079 return false;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1080 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1081 else
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1082 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1083 internalId = s.ColumnInt(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1084 return true;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1085 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1086 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1087
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1088
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1089 bool SQLiteDatabaseWrapper::SelectPatientToRecycle(int64_t& internalId,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1090 int64_t patientIdToAvoid)
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1093 "SELECT patientId FROM PatientRecyclingOrder "
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1094 "WHERE patientId != ? ORDER BY seq ASC LIMIT 1");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1095 s.BindInt64(0, patientIdToAvoid);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1096
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1097 if (!s.Step())
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1098 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1099 // No patient remaining or all the patients are protected
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1100 return false;
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 else
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1103 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1104 internalId = s.ColumnInt(0);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1105 return true;
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1106 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1107 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1108
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1109
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1110 bool SQLiteDatabaseWrapper::IsProtectedPatient(int64_t internalId)
2773
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1113 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1114 s.BindInt64(0, internalId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1115 return !s.Step();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1116 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1117
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1118
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1119 void SQLiteDatabaseWrapper::SetProtectedPatient(int64_t internalId,
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1120 bool isProtected)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1121 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1122 if (isProtected)
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 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
1125 s.BindInt64(0, internalId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1126 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1127 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1128 else if (IsProtectedPatient(internalId))
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1129 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1130 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
1131 s.BindInt64(0, internalId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1132 s.Run();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1133 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1134 else
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1135 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1136 // Nothing to do: The patient is already unprotected
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1137 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1138 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1139
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1140
3017
517fc4767ae0 renamed class DatabaseWrapper as SQLiteDatabaseWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2955
diff changeset
1141 bool SQLiteDatabaseWrapper::IsExistingResource(int64_t internalId)
2773
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1142 {
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1143 SQLite::Statement s(db_, SQLITE_FROM_HERE,
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1144 "SELECT * FROM Resources WHERE internalId=?");
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1145 s.BindInt64(0, internalId);
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1146 return s.Step();
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1147 }
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1148
bb63068844ae moving DatabaseWrapperBase into graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
1149
3020
d207f6ac1f86 tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3019
diff changeset
1150 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
1151 {
d207f6ac1f86 tracking disk size by the database engine to ensure consistency across transactions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3019
diff changeset
1152 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
1153 }
3025
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3020
diff changeset
1154
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3020
diff changeset
1155
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1156
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1157 class SQLiteDatabaseWrapper::LookupFormatter : public ISqlLookupFormatter
3029
ea653ec47f31 new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
1158 {
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1159 private:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1160 std::list<std::string> values_;
3029
ea653ec47f31 new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
1161
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1162 public:
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1163 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
1164 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1165 values_.push_back(value);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1166 return "?";
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1167 }
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1168
3078
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3075
diff changeset
1169 virtual std::string FormatResourceType(ResourceType level)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3075
diff changeset
1170 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3075
diff changeset
1171 return boost::lexical_cast<std::string>(level);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3075
diff changeset
1172 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3075
diff changeset
1173
3079
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
1174 virtual std::string FormatWildcardEscape()
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
1175 {
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
1176 return "ESCAPE '\\'";
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
1177 }
65e2bfa953ef ISqlLookupFormatter::FormatWildcardEscape()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3078
diff changeset
1178
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1179 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
1180 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1181 size_t pos = 0;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1182
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1183 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
1184 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
1185 {
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1186 statement.BindString(pos, *it);
3029
ea653ec47f31 new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
1187 }
ea653ec47f31 new class: DatabaseConstraint
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3027
diff changeset
1188 }
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1189 };
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1190
3031
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
1191
3075
ead8576a02ef IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3061
diff changeset
1192 static void AnswerLookup(std::list<std::string>& resourcesId,
ead8576a02ef IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3061
diff changeset
1193 std::list<std::string>& instancesId,
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1194 SQLite::Connection& db,
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1195 ResourceType level)
3025
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3020
diff changeset
1196 {
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1197 resourcesId.clear();
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1198 instancesId.clear();
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1199
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
1200 std::unique_ptr<SQLite::Statement> statement;
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1201
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1202 switch (level)
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 case ResourceType_Patient:
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1205 {
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1206 statement.reset(
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1207 new SQLite::Statement(
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1208 db, SQLITE_FROM_HERE,
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1209 "SELECT patients.publicId, instances.publicID FROM Lookup AS patients "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1210 "INNER JOIN Resources studies ON patients.internalId=studies.parentId "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1211 "INNER JOIN Resources series ON studies.internalId=series.parentId "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1212 "INNER JOIN Resources instances ON series.internalId=instances.parentId "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1213 "GROUP BY patients.publicId"));
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 break;
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1216 }
3025
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3020
diff changeset
1217
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1218 case ResourceType_Study:
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1219 {
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1220 statement.reset(
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1221 new SQLite::Statement(
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1222 db, SQLITE_FROM_HERE,
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1223 "SELECT studies.publicId, instances.publicID FROM Lookup AS studies "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1224 "INNER JOIN Resources series ON studies.internalId=series.parentId "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1225 "INNER JOIN Resources instances ON series.internalId=instances.parentId "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1226 "GROUP BY studies.publicId"));
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1227
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1228 break;
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1229 }
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1230
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1231 case ResourceType_Series:
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 statement.reset(
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1234 new SQLite::Statement(
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1235 db, SQLITE_FROM_HERE,
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1236 "SELECT series.publicId, instances.publicID FROM Lookup AS series "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1237 "INNER JOIN Resources instances ON series.internalId=instances.parentId "
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1238 "GROUP BY series.publicId"));
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1239
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1240 break;
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
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1243 case ResourceType_Instance:
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1244 {
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1245 statement.reset(
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1246 new SQLite::Statement(
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1247 db, SQLITE_FROM_HERE, "SELECT publicId, publicId FROM Lookup"));
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 break;
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1250 }
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1251
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1252 default:
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1253 throw OrthancException(ErrorCode_InternalError);
3027
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3025
diff changeset
1254 }
3025
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3020
diff changeset
1255
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1256 assert(statement.get() != NULL);
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1257
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1258 while (statement->Step())
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1259 {
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1260 resourcesId.push_back(statement->ColumnString(0));
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1261 instancesId.push_back(statement->ColumnString(1));
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1262 }
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1263 }
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1264
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1265
3075
ead8576a02ef IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3061
diff changeset
1266 void SQLiteDatabaseWrapper::ApplyLookupResources(std::list<std::string>& resourcesId,
ead8576a02ef IDatabaseWrapper::ApplyLookupResources now returns lists
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3061
diff changeset
1267 std::list<std::string>* instancesId,
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1268 const std::vector<DatabaseConstraint>& lookup,
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1269 ResourceType queryLevel,
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1270 size_t limit)
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1271 {
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1272 LookupFormatter formatter;
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1273
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1274 std::string sql;
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1275 LookupFormatter::Apply(sql, formatter, lookup, queryLevel, limit);
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1276
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1277 sql = "CREATE TEMPORARY TABLE Lookup AS " + sql;
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1278
3031
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
1279 {
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
1280 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DROP TABLE IF EXISTS Lookup");
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
1281 s.Run();
18a2d196414b simplification
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3030
diff changeset
1282 }
3030
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1283
25afa7b8cb51 SQLiteDatabaseWrapper::ApplyLookupResources()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3029
diff changeset
1284 {
3058
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1285 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
1286 formatter.Bind(statement);
6faf575ba9cc refactoring: class ISqlLookupFormatter to be used in orthanc-databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3056
diff changeset
1287 statement.Run();
3025
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3020
diff changeset
1288 }
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3020
diff changeset
1289
3036
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1290 if (instancesId != NULL)
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1291 {
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1292 AnswerLookup(resourcesId, *instancesId, db_, queryLevel);
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1293 }
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1294 else
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1295 {
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1296 resourcesId.clear();
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1297
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1298 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
1299
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1300 while (s.Step())
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1301 {
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1302 resourcesId.push_back(s.ColumnString(0));
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1303 }
8fd203510d8b moving LookupIdentifierQuery to the graveyard
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3033
diff changeset
1304 }
3025
039a9d262d64 preparing to speed up find in databases
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3020
diff changeset
1305 }
3105
2e1711f80f74 More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
1306
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 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
1309 {
2e1711f80f74 More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
1310 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
1311 "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
1312
2e1711f80f74 More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
1313 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
1314 {
2e1711f80f74 More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
1315 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
1316 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
1317 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
1318 }
2e1711f80f74 More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
1319 else
2e1711f80f74 More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
1320 {
2e1711f80f74 More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
1321 // 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
1322 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
1323 }
2e1711f80f74 More consistent handling of the "Last" field returned by the "/changes" URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3093
diff changeset
1324 }
3121
f86ebf971a72 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3116
diff changeset
1325
f86ebf971a72 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3116
diff changeset
1326
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
1327 void SQLiteDatabaseWrapper::TagMostRecentPatient(int64_t patient)
3121
f86ebf971a72 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3116
diff changeset
1328 {
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
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 "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
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
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
1335 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
1336 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
1337
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
1338 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
1339 {
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
1340 // 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
1341 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
1342 }
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
1343 }
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
1344
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
1345 {
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
1346 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
1347 "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
1348 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
1349 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
1350 }
3121
f86ebf971a72 fix unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3116
diff changeset
1351 }
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352 }