annotate OrthancServer/DatabaseWrapper.cpp @ 1668:de1413733c97 db-changes

reconstructing main dicom tags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Sep 2015 17:18:39 +0200
parents 761a5c07fb1b
children a412ad57f0f9
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
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1286
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1286
diff changeset
4 * Department, University Hospital of Liege, Belgium
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * modify file(s) with this exception, you may extend this exception to
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * 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
19 * you do not wish to do so, delete this exception statement from your
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
33 #include "PrecompiledHeadersServer.h"
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "DatabaseWrapper.h"
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "../Core/DicomFormat/DicomArray.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1432
diff changeset
37 #include "../Core/Logging.h"
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
38 #include "../Core/Uuid.h"
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "EmbeddedResources.h"
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <stdio.h>
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
42 #include <boost/lexical_cast.hpp>
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 namespace Orthanc
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 namespace Internals
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 class SignalFileDeleted : public SQLite::IScalarFunction
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 private:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
52 IDatabaseListener& listener_;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 public:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
55 SignalFileDeleted(IDatabaseListener& listener) :
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 listener_(listener)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 virtual const char* GetName() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return "SignalFileDeleted";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 virtual unsigned int GetCardinality() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
67 return 7;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 virtual void Compute(SQLite::FunctionContext& context)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
72 std::string uncompressedMD5, compressedMD5;
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
73
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
74 if (!context.IsNullValue(5))
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
75 {
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
76 uncompressedMD5 = context.GetStringValue(5);
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
77 }
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 if (!context.IsNullValue(6))
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 compressedMD5 = context.GetStringValue(6);
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
82 }
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
83
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
84 FileInfo info(context.GetStringValue(0),
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
85 static_cast<FileContentType>(context.GetIntValue(1)),
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
86 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
87 uncompressedMD5,
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
88 static_cast<CompressionType>(context.GetIntValue(3)),
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
89 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
90 compressedMD5);
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
91
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
92 listener_.SignalFileDeleted(info);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 };
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
96 class SignalResourceDeleted : public SQLite::IScalarFunction
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
97 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
98 private:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
99 IDatabaseListener& listener_;
1158
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 public:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
102 SignalResourceDeleted(IDatabaseListener& listener) :
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
103 listener_(listener)
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
104 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
105 }
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
106
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
107 virtual const char* GetName() const
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 return "SignalResourceDeleted";
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
110 }
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 virtual unsigned int GetCardinality() const
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 return 2;
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
115 }
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 virtual void Compute(SQLite::FunctionContext& context)
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 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1));
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
120 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
121 listener_.SignalChange(change);
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
122 }
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
123 };
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
124
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 class SignalRemainingAncestor : public SQLite::IScalarFunction
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 private:
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 bool hasRemainingAncestor_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 std::string remainingPublicId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 ResourceType remainingType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 public:
660
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
133 SignalRemainingAncestor() :
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
134 hasRemainingAncestor_(false)
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
135 {
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
136 }
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
137
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 void Reset()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 hasRemainingAncestor_ = false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 virtual const char* GetName() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 return "SignalRemainingAncestor";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 virtual unsigned int GetCardinality() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 return 2;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 virtual void Compute(SQLite::FunctionContext& context)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 VLOG(1) << "There exists a remaining ancestor with public ID \""
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 << context.GetStringValue(0)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 << "\" of type "
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 << context.GetIntValue(1);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 if (!hasRemainingAncestor_ ||
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 remainingType_ >= context.GetIntValue(1))
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 hasRemainingAncestor_ = true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 remainingPublicId_ = context.GetStringValue(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 remainingType_ = static_cast<ResourceType>(context.GetIntValue(1));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 bool HasRemainingAncestor() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 return hasRemainingAncestor_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 const std::string& GetRemainingAncestorId() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 assert(hasRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 return remainingPublicId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 ResourceType GetRemainingAncestorType() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 assert(hasRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 return remainingType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 };
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
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
190 void DatabaseWrapper::SetGlobalProperty(GlobalProperty property,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 const std::string& value)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO GlobalProperties VALUES(?, ?)");
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
194 s.BindInt(0, property);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 s.BindString(1, value);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
199 bool DatabaseWrapper::LookupGlobalProperty(std::string& target,
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
200 GlobalProperty property)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 SQLite::Statement s(db_, SQLITE_FROM_HERE,
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
203 "SELECT value FROM GlobalProperties WHERE property=?");
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
204 s.BindInt(0, property);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 if (!s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 target = s.ColumnString(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 int64_t DatabaseWrapper::CreateResource(const std::string& publicId,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 ResourceType type)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Resources VALUES(NULL, ?, ?, NULL)");
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 s.BindInt(0, type);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 s.BindString(1, publicId);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 s.Run();
1299
4ce47e8ed0d2 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1294
diff changeset
224 return db_.GetLastInsertRowId();
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
1294
910478b2d4e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
227 bool DatabaseWrapper::LookupResource(int64_t& id,
910478b2d4e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
228 ResourceType& type,
910478b2d4e4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
229 const std::string& publicId)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 SQLite::Statement s(db_, SQLITE_FROM_HERE,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 "SELECT internalId, resourceType FROM Resources WHERE publicId=?");
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 s.BindString(0, publicId);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 if (!s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 id = s.ColumnInt(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 type = static_cast<ResourceType>(s.ColumnInt(1));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 // Check whether there is a single resource with this public id
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 assert(!s.Step());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
251 bool DatabaseWrapper::LookupParent(int64_t& parentId,
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
252 int64_t resourceId)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
253 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
254 SQLite::Statement s(db_, SQLITE_FROM_HERE,
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
255 "SELECT parentId FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
256 s.BindInt64(0, resourceId);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
257
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
258 if (!s.Step())
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
259 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
260 throw OrthancException(ErrorCode_UnknownResource);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
261 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
262
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
263 if (s.ColumnIsNull(0))
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
264 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
265 return false;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
266 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
267 else
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
268 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
269 parentId = s.ColumnInt(0);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
270 return true;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
271 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
272 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
273
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
274 std::string DatabaseWrapper::GetPublicId(int64_t resourceId)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
275 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
276 SQLite::Statement s(db_, SQLITE_FROM_HERE,
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
277 "SELECT publicId FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
278 s.BindInt64(0, resourceId);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
279
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
280 if (!s.Step())
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
281 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
282 throw OrthancException(ErrorCode_UnknownResource);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
283 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
284
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
285 return s.ColumnString(0);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
286 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
287
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
288
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
289 ResourceType DatabaseWrapper::GetResourceType(int64_t resourceId)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
290 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
291 SQLite::Statement s(db_, SQLITE_FROM_HERE,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
292 "SELECT resourceType FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
293 s.BindInt64(0, resourceId);
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
294
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
295 if (!s.Step())
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
296 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
297 throw OrthancException(ErrorCode_UnknownResource);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
298 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
299
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
300 return static_cast<ResourceType>(s.ColumnInt(0));
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
301 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
302
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
303
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 void DatabaseWrapper::AttachChild(int64_t parent,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 int64_t child)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 SQLite::Statement s(db_, SQLITE_FROM_HERE, "UPDATE Resources SET parentId = ? WHERE internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
308 s.BindInt64(0, parent);
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
309 s.BindInt64(1, child);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
313
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
314 void DatabaseWrapper::GetChildren(std::list<std::string>& childrenPublicIds,
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
315 int64_t id)
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
316 {
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
317 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE parentId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
318 s.BindInt64(0, id);
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
319
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
320 childrenPublicIds.clear();
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
321 while (s.Step())
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
322 {
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
323 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
324 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
325 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
326
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
327
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 void DatabaseWrapper::DeleteResource(int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 signalRemainingAncestor_->Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
333 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
336 if (signalRemainingAncestor_->HasRemainingAncestor() &&
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
337 listener_ != NULL)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
339 listener_->SignalRemainingAncestor(signalRemainingAncestor_->GetRemainingAncestorType(),
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
340 signalRemainingAncestor_->GetRemainingAncestorId());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 void DatabaseWrapper::SetMetadata(int64_t id,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 MetadataType type,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 const std::string& value)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO Metadata VALUES(?, ?, ?)");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
349 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 s.BindInt(1, type);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 s.BindString(2, value);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
438
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
355 void DatabaseWrapper::DeleteMetadata(int64_t id,
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
356 MetadataType type)
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
357 {
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
358 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Metadata WHERE id=? and type=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
359 s.BindInt64(0, id);
438
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
360 s.BindInt(1, type);
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
361 s.Run();
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
362 }
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
363
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
364 bool DatabaseWrapper::LookupMetadata(std::string& target,
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
365 int64_t id,
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
366 MetadataType type)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 SQLite::Statement s(db_, SQLITE_FROM_HERE,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 "SELECT value FROM Metadata WHERE id=? AND type=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
370 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 s.BindInt(1, type);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 if (!s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 target = s.ColumnString(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
739
696dbb4fd390 api uniformization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
384 void DatabaseWrapper::ListAvailableMetadata(std::list<MetadataType>& target,
436
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
385 int64_t id)
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
386 {
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
387 target.clear();
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
388
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
389 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT type FROM Metadata WHERE id=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
390 s.BindInt64(0, id);
436
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
391
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
392 while (s.Step())
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
393 {
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
394 target.push_back(static_cast<MetadataType>(s.ColumnInt(0)));
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
395 }
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
396 }
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
397
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
398
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
399 void DatabaseWrapper::AddAttachment(int64_t id,
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
400 const FileInfo& attachment)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 {
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
402 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
403 s.BindInt64(0, id);
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
404 s.BindInt(1, attachment.GetContentType());
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
405 s.BindString(2, attachment.GetUuid());
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
406 s.BindInt64(3, attachment.GetCompressedSize());
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
407 s.BindInt64(4, attachment.GetUncompressedSize());
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
408 s.BindInt(5, attachment.GetCompressionType());
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
409 s.BindString(6, attachment.GetUncompressedMD5());
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
410 s.BindString(7, attachment.GetCompressedMD5());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
414
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
415 void DatabaseWrapper::DeleteAttachment(int64_t id,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
416 FileContentType attachment)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
417 {
701
f9052558eada fix attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
418 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM AttachedFiles WHERE id=? AND fileType=?");
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
419 s.BindInt64(0, id);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
420 s.BindInt(1, attachment);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
421 s.Run();
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
422 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
423
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
424
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
425
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
426 void DatabaseWrapper::ListAvailableAttachments(std::list<FileContentType>& target,
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
427 int64_t id)
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
428 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
429 target.clear();
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
430
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
431 SQLite::Statement s(db_, SQLITE_FROM_HERE,
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
432 "SELECT fileType FROM AttachedFiles WHERE id=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
433 s.BindInt64(0, id);
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
434
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
435 while (s.Step())
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
436 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
437 target.push_back(static_cast<FileContentType>(s.ColumnInt(0)));
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
438 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
439 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
440
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
441 bool DatabaseWrapper::LookupAttachment(FileInfo& attachment,
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
442 int64_t id,
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
443 FileContentType contentType)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 SQLite::Statement s(db_, SQLITE_FROM_HERE,
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
446 "SELECT uuid, uncompressedSize, compressionType, compressedSize, uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
447 s.BindInt64(0, id);
197
530a25320461 removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
448 s.BindInt(1, contentType);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 if (!s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
456 attachment = FileInfo(s.ColumnString(0),
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
457 contentType,
740
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 739
diff changeset
458 s.ColumnInt64(1),
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
459 s.ColumnString(4),
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
460 static_cast<CompressionType>(s.ColumnInt(2)),
740
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 739
diff changeset
461 s.ColumnInt64(3),
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
462 s.ColumnString(5));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
467
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
468 void DatabaseWrapper::ClearMainDicomTags(int64_t id)
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
469 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
470 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
471 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM DicomIdentifiers WHERE id=?");
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
472 s.BindInt64(0, id);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
473 s.Run();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
474 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
475
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
476 {
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
477 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM MainDicomTags WHERE id=?");
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
478 s.BindInt64(0, id);
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
479 s.Run();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
480 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
481 }
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
482
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
483
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
484 static void SetMainDicomTagsInternal(SQLite::Statement& s,
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
485 int64_t id,
1286
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
486 const DicomTag& tag,
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
487 const std::string& value)
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
488 {
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
489 s.BindInt64(0, id);
1286
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
490 s.BindInt(1, tag.GetGroup());
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
491 s.BindInt(2, tag.GetElement());
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
492 s.BindString(3, value);
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
493 s.Run();
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
494 }
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
495
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
496
1286
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
497 void DatabaseWrapper::SetMainDicomTag(int64_t id,
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
498 const DicomTag& tag,
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
499 const std::string& value)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 {
1286
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
501 if (tag.IsIdentifier())
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 {
1286
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
503 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifiers VALUES(?, ?, ?, ?)");
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
504 SetMainDicomTagsInternal(s, id, tag, value);
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
505 }
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
506 else
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
507 {
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
508 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)");
b4acdb37e43b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1247
diff changeset
509 SetMainDicomTagsInternal(s, id, tag, value);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 void DatabaseWrapper::GetMainDicomTags(DicomMap& map,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 map.Clear();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM MainDicomTags WHERE id=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
519 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 while (s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 map.SetValue(s.ColumnInt(1),
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 s.ColumnInt(2),
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 s.ColumnString(3));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 }
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
526
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
527 SQLite::Statement s2(db_, SQLITE_FROM_HERE, "SELECT * FROM DicomIdentifiers WHERE id=?");
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
528 s2.BindInt64(0, id);
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
529 while (s2.Step())
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
530 {
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
531 map.SetValue(s2.ColumnInt(1),
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
532 s2.ColumnInt(2),
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
533 s2.ColumnString(3));
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
534 }
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
538 bool DatabaseWrapper::GetParentPublicId(std::string& target,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 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
542 "WHERE a.internalId = b.parentId AND b.internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
543 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 if (s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
547 target = s.ColumnString(0);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
557 void DatabaseWrapper::GetChildrenPublicId(std::list<std::string>& target,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 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
561 "WHERE a.parentId = b.internalId AND b.internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
562 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
564 target.clear();
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 while (s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
568 target.push_back(s.ColumnString(0));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
573 void DatabaseWrapper::GetChildrenInternalId(std::list<int64_t>& target,
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
574 int64_t id)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
575 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
576 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.internalId FROM Resources AS a, Resources AS b "
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
577 "WHERE a.parentId = b.internalId AND b.internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
578 s.BindInt64(0, id);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
579
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
580 target.clear();
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
581
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
582 while (s.Step())
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
583 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
584 target.push_back(s.ColumnInt64(0));
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
585 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
586 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
587
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
588
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
589 void DatabaseWrapper::LogChange(int64_t internalId,
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
590 const ServerIndexChange& change)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 {
1300
919dfb2fb3fe DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
592 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)");
919dfb2fb3fe DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
593 s.BindInt(0, change.GetChangeType());
919dfb2fb3fe DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
594 s.BindInt64(1, internalId);
919dfb2fb3fe DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
595 s.BindInt(2, change.GetResourceType());
919dfb2fb3fe DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
596 s.BindString(3, change.GetDate());
919dfb2fb3fe DANGEROUS refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1299
diff changeset
597 s.Run();
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
601 void DatabaseWrapper::GetChangesInternal(std::list<ServerIndexChange>& target,
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
602 bool& done,
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
603 SQLite::Statement& s,
1302
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1301
diff changeset
604 uint32_t maxResults)
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
605 {
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
606 target.clear();
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
607
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
608 while (target.size() < maxResults && s.Step())
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
609 {
742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
610 int64_t seq = s.ColumnInt64(0);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
611 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1));
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
612 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3));
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
613 const std::string& date = s.ColumnString(4);
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
614
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
615 int64_t internalId = s.ColumnInt64(2);
205
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
616 std::string publicId = GetPublicId(internalId);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
617
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
618 target.push_back(ServerIndexChange(seq, changeType, resourceType, publicId, date));
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
619 }
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
620
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
621 done = !(target.size() == maxResults && s.Step());
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
622 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
623
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
624
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
625 void DatabaseWrapper::GetChanges(std::list<ServerIndexChange>& target,
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
626 bool& done,
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
627 int64_t since,
1302
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1301
diff changeset
628 uint32_t maxResults)
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
629 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
630 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes WHERE seq>? ORDER BY seq LIMIT ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
631 s.BindInt64(0, since);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
632 s.BindInt(1, maxResults + 1);
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
633 GetChangesInternal(target, done, s, maxResults);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
634 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
635
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
636 void DatabaseWrapper::GetLastChange(std::list<ServerIndexChange>& target)
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
637 {
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
638 bool done; // Ignored
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
639 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1");
1240
62c35e4b67db refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1239
diff changeset
640 GetChangesInternal(target, done, s, 1);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
641 }
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
642
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
643
1246
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
644 void DatabaseWrapper::LogExportedResource(const ExportedResource& resource)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 {
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
646 SQLite::Statement s(db_, SQLITE_FROM_HERE,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
647 "INSERT INTO ExportedResources VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)");
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
648
1246
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
649 s.BindInt(0, resource.GetResourceType());
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
650 s.BindString(1, resource.GetPublicId());
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
651 s.BindString(2, resource.GetModality());
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
652 s.BindString(3, resource.GetPatientId());
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
653 s.BindString(4, resource.GetStudyInstanceUid());
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
654 s.BindString(5, resource.GetSeriesInstanceUid());
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
655 s.BindString(6, resource.GetSopInstanceUid());
54bf0f0245f4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1244
diff changeset
656 s.BindString(7, resource.GetDate());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 }
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
659
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
660
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
661 void DatabaseWrapper::GetExportedResourcesInternal(std::list<ExportedResource>& target,
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
662 bool& done,
742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
663 SQLite::Statement& s,
1302
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1301
diff changeset
664 uint32_t maxResults)
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
665 {
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
666 target.clear();
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
667
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
668 while (target.size() < maxResults && s.Step())
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
669 {
743
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
670 int64_t seq = s.ColumnInt64(0);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
671 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1));
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
672 std::string publicId = s.ColumnString(2);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
673
1242
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
674 ExportedResource resource(seq,
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
675 resourceType,
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
676 publicId,
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
677 s.ColumnString(3), // modality
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
678 s.ColumnString(8), // date
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
679 s.ColumnString(4), // patient ID
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
680 s.ColumnString(5), // study instance UID
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
681 s.ColumnString(6), // series instance UID
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
682 s.ColumnString(7)); // sop instance UID
58e6a89c3ef4 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1241
diff changeset
683
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
684 target.push_back(resource);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
685 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
686
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
687 done = !(target.size() == maxResults && s.Step());
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
688 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
689
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
690
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
691 void DatabaseWrapper::GetExportedResources(std::list<ExportedResource>& target,
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
692 bool& done,
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
693 int64_t since,
1302
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1301
diff changeset
694 uint32_t maxResults)
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
695 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
696 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
697 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
698 s.BindInt64(0, since);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
699 s.BindInt(1, maxResults + 1);
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
700 GetExportedResourcesInternal(target, done, s, maxResults);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
701 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
702
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
703
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
704 void DatabaseWrapper::GetLastExportedResource(std::list<ExportedResource>& target)
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
705 {
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
706 bool done; // Ignored
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
707 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
708 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1");
1244
a0e420c5f2b8 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1242
diff changeset
709 GetExportedResourcesInternal(target, done, s, 1);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
710 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
711
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
712
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 int64_t DatabaseWrapper::GetTableRecordCount(const std::string& table)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 char buf[128];
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 sprintf(buf, "SELECT COUNT(*) FROM %s", table.c_str());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 SQLite::Statement s(db_, buf);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
218
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
721 if (!s.Step())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
722 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
723 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
724 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
725
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 int64_t c = s.ColumnInt(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 assert(!s.Step());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 return c;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 uint64_t DatabaseWrapper::GetTotalCompressedSize()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(compressedSize) FROM AttachedFiles");
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 return static_cast<uint64_t>(s.ColumnInt64(0));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 uint64_t DatabaseWrapper::GetTotalUncompressedSize()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(uncompressedSize) FROM AttachedFiles");
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 return static_cast<uint64_t>(s.ColumnInt64(0));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
748 void DatabaseWrapper::GetAllPublicIds(std::list<std::string>& target,
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
749 ResourceType resourceType)
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
750 {
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
751 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE resourceType=?");
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
752 s.BindInt(0, resourceType);
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
753
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
754 target.clear();
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
755 while (s.Step())
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
756 {
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
757 target.push_back(s.ColumnString(0));
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
758 }
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
759 }
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
760
1509
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
761 void DatabaseWrapper::GetAllPublicIds(std::list<std::string>& target,
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
762 ResourceType resourceType,
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
763 size_t since,
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
764 size_t limit)
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
765 {
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
766 if (limit == 0)
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
767 {
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
768 target.clear();
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
769 return;
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
770 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
771
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
772 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE resourceType=? LIMIT ? OFFSET ?");
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
773 s.BindInt(0, resourceType);
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
774 s.BindInt64(1, limit);
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
775 s.BindInt64(2, since);
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
776
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
777 target.clear();
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
778 while (s.Step())
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
779 {
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
780 target.push_back(s.ColumnString(0));
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
781 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
782 }
0586ed8897f1 limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
783
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
785 DatabaseWrapper::DatabaseWrapper(const std::string& path) : listener_(NULL)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 db_.Open(path);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 Open();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
791 DatabaseWrapper::DatabaseWrapper() : listener_(NULL)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 db_.OpenInMemory();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 Open();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 void DatabaseWrapper::Open()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 {
374
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
799 // Performance tuning of SQLite with PRAGMAs
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
800 // http://www.sqlite.org/pragma.html
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
801 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
802 db_.Execute("PRAGMA JOURNAL_MODE=WAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
803 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
804 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
805 //db_.Execute("PRAGMA TEMP_STORE=memory");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
806
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 if (!db_.DoesTableExist("GlobalProperties"))
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 LOG(INFO) << "Creating the database";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 std::string query;
203
9283552c25df db refactoring done
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
811 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 db_.Execute(query);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814
567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 521
diff changeset
815 // Check the version of the database
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
816 std::string tmp;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
817 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabaseSchemaVersion))
1239
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
818 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
819 tmp = "Unknown";
1239
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
820 }
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
821
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
822 bool ok = false;
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
823 try
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
824 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
825 LOG(INFO) << "Version of the Orthanc database: " << tmp;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
826 version_ = boost::lexical_cast<unsigned int>(tmp);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
827 ok = true;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
828 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
829 catch (boost::bad_lexical_cast&)
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
830 {
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
831 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
832
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
833 if (!ok)
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
834 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
835 LOG(ERROR) << "Incompatible version of the Orthanc database: " << tmp;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
836 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
837 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
838
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 db_.Register(signalRemainingAncestor_);
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
841 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
842
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
843
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
844 static void ExecuteUpgradeScript(SQLite::Connection& db,
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
845 EmbeddedResources::FileResourceId script)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
846 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
847 std::string upgrade;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
848 EmbeddedResources::GetFileResource(upgrade, script);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
849 db.BeginTransaction();
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
850 db.Execute(upgrade);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
851 db.CommitTransaction();
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
852 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
853
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
854
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
855 void DatabaseWrapper::Upgrade(unsigned int targetVersion,
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
856 IStorageArea& storageArea)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
857 {
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
858 if (targetVersion != 6)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
859 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
860 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
861 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
862
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
863 // 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
864 // 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
865 if (version_ != 3 &&
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
866 version_ != 4 &&
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
867 version_ != 5 &&
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
868 version_ != 6)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
869 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
870 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
871 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
872
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
873 if (version_ == 3)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
874 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
875 LOG(WARNING) << "Upgrading database version from 3 to 4";
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
876 ExecuteUpgradeScript(db_, EmbeddedResources::UPGRADE_DATABASE_3_TO_4);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
877 version_ = 4;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
878 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
879
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
880 if (version_ == 4)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
881 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
882 LOG(WARNING) << "Upgrading database version from 4 to 5";
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
883 ExecuteUpgradeScript(db_, EmbeddedResources::UPGRADE_DATABASE_4_TO_5);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
884 version_ = 5;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
885 }
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
886
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
887 if (version_ == 5)
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
888 {
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
889 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
890 // No change in the DB schema, the step from version 5 to 6 only
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
891 // consists in reconstructing the main DICOM tags information.
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
892 db_.BeginTransaction();
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
893 SetGlobalProperty(GlobalProperty_DatabaseSchemaVersion, "6");
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
894 SetGlobalProperty(GlobalProperty_ReconstructStudiesTags, "1");
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
895 SetGlobalProperty(GlobalProperty_ReconstructSeriesTags, "1");
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
896 db_.CommitTransaction();
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
897 version_ = 6;
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
898 }
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
899 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
900
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
901
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
902 void DatabaseWrapper::SetListener(IDatabaseListener& listener)
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
903 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
904 listener_ = &listener;
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
905 db_.Register(new Internals::SignalFileDeleted(listener));
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
906 db_.Register(new Internals::SignalResourceDeleted(listener));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 }
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
908
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
909 uint64_t DatabaseWrapper::GetResourceCount(ResourceType resourceType)
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
910 {
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
911 SQLite::Statement s(db_, SQLITE_FROM_HERE,
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
912 "SELECT COUNT(*) FROM Resources WHERE resourceType=?");
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
913 s.BindInt(0, resourceType);
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
914
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
915 if (!s.Step())
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
916 {
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
917 throw OrthancException(ErrorCode_InternalError);
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
918 }
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
919
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
920 int64_t c = s.ColumnInt(0);
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
921 assert(!s.Step());
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
922
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
923 return c;
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
924 }
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
925
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
926 bool DatabaseWrapper::SelectPatientToRecycle(int64_t& internalId)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
927 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
928 SQLite::Statement s(db_, SQLITE_FROM_HERE,
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
929 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1");
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
930
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
931 if (!s.Step())
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
932 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
933 // No patient remaining or all the patients are protected
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
934 return false;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
935 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
936 else
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
937 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
938 internalId = s.ColumnInt(0);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
939 return true;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
940 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
941 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
942
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
943 bool DatabaseWrapper::SelectPatientToRecycle(int64_t& internalId,
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
944 int64_t patientIdToAvoid)
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
945 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
946 SQLite::Statement s(db_, SQLITE_FROM_HERE,
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
947 "SELECT patientId FROM PatientRecyclingOrder "
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
948 "WHERE patientId != ? ORDER BY seq ASC LIMIT 1");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
949 s.BindInt64(0, patientIdToAvoid);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
950
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
951 if (!s.Step())
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
952 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
953 // No patient remaining or all the patients are protected
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
954 return false;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
955 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
956 else
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
957 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
958 internalId = s.ColumnInt(0);
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
959 return true;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
960 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
961 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
962
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
963 bool DatabaseWrapper::IsProtectedPatient(int64_t internalId)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
964 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
965 SQLite::Statement s(db_, SQLITE_FROM_HERE,
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
966 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
967 s.BindInt64(0, internalId);
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
968 return !s.Step();
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
969 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
970
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
971 void DatabaseWrapper::SetProtectedPatient(int64_t internalId,
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
972 bool isProtected)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
973 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
974 if (isProtected)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
975 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
976 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM PatientRecyclingOrder WHERE patientId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
977 s.BindInt64(0, internalId);
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
978 s.Run();
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
979 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
980 else if (IsProtectedPatient(internalId))
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
981 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
982 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO PatientRecyclingOrder VALUES(NULL, ?)");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
983 s.BindInt64(0, internalId);
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
984 s.Run();
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
985 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
986 else
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
987 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
988 // Nothing to do: The patient is already unprotected
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
989 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
990 }
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
991
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
992
413
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
993
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
994 void DatabaseWrapper::ClearTable(const std::string& tableName)
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
995 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
996 db_.Execute("DELETE FROM " + tableName);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
997 }
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
998
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
999
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1000 bool DatabaseWrapper::IsExistingResource(int64_t internalId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1001 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1002 SQLite::Statement s(db_, SQLITE_FROM_HERE,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1003 "SELECT * FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
1004 s.BindInt64(0, internalId);
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1005 return s.Step();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1006 }
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1007
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1008
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1009 void DatabaseWrapper::LookupIdentifier(std::list<int64_t>& target,
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1010 const DicomTag& tag,
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1011 const std::string& value)
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1012 {
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1013 if (!tag.IsIdentifier())
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1014 {
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1015 throw OrthancException(ErrorCode_ParameterOutOfRange);
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1016 }
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1017
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1018 SQLite::Statement s(db_, SQLITE_FROM_HERE,
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1019 "SELECT id FROM DicomIdentifiers WHERE tagGroup=? AND tagElement=? and value=?");
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1020
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1021 s.BindInt(0, tag.GetGroup());
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1022 s.BindInt(1, tag.GetElement());
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1023 s.BindString(2, value);
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1024
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1025 target.clear();
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1026
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1027 while (s.Step())
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1028 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1029 target.push_back(s.ColumnInt64(0));
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1030 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1031 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1032
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1033
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1034 void DatabaseWrapper::LookupIdentifier(std::list<int64_t>& target,
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1035 const std::string& value)
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1036 {
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1037 SQLite::Statement s(db_, SQLITE_FROM_HERE,
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1038 "SELECT id FROM DicomIdentifiers WHERE value=?");
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1039
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1040 s.BindString(0, value);
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1041
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1042 target.clear();
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1043
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1044 while (s.Step())
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1045 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1046 target.push_back(s.ColumnInt64(0));
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1047 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1048 }
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1049
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1050
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1051 void DatabaseWrapper::GetAllMetadata(std::map<MetadataType, std::string>& target,
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1052 int64_t id)
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1053 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1054 target.clear();
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1055
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1056 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
1057 s.BindInt64(0, id);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1058
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1059 while (s.Step())
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1060 {
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1061 MetadataType key = static_cast<MetadataType>(s.ColumnInt(0));
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
1062 target[key] = s.ColumnString(1);
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1063 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1064 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1065
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 }