annotate OrthancServer/DatabaseWrapper.cpp @ 2704:b71c59312bae

fix MIME type for PAM images
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 06 Jul 2018 15:18:53 +0200
parents 878b59270859
children bb63068844ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1847
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1286
diff changeset
4 * Department, University Hospital of Liege, Belgium
2447
878b59270859 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
34 #include "PrecompiledHeadersServer.h"
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "DatabaseWrapper.h"
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../Core/DicomFormat/DicomArray.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1432
diff changeset
38 #include "../Core/Logging.h"
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #include "EmbeddedResources.h"
1669
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
40 #include "ServerToolbox.h"
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #include <stdio.h>
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
43 #include <boost/lexical_cast.hpp>
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 namespace Orthanc
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 namespace Internals
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 class SignalFileDeleted : public SQLite::IScalarFunction
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 private:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
53 IDatabaseListener& listener_;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 public:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
56 SignalFileDeleted(IDatabaseListener& listener) :
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 listener_(listener)
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
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 virtual const char* GetName() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 return "SignalFileDeleted";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 virtual unsigned int GetCardinality() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
68 return 7;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 virtual void Compute(SQLite::FunctionContext& context)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
73 std::string uncompressedMD5, compressedMD5;
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
74
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
75 if (!context.IsNullValue(5))
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
76 {
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
77 uncompressedMD5 = context.GetStringValue(5);
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
78 }
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
79
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
80 if (!context.IsNullValue(6))
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
81 {
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
82 compressedMD5 = context.GetStringValue(6);
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
83 }
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
84
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
85 FileInfo info(context.GetStringValue(0),
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
86 static_cast<FileContentType>(context.GetIntValue(1)),
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
87 static_cast<uint64_t>(context.GetInt64Value(2)),
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
88 uncompressedMD5,
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
89 static_cast<CompressionType>(context.GetIntValue(3)),
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
90 static_cast<uint64_t>(context.GetInt64Value(4)),
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
91 compressedMD5);
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
92
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
93 listener_.SignalFileDeleted(info);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 };
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
97 class SignalResourceDeleted : public SQLite::IScalarFunction
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
98 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
99 private:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
100 IDatabaseListener& listener_;
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
101
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
102 public:
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
103 SignalResourceDeleted(IDatabaseListener& listener) :
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
104 listener_(listener)
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
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
108 virtual const char* GetName() const
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
109 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
110 return "SignalResourceDeleted";
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
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
113 virtual unsigned int GetCardinality() const
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
114 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
115 return 2;
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
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
118 virtual void Compute(SQLite::FunctionContext& context)
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
119 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
120 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1));
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
121 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
122 listener_.SignalChange(change);
1158
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 };
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
125
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 class SignalRemainingAncestor : public SQLite::IScalarFunction
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 private:
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 bool hasRemainingAncestor_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 std::string remainingPublicId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ResourceType remainingType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 public:
660
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
134 SignalRemainingAncestor() :
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
135 hasRemainingAncestor_(false)
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 }
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
138
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 void Reset()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 hasRemainingAncestor_ = false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 virtual const char* GetName() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 return "SignalRemainingAncestor";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 virtual unsigned int GetCardinality() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 return 2;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 virtual void Compute(SQLite::FunctionContext& context)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 VLOG(1) << "There exists a remaining ancestor with public ID \""
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 << context.GetStringValue(0)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 << "\" of type "
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 << context.GetIntValue(1);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 if (!hasRemainingAncestor_ ||
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 remainingType_ >= context.GetIntValue(1))
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 hasRemainingAncestor_ = true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 remainingPublicId_ = context.GetStringValue(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 remainingType_ = static_cast<ResourceType>(context.GetIntValue(1));
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
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 bool HasRemainingAncestor() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 return hasRemainingAncestor_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 const std::string& GetRemainingAncestorId() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 assert(hasRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 return remainingPublicId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 ResourceType GetRemainingAncestorType() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 assert(hasRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 return remainingType_;
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
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
190
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
191 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
192 int64_t id)
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
193 {
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
194 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE parentId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
195 s.BindInt64(0, id);
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
196
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
197 childrenPublicIds.clear();
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
198 while (s.Step())
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
199 {
1241
90d2f320862d refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1240
diff changeset
200 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
201 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
202 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
203
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
204
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 void DatabaseWrapper::DeleteResource(int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 signalRemainingAncestor_->Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
210 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
213 if (signalRemainingAncestor_->HasRemainingAncestor() &&
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
214 listener_ != NULL)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
216 listener_->SignalRemainingAncestor(signalRemainingAncestor_->GetRemainingAncestorType(),
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
217 signalRemainingAncestor_->GetRemainingAncestorId());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
222 bool DatabaseWrapper::GetParentPublicId(std::string& target,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 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
226 "WHERE a.internalId = b.parentId AND b.internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
227 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
231 target = s.ColumnString(0);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 int64_t DatabaseWrapper::GetTableRecordCount(const std::string& table)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 char buf[128];
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 sprintf(buf, "SELECT COUNT(*) FROM %s", table.c_str());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 SQLite::Statement s(db_, buf);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
218
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
247 if (!s.Step())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
248 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
249 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
250 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
251
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 int64_t c = s.ColumnInt(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 assert(!s.Step());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 return c;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
259 DatabaseWrapper::DatabaseWrapper(const std::string& path) :
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
260 listener_(NULL),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
261 base_(db_),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
262 signalRemainingAncestor_(NULL),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
263 version_(0)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 db_.Open(path);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
1847
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
268 DatabaseWrapper::DatabaseWrapper() :
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
269 listener_(NULL),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
270 base_(db_),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
271 signalRemainingAncestor_(NULL),
559956d5ceb2 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1729
diff changeset
272 version_(0)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 db_.OpenInMemory();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 void DatabaseWrapper::Open()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1712
diff changeset
279 db_.Execute("PRAGMA ENCODING=\"UTF-8\";");
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1712
diff changeset
280
374
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
281 // Performance tuning of SQLite with PRAGMAs
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
282 // http://www.sqlite.org/pragma.html
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
283 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
284 db_.Execute("PRAGMA JOURNAL_MODE=WAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
285 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
286 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
287 //db_.Execute("PRAGMA TEMP_STORE=memory");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
288
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 if (!db_.DoesTableExist("GlobalProperties"))
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 LOG(INFO) << "Creating the database";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 std::string query;
203
9283552c25df db refactoring done
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
293 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 db_.Execute(query);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 521
diff changeset
297 // 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
298 std::string tmp;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
299 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabaseSchemaVersion))
1239
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
300 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
301 tmp = "Unknown";
1239
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
302 }
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
303
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
304 bool ok = false;
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
305 try
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
306 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
307 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
308 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
309 ok = true;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
310 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
311 catch (boost::bad_lexical_cast&)
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
312 {
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
313 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
314
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
315 if (!ok)
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
316 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
317 LOG(ERROR) << "Incompatible version of the Orthanc database: " << tmp;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
318 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
319 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
320
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 db_.Register(signalRemainingAncestor_);
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
323 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
324
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
325
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
326 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
327 EmbeddedResources::FileResourceId script)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
328 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
329 std::string upgrade;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
330 EmbeddedResources::GetFileResource(upgrade, script);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
331 db.BeginTransaction();
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
332 db.Execute(upgrade);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
333 db.CommitTransaction();
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
334 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
335
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
336
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
337 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
338 IStorageArea& storageArea)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
339 {
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
340 if (targetVersion != 6)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
341 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
342 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
343 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
344
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
345 // 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
346 // 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
347 if (version_ != 3 &&
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
348 version_ != 4 &&
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
349 version_ != 5 &&
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
350 version_ != 6)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
351 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
352 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
353 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
354
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
355 if (version_ == 3)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
356 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
357 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
358 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
359 version_ = 4;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
360 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
361
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
362 if (version_ == 4)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
363 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
364 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
365 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
366 version_ = 5;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
367 }
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
368
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
369 if (version_ == 5)
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
370 {
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
371 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
372 // No change in the DB schema, the step from version 5 to 6 only
1710
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
373 // consists in reconstructing the main DICOM tags information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
374 // (as more tags got included).
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
375 db_.BeginTransaction();
2120
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
376 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Patient);
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
377 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Study);
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
378 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Series);
4b02ec79728a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
379 ServerToolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Instance);
1710
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
380 db_.Execute("UPDATE GlobalProperties SET value=\"6\" WHERE property=" +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
381 boost::lexical_cast<std::string>(GlobalProperty_DatabaseSchemaVersion) + ";");
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
382 db_.CommitTransaction();
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
383 version_ = 6;
1729
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
384 }
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
385 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
386
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
387
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
388 void DatabaseWrapper::SetListener(IDatabaseListener& listener)
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
389 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
390 listener_ = &listener;
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
391 db_.Register(new Internals::SignalFileDeleted(listener));
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
392 db_.Register(new Internals::SignalResourceDeleted(listener));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 }
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
394
413
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
395
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
396 void DatabaseWrapper::ClearTable(const std::string& tableName)
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
397 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
398 db_.Execute("DELETE FROM " + tableName);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
399 }
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
400
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
401
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
402 bool DatabaseWrapper::LookupParent(int64_t& parentId,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
403 int64_t resourceId)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
404 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
405 bool found;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
406 ErrorCode error = base_.LookupParent(found, parentId, resourceId);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
407
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
408 if (error != ErrorCode_Success)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
409 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
410 throw OrthancException(error);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
411 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
412 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
413 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
414 return found;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
415 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
416 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
417
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
418
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
419 ResourceType DatabaseWrapper::GetResourceType(int64_t resourceId)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
420 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
421 ResourceType result;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
422 ErrorCode code = base_.GetResourceType(result, resourceId);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
423
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
424 if (code == ErrorCode_Success)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
425 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
426 return result;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
427 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
428 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
429 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
430 throw OrthancException(code);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
431 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
432 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
433
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
434
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
435 std::string DatabaseWrapper::GetPublicId(int64_t resourceId)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
436 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
437 std::string id;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
438
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
439 if (base_.GetPublicId(id, resourceId))
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
440 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
441 return id;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
442 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
443 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
444 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
445 throw OrthancException(ErrorCode_UnknownResource);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
446 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
447 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
448
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
449
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
450 void DatabaseWrapper::GetChanges(std::list<ServerIndexChange>& target /*out*/,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
451 bool& done /*out*/,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
452 int64_t since,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
453 uint32_t maxResults)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
454 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
455 ErrorCode code = base_.GetChanges(target, done, since, maxResults);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
456
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
457 if (code != ErrorCode_Success)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
458 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
459 throw OrthancException(code);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
460 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
461 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
462
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
463
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
464 void DatabaseWrapper::GetLastChange(std::list<ServerIndexChange>& target /*out*/)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
465 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
466 ErrorCode code = base_.GetLastChange(target);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
467
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
468 if (code != ErrorCode_Success)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
469 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
470 throw OrthancException(code);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
471 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
472 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
473
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
474
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
475 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
476 int64_t id)
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
477 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
478 target.clear();
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
479
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
480 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
481 s.BindInt64(0, id);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
482
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
483 while (s.Step())
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
484 {
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
485 MetadataType key = static_cast<MetadataType>(s.ColumnInt(0));
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
486 target[key] = s.ColumnString(1);
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
487 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
488 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
489
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 }