annotate OrthancServer/DatabaseWrapper.cpp @ 1749:99f4a05f39fa db-changes

various types of constraints
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Oct 2015 10:54:51 +0100
parents 54d78925cbb6
children 559956d5ceb2
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"
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
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1669
diff changeset
259 DatabaseWrapper::DatabaseWrapper(const std::string& path) : listener_(NULL), base_(db_)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 db_.Open(path);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1669
diff changeset
264 DatabaseWrapper::DatabaseWrapper() : listener_(NULL), base_(db_)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 db_.OpenInMemory();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 void DatabaseWrapper::Open()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
1717
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1712
diff changeset
271 db_.Execute("PRAGMA ENCODING=\"UTF-8\";");
3926e6317a43 SetIdentifierTagInternal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1712
diff changeset
272
374
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
273 // Performance tuning of SQLite with PRAGMAs
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
274 // http://www.sqlite.org/pragma.html
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
275 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
276 db_.Execute("PRAGMA JOURNAL_MODE=WAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
277 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
278 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
279 //db_.Execute("PRAGMA TEMP_STORE=memory");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
280
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 if (!db_.DoesTableExist("GlobalProperties"))
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 LOG(INFO) << "Creating the database";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 std::string query;
203
9283552c25df db refactoring done
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
285 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 db_.Execute(query);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 521
diff changeset
289 // 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
290 std::string tmp;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
291 if (!LookupGlobalProperty(tmp, GlobalProperty_DatabaseSchemaVersion))
1239
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
292 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
293 tmp = "Unknown";
1239
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
294 }
92c6b3b57699 cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1238
diff changeset
295
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
296 bool ok = false;
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
297 try
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
298 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
299 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
300 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
301 ok = true;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
302 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
303 catch (boost::bad_lexical_cast&)
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
304 {
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
305 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
306
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
307 if (!ok)
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
308 {
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
309 LOG(ERROR) << "Incompatible version of the Orthanc database: " << tmp;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
310 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
311 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
312
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 db_.Register(signalRemainingAncestor_);
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
315 }
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
316
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
317
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
318 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
319 EmbeddedResources::FileResourceId script)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
320 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
321 std::string upgrade;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
322 EmbeddedResources::GetFileResource(upgrade, script);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
323 db.BeginTransaction();
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
324 db.Execute(upgrade);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
325 db.CommitTransaction();
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
326 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
327
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 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
330 IStorageArea& storageArea)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
331 {
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
332 if (targetVersion != 6)
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
333 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
334 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
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
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
337 // 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
338 // 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
339 if (version_ != 3 &&
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
340 version_ != 4 &&
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
341 version_ != 5 &&
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
342 version_ != 6)
1615
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 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
345 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
346
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 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
349 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
350 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
351 version_ = 4;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
352 }
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 if (version_ == 4)
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
355 {
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
356 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
357 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
358 version_ = 5;
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
359 }
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
360
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
361 if (version_ == 5)
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
362 {
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
363 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
364 // 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
365 // consists in reconstructing the main DICOM tags information
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
366 // (as more tags got included).
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
367 db_.BeginTransaction();
1710
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
368 Toolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Patient);
1669
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
369 Toolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Study);
a412ad57f0f9 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1668
diff changeset
370 Toolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Series);
1710
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
371 Toolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Instance);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
372 db_.Execute("UPDATE GlobalProperties SET value=\"6\" WHERE property=" +
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
373 boost::lexical_cast<std::string>(GlobalProperty_DatabaseSchemaVersion) + ";");
1668
de1413733c97 reconstructing main dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1665
diff changeset
374 db_.CommitTransaction();
1664
0c58f189782d prepare migration to db v6
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1615
diff changeset
375 version_ = 6;
1729
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1725
diff changeset
376 }
1615
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
377 }
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
378
c40fe92a68e7 Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1509
diff changeset
379
1432
0ac74fa21db8 rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1407
diff changeset
380 void DatabaseWrapper::SetListener(IDatabaseListener& listener)
1247
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
381 {
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
382 listener_ = &listener;
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
383 db_.Register(new Internals::SignalFileDeleted(listener));
32fcc5dc7562 abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1246
diff changeset
384 db_.Register(new Internals::SignalResourceDeleted(listener));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
386
413
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
387
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
388 void DatabaseWrapper::ClearTable(const std::string& tableName)
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
389 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
390 db_.Execute("DELETE FROM " + tableName);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
391 }
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
392
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
393
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
394 bool DatabaseWrapper::LookupParent(int64_t& parentId,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
395 int64_t resourceId)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
396 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
397 bool found;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
398 ErrorCode error = base_.LookupParent(found, parentId, resourceId);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
399
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
400 if (error != ErrorCode_Success)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
401 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
402 throw OrthancException(error);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
403 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
404 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
405 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
406 return found;
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 }
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
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
411 ResourceType DatabaseWrapper::GetResourceType(int64_t resourceId)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
412 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
413 ResourceType result;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
414 ErrorCode code = base_.GetResourceType(result, resourceId);
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 if (code == ErrorCode_Success)
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 return result;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
419 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
420 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
421 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
422 throw OrthancException(code);
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 }
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
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
427 std::string DatabaseWrapper::GetPublicId(int64_t resourceId)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
428 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
429 std::string id;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
430
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
431 if (base_.GetPublicId(id, resourceId))
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 return id;
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 else
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 throw OrthancException(ErrorCode_UnknownResource);
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 }
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
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
442 void DatabaseWrapper::GetChanges(std::list<ServerIndexChange>& target /*out*/,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
443 bool& done /*out*/,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
444 int64_t since,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
445 uint32_t maxResults)
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 ErrorCode code = base_.GetChanges(target, done, since, maxResults);
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 if (code != ErrorCode_Success)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
450 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
451 throw OrthancException(code);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
452 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
453 }
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
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
456 void DatabaseWrapper::GetLastChange(std::list<ServerIndexChange>& target /*out*/)
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
457 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
458 ErrorCode code = base_.GetLastChange(target);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
459
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
460 if (code != ErrorCode_Success)
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 throw OrthancException(code);
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 }
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
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
467 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
468 int64_t id)
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
469 {
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
470 target.clear();
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
471
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
472 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
473 s.BindInt64(0, id);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
474
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
475 while (s.Step())
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
476 {
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
477 MetadataType key = static_cast<MetadataType>(s.ColumnInt(0));
1301
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1300
diff changeset
478 target[key] = s.ColumnString(1);
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 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
481
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 }