annotate OrthancServer/DatabaseWrapper.cpp @ 588:a0001c222b32

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