annotate OrthancServer/DatabaseWrapper.cpp @ 1229:5405d36e9d48

explorer-plugin.js for plugins to adapt the default Orthanc Explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Nov 2014 13:54:53 +0100
parents 178de5edc0a8
children 0f3716b88af7
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
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 660
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
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"
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
37 #include "../Core/Uuid.h"
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "EmbeddedResources.h"
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <glog/logging.h>
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include <stdio.h>
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 namespace Orthanc
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 namespace Internals
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 class SignalFileDeleted : public SQLite::IScalarFunction
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 private:
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 IServerIndexListener& listener_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 public:
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 SignalFileDeleted(IServerIndexListener& listener) :
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 listener_(listener)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 virtual const char* GetName() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 return "SignalFileDeleted";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 virtual unsigned int GetCardinality() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
66 return 7;
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 virtual void Compute(SQLite::FunctionContext& context)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
71 std::string uncompressedMD5, compressedMD5;
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
72
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
73 if (!context.IsNullValue(5))
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 uncompressedMD5 = context.GetStringValue(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
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
78 if (!context.IsNullValue(6))
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 compressedMD5 = context.GetStringValue(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
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
83 FileInfo info(context.GetStringValue(0),
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
84 static_cast<FileContentType>(context.GetIntValue(1)),
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
85 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
86 uncompressedMD5,
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
87 static_cast<CompressionType>(context.GetIntValue(3)),
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
88 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
89 compressedMD5);
273
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
90
d384af918264 more detailed signal about deleted file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 268
diff changeset
91 listener_.SignalFileDeleted(info);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 };
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
95 class SignalResourceDeleted : public SQLite::IScalarFunction
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
96 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
97 private:
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
98 IServerIndexListener& listener_;
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
99
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
100 public:
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
101 SignalResourceDeleted(IServerIndexListener& listener) :
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
102 listener_(listener)
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
103 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
104 }
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 virtual const char* GetName() const
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 return "SignalResourceDeleted";
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
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
111 virtual unsigned int GetCardinality() const
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 return 2;
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
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
116 virtual void Compute(SQLite::FunctionContext& context)
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 ResourceType type = static_cast<ResourceType>(context.GetIntValue(1));
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
119 ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
120 listener_.SignalChange(change);
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
121 }
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
122 };
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
123
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 class SignalRemainingAncestor : public SQLite::IScalarFunction
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 private:
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 bool hasRemainingAncestor_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 std::string remainingPublicId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 ResourceType remainingType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 public:
660
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
132 SignalRemainingAncestor() :
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
133 hasRemainingAncestor_(false)
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
134 {
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
135 }
f0232774b913 fix warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 616
diff changeset
136
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 void Reset()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 hasRemainingAncestor_ = false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 virtual const char* GetName() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 return "SignalRemainingAncestor";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 virtual unsigned int GetCardinality() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 return 2;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 virtual void Compute(SQLite::FunctionContext& context)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 VLOG(1) << "There exists a remaining ancestor with public ID \""
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 << context.GetStringValue(0)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 << "\" of type "
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 << context.GetIntValue(1);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 if (!hasRemainingAncestor_ ||
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 remainingType_ >= context.GetIntValue(1))
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 hasRemainingAncestor_ = true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 remainingPublicId_ = context.GetStringValue(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 remainingType_ = static_cast<ResourceType>(context.GetIntValue(1));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 bool HasRemainingAncestor() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 return hasRemainingAncestor_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 const std::string& GetRemainingAncestorId() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 assert(hasRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 return remainingPublicId_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 ResourceType GetRemainingAncestorType() const
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 assert(hasRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 return remainingType_;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 };
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
189 void DatabaseWrapper::SetGlobalProperty(GlobalProperty property,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 const std::string& value)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO GlobalProperties VALUES(?, ?)");
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
193 s.BindInt(0, property);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 s.BindString(1, value);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
198 bool DatabaseWrapper::LookupGlobalProperty(std::string& target,
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
199 GlobalProperty property)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 SQLite::Statement s(db_, SQLITE_FROM_HERE,
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
202 "SELECT value FROM GlobalProperties WHERE property=?");
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
203 s.BindInt(0, property);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (!s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 target = s.ColumnString(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
216 std::string DatabaseWrapper::GetGlobalProperty(GlobalProperty property,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 const std::string& defaultValue)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 std::string s;
206
4453a010d0db flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 205
diff changeset
220 if (LookupGlobalProperty(s, property))
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 return s;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 return defaultValue;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 int64_t DatabaseWrapper::CreateResource(const std::string& publicId,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 ResourceType type)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Resources VALUES(NULL, ?, ?, NULL)");
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 s.BindInt(0, type);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 s.BindString(1, publicId);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 s.Run();
189
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
237 int64_t id = db_.GetLastInsertRowId();
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
238
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
239 ChangeType changeType;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
240 switch (type)
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
241 {
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
242 case ResourceType_Patient:
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
243 changeType = ChangeType_NewPatient;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
244 break;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
245
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
246 case ResourceType_Study:
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
247 changeType = ChangeType_NewStudy;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
248 break;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
249
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
250 case ResourceType_Series:
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
251 changeType = ChangeType_NewSeries;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
252 break;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
253
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
254 case ResourceType_Instance:
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
255 changeType = ChangeType_NewInstance;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
256 break;
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
257
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
258 default:
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
259 throw OrthancException(ErrorCode_InternalError);
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
260 }
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
261
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
262 LogChange(id, changeType, type, publicId);
189
ccbc2cf64a0d record main dicom tags and changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 188
diff changeset
263 return id;
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
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
266 bool DatabaseWrapper::LookupResource(const std::string& publicId,
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
267 int64_t& id,
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
268 ResourceType& type)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 SQLite::Statement s(db_, SQLITE_FROM_HERE,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 "SELECT internalId, resourceType FROM Resources WHERE publicId=?");
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 s.BindString(0, publicId);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 if (!s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 id = s.ColumnInt(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 type = static_cast<ResourceType>(s.ColumnInt(1));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 // Check whether there is a single resource with this public id
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 assert(!s.Step());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
290 bool DatabaseWrapper::LookupParent(int64_t& parentId,
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
291 int64_t resourceId)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
292 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
293 SQLite::Statement s(db_, SQLITE_FROM_HERE,
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
294 "SELECT parentId FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
295 s.BindInt64(0, resourceId);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
296
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
297 if (!s.Step())
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
298 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
299 throw OrthancException(ErrorCode_UnknownResource);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
300 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
301
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
302 if (s.ColumnIsNull(0))
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
303 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
304 return false;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
305 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
306 else
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
307 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
308 parentId = s.ColumnInt(0);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
309 return true;
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
310 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
311 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
312
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
313 std::string DatabaseWrapper::GetPublicId(int64_t resourceId)
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
314 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
315 SQLite::Statement s(db_, SQLITE_FROM_HERE,
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
316 "SELECT publicId FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
317 s.BindInt64(0, resourceId);
198
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
318
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
319 if (!s.Step())
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
320 {
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
321 throw OrthancException(ErrorCode_UnknownResource);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
322 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
323
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
324 return s.ColumnString(0);
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
325 }
663cc6c46d0a before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 197
diff changeset
326
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
327
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
328 ResourceType DatabaseWrapper::GetResourceType(int64_t resourceId)
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
329 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
330 SQLite::Statement s(db_, SQLITE_FROM_HERE,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
331 "SELECT resourceType FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
332 s.BindInt64(0, resourceId);
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
333
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
334 if (!s.Step())
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
335 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
336 throw OrthancException(ErrorCode_UnknownResource);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
337 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
338
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
339 return static_cast<ResourceType>(s.ColumnInt(0));
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
340 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
341
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 273
diff changeset
342
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 void DatabaseWrapper::AttachChild(int64_t parent,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 int64_t child)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 SQLite::Statement s(db_, SQLITE_FROM_HERE, "UPDATE Resources SET parentId = ? WHERE internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
347 s.BindInt64(0, parent);
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
348 s.BindInt64(1, child);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
352 void DatabaseWrapper::GetChildren(Json::Value& childrenPublicIds,
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
353 int64_t id)
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
354 {
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
355 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE parentId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
356 s.BindInt64(0, id);
193
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
357
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
358 childrenPublicIds = Json::arrayValue;
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
359 while (s.Step())
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
360 {
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
361 childrenPublicIds.append(s.ColumnString(0));
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
362 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
363 }
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
364
a1b9d1e1497b failed attempt to compile with linux standard base
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 192
diff changeset
365
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 void DatabaseWrapper::DeleteResource(int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 signalRemainingAncestor_->Reset();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
371 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 if (signalRemainingAncestor_->HasRemainingAncestor())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 listener_.SignalRemainingAncestor(signalRemainingAncestor_->GetRemainingAncestorType(),
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 signalRemainingAncestor_->GetRemainingAncestorId());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 void DatabaseWrapper::SetMetadata(int64_t id,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 MetadataType type,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 const std::string& value)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO Metadata VALUES(?, ?, ?)");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
386 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 s.BindInt(1, type);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 s.BindString(2, value);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
438
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
392 void DatabaseWrapper::DeleteMetadata(int64_t id,
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
393 MetadataType type)
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
394 {
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
395 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Metadata WHERE id=? and type=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
396 s.BindInt64(0, id);
438
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
397 s.BindInt(1, type);
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
398 s.Run();
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
399 }
7bbe77cb9e12 DELETE metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 436
diff changeset
400
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
401 bool DatabaseWrapper::LookupMetadata(std::string& target,
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
402 int64_t id,
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
403 MetadataType type)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 SQLite::Statement s(db_, SQLITE_FROM_HERE,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 "SELECT value FROM Metadata WHERE id=? AND type=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
407 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 s.BindInt(1, type);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 if (!s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 target = s.ColumnString(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420
739
696dbb4fd390 api uniformization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 701
diff changeset
421 void DatabaseWrapper::ListAvailableMetadata(std::list<MetadataType>& target,
436
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
422 int64_t id)
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
423 {
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
424 target.clear();
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
425
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
426 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT type FROM Metadata WHERE id=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
427 s.BindInt64(0, id);
436
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
428
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
429 while (s.Step())
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
430 {
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
431 target.push_back(static_cast<MetadataType>(s.ColumnInt(0)));
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
432 }
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
433 }
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
434
d51186bf7602 read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 434
diff changeset
435
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 std::string DatabaseWrapper::GetMetadata(int64_t id,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 MetadataType type,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 const std::string& defaultValue)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 std::string s;
188
090cefdab1d1 fix because of Windows macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 187
diff changeset
441 if (LookupMetadata(s, id, type))
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 return s;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 return defaultValue;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
200
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
451
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
452 bool DatabaseWrapper::GetMetadataAsInteger(int& result,
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
453 int64_t id,
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
454 MetadataType type)
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
455 {
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
456 std::string s = GetMetadata(id, type, "");
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
457 if (s.size() == 0)
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
458 {
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
459 return false;
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
460 }
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
461
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
462 try
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
463 {
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
464 result = boost::lexical_cast<int>(s);
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
465 return true;
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
466 }
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
467 catch (boost::bad_lexical_cast&)
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
468 {
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
469 return false;
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
470 }
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
471 }
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
472
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
473
9c58b2b03cf0 refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 199
diff changeset
474
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
475 void DatabaseWrapper::AddAttachment(int64_t id,
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
476 const FileInfo& attachment)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 {
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
478 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
479 s.BindInt64(0, id);
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
480 s.BindInt(1, attachment.GetContentType());
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
481 s.BindString(2, attachment.GetUuid());
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
482 s.BindInt64(3, attachment.GetCompressedSize());
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
483 s.BindInt64(4, attachment.GetUncompressedSize());
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
484 s.BindInt(5, attachment.GetCompressionType());
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
485 s.BindString(6, attachment.GetUncompressedMD5());
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
486 s.BindString(7, attachment.GetCompressedMD5());
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
490
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
491 void DatabaseWrapper::DeleteAttachment(int64_t id,
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
492 FileContentType attachment)
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
493 {
701
f9052558eada fix attachment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 699
diff changeset
494 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM AttachedFiles WHERE id=? AND fileType=?");
699
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
495 s.BindInt64(0, id);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
496 s.BindInt(1, attachment);
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
497 s.Run();
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
498 }
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
499
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
500
2929e17f8447 add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 694
diff changeset
501
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
502 void DatabaseWrapper::ListAvailableAttachments(std::list<FileContentType>& result,
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
503 int64_t id)
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
504 {
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
505 result.clear();
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
506
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
507 SQLite::Statement s(db_, SQLITE_FROM_HERE,
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
508 "SELECT fileType FROM AttachedFiles WHERE id=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
509 s.BindInt64(0, id);
440
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
510
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
511 while (s.Step())
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
512 {
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
513 result.push_back(static_cast<FileContentType>(s.ColumnInt(0)));
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
514 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
515 }
23e5b35e3c5c statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 438
diff changeset
516
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
517 bool DatabaseWrapper::LookupAttachment(FileInfo& attachment,
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
518 int64_t id,
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
519 FileContentType contentType)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 SQLite::Statement s(db_, SQLITE_FROM_HERE,
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
522 "SELECT uuid, uncompressedSize, compressionType, compressedSize, uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
523 s.BindInt64(0, id);
197
530a25320461 removal of text as ids in sqlite db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
524 s.BindInt(1, contentType);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 if (!s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 {
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
532 attachment = FileInfo(s.ColumnString(0),
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
533 contentType,
740
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 739
diff changeset
534 s.ColumnInt64(1),
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
535 s.ColumnString(4),
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
536 static_cast<CompressionType>(s.ColumnInt(2)),
740
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 739
diff changeset
537 s.ColumnInt64(3),
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
538 s.ColumnString(5));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
543
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
544 static void SetMainDicomTagsInternal(SQLite::Statement& s,
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
545 int64_t id,
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
546 const DicomElement& element)
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
547 {
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
548 s.BindInt64(0, id);
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
549 s.BindInt(1, element.GetTag().GetGroup());
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
550 s.BindInt(2, element.GetTag().GetElement());
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
551 s.BindString(3, element.GetValue().AsString());
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
552 s.Run();
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
553 }
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
554
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
555
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 void DatabaseWrapper::SetMainDicomTags(int64_t id,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 const DicomMap& tags)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 DicomArray flattened(tags);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 for (size_t i = 0; i < flattened.GetSize(); i++)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 {
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
562 if (flattened.GetElement(i).GetTag().IsIdentifier())
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
563 {
1173
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1162
diff changeset
564 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifiers VALUES(?, ?, ?, ?)");
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
565 SetMainDicomTagsInternal(s, id, flattened.GetElement(i));
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
566 }
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
567 else
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
568 {
1173
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1162
diff changeset
569 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)");
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
570 SetMainDicomTagsInternal(s, id, flattened.GetElement(i));
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
571 }
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 void DatabaseWrapper::GetMainDicomTags(DicomMap& map,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 map.Clear();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM MainDicomTags WHERE id=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
581 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 while (s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 map.SetValue(s.ColumnInt(1),
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 s.ColumnInt(2),
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 s.ColumnString(3));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 }
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
588
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
589 SQLite::Statement s2(db_, SQLITE_FROM_HERE, "SELECT * FROM DicomIdentifiers WHERE id=?");
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
590 s2.BindInt64(0, id);
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
591 while (s2.Step())
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
592 {
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
593 map.SetValue(s2.ColumnInt(1),
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
594 s2.ColumnInt(2),
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
595 s2.ColumnString(3));
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
596 }
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 bool DatabaseWrapper::GetParentPublicId(std::string& result,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 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
604 "WHERE a.internalId = b.parentId AND b.internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
605 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 if (s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 result = s.ColumnString(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 return true;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 else
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 return false;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 void DatabaseWrapper::GetChildrenPublicId(std::list<std::string>& result,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 int64_t id)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 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
623 "WHERE a.parentId = b.internalId AND b.internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
624 s.BindInt64(0, id);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 result.clear();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 while (s.Step())
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 result.push_back(s.ColumnString(0));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
635 void DatabaseWrapper::GetChildrenInternalId(std::list<int64_t>& result,
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
636 int64_t id)
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
637 {
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
638 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.internalId FROM Resources AS a, Resources AS b "
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
639 "WHERE a.parentId = b.internalId AND b.internalId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
640 s.BindInt64(0, id);
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
641
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
642 result.clear();
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
643
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
644 while (s.Step())
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
645 {
741
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 740
diff changeset
646 result.push_back(s.ColumnInt64(0));
199
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
647 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
648 }
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
649
dfa2899d9960 refactoring cont
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 198
diff changeset
650
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
651 void DatabaseWrapper::LogChange(int64_t internalId,
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
652 const ServerIndexChange& change)
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 {
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
654 if (change.GetChangeType() <= ChangeType_INTERNAL_LastLogged)
1177
5b2d8c280ac2 Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1173
diff changeset
655 {
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1177
diff changeset
656 const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
1177
5b2d8c280ac2 Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1173
diff changeset
657
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1177
diff changeset
658 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)");
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
659 s.BindInt(0, change.GetChangeType());
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1177
diff changeset
660 s.BindInt64(1, internalId);
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
661 s.BindInt(2, change.GetResourceType());
1189
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1177
diff changeset
662 s.BindString(3, boost::posix_time::to_iso_string(now));
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1177
diff changeset
663 s.Run();
6b9b02a16e99 NewChildInstance change type
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1177
diff changeset
664 }
1177
5b2d8c280ac2 Plugins can monitor changes through callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1173
diff changeset
665
1198
1169528a9a5f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1189
diff changeset
666 listener_.SignalChange(change);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
670 void DatabaseWrapper::GetChangesInternal(Json::Value& target,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
671 SQLite::Statement& s,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
672 int64_t since,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
673 unsigned int maxResults)
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
674 {
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
675 Json::Value changes = Json::arrayValue;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
676 int64_t last = since;
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
677
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
678 while (changes.size() < maxResults && s.Step())
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
679 {
742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
680 int64_t seq = s.ColumnInt64(0);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
681 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1));
742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
682 int64_t internalId = s.ColumnInt64(2);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
683 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3));
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
684 const std::string& date = s.ColumnString(4);
205
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
685 std::string publicId = GetPublicId(internalId);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
686
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
687 Json::Value item = Json::objectValue;
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
688 item["Seq"] = static_cast<int>(seq);
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 413
diff changeset
689 item["ChangeType"] = EnumerationToString(changeType);
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 413
diff changeset
690 item["ResourceType"] = EnumerationToString(resourceType);
205
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
691 item["ID"] = publicId;
6ab754744446 logging of completed series
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 204
diff changeset
692 item["Path"] = GetBasePath(resourceType, publicId);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
693 item["Date"] = date;
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
694 last = seq;
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
695
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
696 changes.append(item);
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
697 }
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
698
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
699 target = Json::objectValue;
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
700 target["Changes"] = changes;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
701 target["Done"] = !(changes.size() == maxResults && s.Step());
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
702 target["Last"] = static_cast<int>(last);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
703 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
704
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
705
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
706 void DatabaseWrapper::GetChanges(Json::Value& target,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
707 int64_t since,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
708 unsigned int maxResults)
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
709 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
710 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes WHERE seq>? ORDER BY seq LIMIT ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
711 s.BindInt64(0, since);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
712 s.BindInt(1, maxResults + 1);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
713 GetChangesInternal(target, s, since, maxResults);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
714 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
715
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
716 void DatabaseWrapper::GetLastChange(Json::Value& target)
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
717 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
718 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1");
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
719 GetChangesInternal(target, s, 0, 1);
204
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
720 }
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
721
7f4acf490179 changes api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
722
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
723 void DatabaseWrapper::LogExportedResource(ResourceType resourceType,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
724 const std::string& publicId,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
725 const std::string& remoteModality,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
726 const std::string& patientId,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
727 const std::string& studyInstanceUid,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
728 const std::string& seriesInstanceUid,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
729 const std::string& sopInstanceUid,
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 const boost::posix_time::ptime& date)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 {
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
732 SQLite::Statement s(db_, SQLITE_FROM_HERE,
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
733 "INSERT INTO ExportedResources VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)");
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
734
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
735 s.BindInt(0, resourceType);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
736 s.BindString(1, publicId);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
737 s.BindString(2, remoteModality);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
738 s.BindString(3, patientId);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
739 s.BindString(4, studyInstanceUid);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
740 s.BindString(5, seriesInstanceUid);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
741 s.BindString(6, sopInstanceUid);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
742 s.BindString(7, boost::posix_time::to_iso_string(date));
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
743
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 }
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
746
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
747
742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
748 void DatabaseWrapper::GetExportedResourcesInternal(Json::Value& target,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
749 SQLite::Statement& s,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
750 int64_t since,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
751 unsigned int maxResults)
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
752 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
753 Json::Value changes = Json::arrayValue;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
754 int64_t last = since;
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
755
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
756 while (changes.size() < maxResults && s.Step())
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
757 {
743
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 742
diff changeset
758 int64_t seq = s.ColumnInt64(0);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
759 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1));
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
760 std::string publicId = s.ColumnString(2);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
761
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
762 Json::Value item = Json::objectValue;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
763 item["Seq"] = static_cast<int>(seq);
434
ccf3a0a43dac EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 413
diff changeset
764 item["ResourceType"] = EnumerationToString(resourceType);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
765 item["ID"] = publicId;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
766 item["Path"] = GetBasePath(resourceType, publicId);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
767 item["RemoteModality"] = s.ColumnString(3);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
768 item["Date"] = s.ColumnString(8);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
769
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
770 // WARNING: Do not add "break" below and do not reorder the case items!
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
771 switch (resourceType)
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
772 {
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
773 case ResourceType_Instance:
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
774 item["SopInstanceUid"] = s.ColumnString(7);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
775
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
776 case ResourceType_Series:
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
777 item["SeriesInstanceUid"] = s.ColumnString(6);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
778
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
779 case ResourceType_Study:
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
780 item["StudyInstanceUid"] = s.ColumnString(5);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
781
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
782 case ResourceType_Patient:
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
783 item["PatientId"] = s.ColumnString(4);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
784 break;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
785
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
786 default:
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
787 throw OrthancException(ErrorCode_InternalError);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
788 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
789
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
790 last = seq;
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
791
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
792 changes.append(item);
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
793 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
794
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
795 target = Json::objectValue;
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
796 target["Exports"] = changes;
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
797 target["Done"] = !(changes.size() == maxResults && s.Step());
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
798 target["Last"] = static_cast<int>(last);
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
799 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
800
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
801
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
802 void DatabaseWrapper::GetExportedResources(Json::Value& target,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
803 int64_t since,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
804 unsigned int maxResults)
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
805 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
806 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
807 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
808 s.BindInt64(0, since);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
809 s.BindInt(1, maxResults + 1);
742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
810 GetExportedResourcesInternal(target, s, since, maxResults);
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
811 }
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
812
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
813
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
814 void DatabaseWrapper::GetLastExportedResource(Json::Value& target)
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
815 {
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
816 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
817 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1");
742
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 741
diff changeset
818 GetExportedResourcesInternal(target, s, 0, 1);
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
819 }
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
820
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 218
diff changeset
821
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 int64_t DatabaseWrapper::GetTableRecordCount(const std::string& table)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 char buf[128];
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 sprintf(buf, "SELECT COUNT(*) FROM %s", table.c_str());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 SQLite::Statement s(db_, buf);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829
218
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
830 if (!s.Step())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
831 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
832 throw OrthancException(ErrorCode_InternalError);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
833 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 206
diff changeset
834
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 int64_t c = s.ColumnInt(0);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 assert(!s.Step());
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 return c;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 uint64_t DatabaseWrapper::GetTotalCompressedSize()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(compressedSize) FROM AttachedFiles");
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 return static_cast<uint64_t>(s.ColumnInt64(0));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 uint64_t DatabaseWrapper::GetTotalUncompressedSize()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(uncompressedSize) FROM AttachedFiles");
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 s.Run();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 return static_cast<uint64_t>(s.ColumnInt64(0));
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856
190
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
857 void DatabaseWrapper::GetAllPublicIds(Json::Value& target,
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
858 ResourceType resourceType)
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
859 {
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
860 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE resourceType=?");
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
861 s.BindInt(0, resourceType);
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
862
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
863 target = Json::arrayValue;
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
864 while (s.Step())
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
865 {
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
866 target.append(s.ColumnString(0));
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
867 }
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
868 }
b6cef9d45cc3 getallpublicids
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 189
diff changeset
869
1210
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
870 static void UpgradeDatabase(SQLite::Connection& db,
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
871 EmbeddedResources::FileResourceId script)
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
872 {
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
873 std::string upgrade;
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
874 EmbeddedResources::GetFileResource(upgrade, script);
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
875 db.BeginTransaction();
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
876 db.Execute(upgrade);
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
877 db.CommitTransaction();
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
878 }
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
879
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 DatabaseWrapper::DatabaseWrapper(const std::string& path,
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 IServerIndexListener& listener) :
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 listener_(listener)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 db_.Open(path);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 Open();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 DatabaseWrapper::DatabaseWrapper(IServerIndexListener& listener) :
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 listener_(listener)
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 db_.OpenInMemory();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 Open();
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 void DatabaseWrapper::Open()
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 {
374
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
898 // Performance tuning of SQLite with PRAGMAs
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
899 // http://www.sqlite.org/pragma.html
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
900 db_.Execute("PRAGMA SYNCHRONOUS=NORMAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
901 db_.Execute("PRAGMA JOURNAL_MODE=WAL;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
902 db_.Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
903 db_.Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
904 //db_.Execute("PRAGMA TEMP_STORE=memory");
42e87c17cab8 some refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 310
diff changeset
905
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 if (!db_.DoesTableExist("GlobalProperties"))
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 {
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 LOG(INFO) << "Creating the database";
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 std::string query;
203
9283552c25df db refactoring done
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 200
diff changeset
910 EmbeddedResources::GetFileResource(query, EmbeddedResources::PREPARE_DATABASE);
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 db_.Execute(query);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 }
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913
567
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 521
diff changeset
914 // Check the version of the database
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
915 std::string version = GetGlobalProperty(GlobalProperty_DatabaseSchemaVersion, "Unknown");
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
916 bool ok = false;
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
917 try
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
918 {
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
919 LOG(INFO) << "Version of the Orthanc database: " << version;
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
920 unsigned int v = boost::lexical_cast<unsigned int>(version);
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
921
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
922 /**
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
923 * History of the database versions:
1210
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
924 * - Orthanc before Orthanc 0.3.0 (inclusive) had no version
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
925 * - Version 2: only Orthanc 0.3.1
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
926 * - Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive)
1210
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
927 * - Version 4: from Orthanc 0.7.3 to Orthanc 0.8.4 (inclusive)
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
928 * - Version 5: from Orthanc 0.8.5 (inclusive)
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
929 **/
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
930
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
931 // This version of Orthanc is only compatible with versions 3, 4 and 5 of the DB schema
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
932 ok = (v == 3 || v == 4 || v == 5);
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
933
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
934 if (v == 3)
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
935 {
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
936 LOG(WARNING) << "Upgrading database version from 3 to 4";
1210
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
937 UpgradeDatabase(db_, EmbeddedResources::UPGRADE_DATABASE_3_TO_4);
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
938 v = 4;
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
939 }
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
940
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
941 if (v == 4)
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
942 {
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
943 LOG(WARNING) << "Upgrading database version from 4 to 5";
1210
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
944 UpgradeDatabase(db_, EmbeddedResources::UPGRADE_DATABASE_4_TO_5);
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
945 v = 5;
694
72dc919a028c upgrade database from v3 to v4
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 693
diff changeset
946 }
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
947 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
948 catch (boost::bad_lexical_cast&)
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
949 {
1210
178de5edc0a8 comments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1198
diff changeset
950 ok = false;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
951 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
952
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
953 if (!ok)
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
954 {
693
01d8611c4a60 md5 for attached files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
955 LOG(ERROR) << "Incompatible version of the Orthanc database: " << version;
252
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
956 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion);
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
957 }
bd009f0b1931 db version
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 238
diff changeset
958
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 signalRemainingAncestor_ = new Internals::SignalRemainingAncestor;
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 db_.Register(signalRemainingAncestor_);
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 db_.Register(new Internals::SignalFileDeleted(listener_));
1158
badc14fee61f speed up db
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1006
diff changeset
962 db_.Register(new Internals::SignalResourceDeleted(listener_));
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 }
238
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
964
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
965 uint64_t DatabaseWrapper::GetResourceCount(ResourceType resourceType)
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
966 {
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
967 SQLite::Statement s(db_, SQLITE_FROM_HERE,
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
968 "SELECT COUNT(*) FROM Resources WHERE resourceType=?");
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
969 s.BindInt(0, resourceType);
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
970
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
971 if (!s.Step())
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
972 {
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
973 throw OrthancException(ErrorCode_InternalError);
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
974 }
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
975
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
976 int64_t c = s.ColumnInt(0);
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
977 assert(!s.Step());
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
978
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
979 return c;
e4148b0ab1d0 statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
980 }
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
981
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
982 bool DatabaseWrapper::SelectPatientToRecycle(int64_t& internalId)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
983 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
984 SQLite::Statement s(db_, SQLITE_FROM_HERE,
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
985 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1");
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
986
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
987 if (!s.Step())
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
988 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
989 // No patient remaining or all the patients are protected
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
990 return false;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
991 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
992 else
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
993 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
994 internalId = s.ColumnInt(0);
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
995 return true;
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
996 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
997 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
998
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
999 bool DatabaseWrapper::SelectPatientToRecycle(int64_t& internalId,
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1000 int64_t patientIdToAvoid)
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1001 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1002 SQLite::Statement s(db_, SQLITE_FROM_HERE,
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1003 "SELECT patientId FROM PatientRecyclingOrder "
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1004 "WHERE patientId != ? ORDER BY seq ASC LIMIT 1");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
1005 s.BindInt64(0, patientIdToAvoid);
268
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1006
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1007 if (!s.Step())
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1008 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1009 // No patient remaining or all the patients are protected
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1010 return false;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1011 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1012 else
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1013 {
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1014 internalId = s.ColumnInt(0);
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1015 return true;
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1016 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1017 }
4bc02e2254ec preparing ServerIndex for recycling
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 262
diff changeset
1018
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1019 bool DatabaseWrapper::IsProtectedPatient(int64_t internalId)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1020 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1021 SQLite::Statement s(db_, SQLITE_FROM_HERE,
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1022 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
1023 s.BindInt64(0, internalId);
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1024 return !s.Step();
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1025 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1026
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1027 void DatabaseWrapper::SetProtectedPatient(int64_t internalId,
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1028 bool isProtected)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1029 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1030 if (isProtected)
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1031 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1032 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM PatientRecyclingOrder WHERE patientId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
1033 s.BindInt64(0, internalId);
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1034 s.Run();
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1035 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1036 else if (IsProtectedPatient(internalId))
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1037 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1038 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO PatientRecyclingOrder VALUES(NULL, ?)");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
1039 s.BindInt64(0, internalId);
262
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1040 s.Run();
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1041 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1042 else
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1043 {
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1044 // Nothing to do: The patient is already unprotected
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1045 }
2354560daf2f primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
1046 }
310
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1047
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1048
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1049 uint64_t DatabaseWrapper::IncrementGlobalSequence(GlobalProperty property)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1050 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1051 std::string oldValue;
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1052
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1053 if (LookupGlobalProperty(oldValue, property))
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1054 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1055 uint64_t oldNumber;
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1056
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1057 try
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1058 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1059 oldNumber = boost::lexical_cast<uint64_t>(oldValue);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1060 SetGlobalProperty(property, boost::lexical_cast<std::string>(oldNumber + 1));
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1061 return oldNumber + 1;
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1062 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1063 catch (boost::bad_lexical_cast&)
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1064 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1065 throw OrthancException(ErrorCode_InternalError);
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1066 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1067 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1068 else
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1069 {
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1070 // Initialize the sequence at "1"
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1071 SetGlobalProperty(property, "1");
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1072 return 1;
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1073 }
6ab6cdeedf4e global sequences
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
1074 }
413
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1075
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1076
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1077 void DatabaseWrapper::ClearTable(const std::string& tableName)
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1078 {
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1079 db_.Execute("DELETE FROM " + tableName);
47d63c941902 clearing /exports and /changes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
1080 }
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1081
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1082
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1083 bool DatabaseWrapper::IsExistingResource(int64_t internalId)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1084 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1085 SQLite::Statement s(db_, SQLITE_FROM_HERE,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1086 "SELECT * FROM Resources WHERE internalId=?");
585
b2357f1f026f fix types
jodogne
parents: 521
diff changeset
1087 s.BindInt64(0, internalId);
513
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1088 return s.Step();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
1089 }
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1090
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1091
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1092 void DatabaseWrapper::LookupIdentifier(std::list<int64_t>& result,
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1093 const DicomTag& tag,
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1094 const std::string& value)
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1095 {
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1096 if (!tag.IsIdentifier())
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1097 {
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1098 throw OrthancException(ErrorCode_ParameterOutOfRange);
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1099 }
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1100
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1101 SQLite::Statement s(db_, SQLITE_FROM_HERE,
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1102 "SELECT id FROM DicomIdentifiers WHERE tagGroup=? AND tagElement=? and value=?");
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1103
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1104 s.BindInt(0, tag.GetGroup());
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1105 s.BindInt(1, tag.GetElement());
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1106 s.BindString(2, value);
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1107
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1108 result.clear();
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1109
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1110 while (s.Step())
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1111 {
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1112 result.push_back(s.ColumnInt64(0));
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1113 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1114 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1115
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1116
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1117 void DatabaseWrapper::LookupIdentifier(std::list<int64_t>& result,
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1118 const std::string& value)
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1119 {
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1120 SQLite::Statement s(db_, SQLITE_FROM_HERE,
1162
1ea4094d077c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1158
diff changeset
1121 "SELECT id FROM DicomIdentifiers WHERE value=?");
521
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1122
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1123 s.BindString(0, value);
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1124
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1125 result.clear();
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1126
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1127 while (s.Step())
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1128 {
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1129 result.push_back(s.ColumnInt64(0));
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1130 }
2c739f76d0bb lookup tag values
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 513
diff changeset
1131 }
1006
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1132
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1133
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1134 void DatabaseWrapper::GetAllMetadata(std::map<MetadataType, std::string>& result,
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1135 int64_t id)
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1136 {
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1137 result.clear();
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1138
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1139 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
1140 s.BindInt64(0, id);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1141
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1142 while (s.Step())
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1143 {
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1144 MetadataType key = static_cast<MetadataType>(s.ColumnInt(0));
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1145 result[key] = s.ColumnString(1);
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1146 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1147 }
649d47854314 proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 831
diff changeset
1148
183
baada606da3c databasewrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 }