annotate OrthancServer/Resources/Graveyard/DatabasePluginSample/DatabaseWrapperBase.cpp @ 4870:43e613a7756b

upgrade to year 2022
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Jan 2022 11:15:42 +0100
parents 7053502fbf97
children 6eff25f70121
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1761
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4870
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
43e613a7756b upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4831
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * In addition, as a special exception, the copyright holders of this
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * program give permission to link the code of its release with the
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * OpenSSL project's "OpenSSL" library (or with modified versions of it
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * that use the same license as the "OpenSSL" library), and distribute
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * the linked executables. You must obey the GNU General Public License
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * in all respects for all of the code used other than "OpenSSL". If you
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * modify file(s) with this exception, you may extend this exception to
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * your version of the file(s), but you are not obligated to do so. If
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * you do not wish to do so, delete this exception statement from your
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * version. If you delete this exception statement from all source files
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * in the program, then also delete it here.
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 *
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * This program is distributed in the hope that it will be useful, but
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * General Public License for more details.
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 *
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * You should have received a copy of the GNU General Public License
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 **/
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
4050
cd363608551a fix paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
35 #include "../../../Sources/PrecompiledHeadersServer.h"
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "DatabaseWrapperBase.h"
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <stdio.h>
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
39 #include <memory>
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 namespace Orthanc
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 void DatabaseWrapperBase::SetGlobalProperty(GlobalProperty property,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 const std::string& value)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO GlobalProperties VALUES(?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 s.BindInt(0, property);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 s.BindString(1, value);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 bool DatabaseWrapperBase::LookupGlobalProperty(std::string& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 GlobalProperty property)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 "SELECT value FROM GlobalProperties WHERE property=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 s.BindInt(0, property);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 target = s.ColumnString(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 int64_t DatabaseWrapperBase::CreateResource(const std::string& publicId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ResourceType type)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Resources VALUES(NULL, ?, ?, NULL)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 s.BindInt(0, type);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 s.BindString(1, publicId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 return db_.GetLastInsertRowId();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 bool DatabaseWrapperBase::LookupResource(int64_t& id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 ResourceType& type,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 const std::string& publicId)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 "SELECT internalId, resourceType FROM Resources WHERE publicId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 s.BindString(0, publicId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 id = s.ColumnInt(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 type = static_cast<ResourceType>(s.ColumnInt(1));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 // Check whether there is a single resource with this public id
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 assert(!s.Step());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
104 ErrorCode DatabaseWrapperBase::LookupParent(bool& found,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
105 int64_t& parentId,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
106 int64_t resourceId)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 "SELECT parentId FROM Resources WHERE internalId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 s.BindInt64(0, resourceId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
114 return ErrorCode_UnknownResource;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 if (s.ColumnIsNull(0))
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
119 found = false;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
123 found = true;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 parentId = s.ColumnInt(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
126
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
127 return ErrorCode_Success;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
130 bool DatabaseWrapperBase::GetPublicId(std::string& result,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
131 int64_t resourceId)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 "SELECT publicId FROM Resources WHERE internalId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 s.BindInt64(0, resourceId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
139 return false;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
141 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
142 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
143 result = s.ColumnString(0);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
144 return true;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
145 }
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
149 ErrorCode DatabaseWrapperBase::GetResourceType(ResourceType& result,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
150 int64_t resourceId)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 "SELECT resourceType FROM Resources WHERE internalId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 s.BindInt64(0, resourceId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
156 if (s.Step())
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
157 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
158 result = static_cast<ResourceType>(s.ColumnInt(0));
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
159 return ErrorCode_Success;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
160 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
161 else
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
163 return ErrorCode_UnknownResource;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 void DatabaseWrapperBase::AttachChild(int64_t parent,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 int64_t child)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 SQLite::Statement s(db_, SQLITE_FROM_HERE, "UPDATE Resources SET parentId = ? WHERE internalId = ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 s.BindInt64(0, parent);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 s.BindInt64(1, child);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 void DatabaseWrapperBase::SetMetadata(int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 MetadataType type,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 const std::string& value)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO Metadata VALUES(?, ?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 s.BindInt(1, type);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 s.BindString(2, value);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 void DatabaseWrapperBase::DeleteMetadata(int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 MetadataType type)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Metadata WHERE id=? and type=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 s.BindInt(1, type);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 bool DatabaseWrapperBase::LookupMetadata(std::string& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 MetadataType type)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 "SELECT value FROM Metadata WHERE id=? AND type=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 s.BindInt(1, type);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 target = s.ColumnString(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 void DatabaseWrapperBase::ListAvailableMetadata(std::list<MetadataType>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT type FROM Metadata WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 target.push_back(static_cast<MetadataType>(s.ColumnInt(0)));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 void DatabaseWrapperBase::AddAttachment(int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 const FileInfo& attachment)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 s.BindInt(1, attachment.GetContentType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 s.BindString(2, attachment.GetUuid());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 s.BindInt64(3, attachment.GetCompressedSize());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 s.BindInt64(4, attachment.GetUncompressedSize());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 s.BindInt(5, attachment.GetCompressionType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 s.BindString(6, attachment.GetUncompressedMD5());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 s.BindString(7, attachment.GetCompressedMD5());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 void DatabaseWrapperBase::DeleteAttachment(int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 FileContentType attachment)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM AttachedFiles WHERE id=? AND fileType=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 s.BindInt(1, attachment);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 void DatabaseWrapperBase::ListAvailableAttachments(std::list<FileContentType>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 "SELECT fileType FROM AttachedFiles WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 target.push_back(static_cast<FileContentType>(s.ColumnInt(0)));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 bool DatabaseWrapperBase::LookupAttachment(FileInfo& attachment,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 FileContentType contentType)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 "SELECT uuid, uncompressedSize, compressionType, compressedSize, uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 s.BindInt(1, contentType);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 attachment = FileInfo(s.ColumnString(0),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 contentType,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 s.ColumnInt64(1),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 s.ColumnString(4),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 static_cast<CompressionType>(s.ColumnInt(2)),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 s.ColumnInt64(3),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 s.ColumnString(5));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 void DatabaseWrapperBase::ClearMainDicomTags(int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM DicomIdentifiers WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM MainDicomTags WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
1715
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
318 void DatabaseWrapperBase::SetMainDicomTag(int64_t id,
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
319 const DicomTag& tag,
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
320 const std::string& value)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 {
1715
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
322 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)");
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 s.BindInt(1, tag.GetGroup());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 s.BindInt(2, tag.GetElement());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 s.BindString(3, value);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
1713
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
331 void DatabaseWrapperBase::SetIdentifierTag(int64_t id,
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
332 const DicomTag& tag,
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
333 const std::string& value)
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
334 {
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
335 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifiers VALUES(?, ?, ?, ?)");
1715
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
336 s.BindInt64(0, id);
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
337 s.BindInt(1, tag.GetGroup());
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
338 s.BindInt(2, tag.GetElement());
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
339 s.BindString(3, value);
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
340 s.Run();
1713
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
341 }
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
342
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
343
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 void DatabaseWrapperBase::GetMainDicomTags(DicomMap& map,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 map.Clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM MainDicomTags WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 map.SetValue(s.ColumnInt(1),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 s.ColumnInt(2),
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
355 s.ColumnString(3), false);
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 void DatabaseWrapperBase::GetChildrenPublicId(std::list<std::string>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.publicId FROM Resources AS a, Resources AS b "
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 "WHERE a.parentId = b.internalId AND b.internalId = ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 target.push_back(s.ColumnString(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 void DatabaseWrapperBase::GetChildrenInternalId(std::list<int64_t>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT a.internalId FROM Resources AS a, Resources AS b "
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 "WHERE a.parentId = b.internalId AND b.internalId = ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 target.push_back(s.ColumnInt64(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 void DatabaseWrapperBase::LogChange(int64_t internalId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 const ServerIndexChange& change)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 s.BindInt(0, change.GetChangeType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 s.BindInt64(1, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 s.BindInt(2, change.GetResourceType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 s.BindString(3, change.GetDate());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
405 ErrorCode DatabaseWrapperBase::GetChangesInternal(std::list<ServerIndexChange>& target,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
406 bool& done,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
407 SQLite::Statement& s,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
408 uint32_t maxResults)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 while (target.size() < maxResults && s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 int64_t seq = s.ColumnInt64(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 const std::string& date = s.ColumnString(4);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 int64_t internalId = s.ColumnInt64(2);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
420 std::string publicId;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
421 if (!GetPublicId(publicId, internalId))
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
422 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
423 return ErrorCode_UnknownResource;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
424 }
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 target.push_back(ServerIndexChange(seq, changeType, resourceType, publicId, date));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 done = !(target.size() == maxResults && s.Step());
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
430 return ErrorCode_Success;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
434 ErrorCode DatabaseWrapperBase::GetChanges(std::list<ServerIndexChange>& target,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
435 bool& done,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
436 int64_t since,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
437 uint32_t maxResults)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes WHERE seq>? ORDER BY seq LIMIT ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 s.BindInt64(0, since);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 s.BindInt(1, maxResults + 1);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
442 return GetChangesInternal(target, done, s, maxResults);
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
445 ErrorCode DatabaseWrapperBase::GetLastChange(std::list<ServerIndexChange>& target)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 bool done; // Ignored
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM Changes ORDER BY seq DESC LIMIT 1");
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
449 return GetChangesInternal(target, done, s, 1);
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 void DatabaseWrapperBase::LogExportedResource(const ExportedResource& resource)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 "INSERT INTO ExportedResources VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 s.BindInt(0, resource.GetResourceType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 s.BindString(1, resource.GetPublicId());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 s.BindString(2, resource.GetModality());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 s.BindString(3, resource.GetPatientId());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 s.BindString(4, resource.GetStudyInstanceUid());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 s.BindString(5, resource.GetSeriesInstanceUid());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 s.BindString(6, resource.GetSopInstanceUid());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 s.BindString(7, resource.GetDate());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 void DatabaseWrapperBase::GetExportedResourcesInternal(std::list<ExportedResource>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 bool& done,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 SQLite::Statement& s,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 uint32_t maxResults)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 while (target.size() < maxResults && s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 int64_t seq = s.ColumnInt64(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 std::string publicId = s.ColumnString(2);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 ExportedResource resource(seq,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 resourceType,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 publicId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 s.ColumnString(3), // modality
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 s.ColumnString(8), // date
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 s.ColumnString(4), // patient ID
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 s.ColumnString(5), // study instance UID
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 s.ColumnString(6), // series instance UID
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 s.ColumnString(7)); // sop instance UID
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 target.push_back(resource);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 done = !(target.size() == maxResults && s.Step());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 void DatabaseWrapperBase::GetExportedResources(std::list<ExportedResource>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 bool& done,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 int64_t since,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 uint32_t maxResults)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 s.BindInt64(0, since);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 s.BindInt(1, maxResults + 1);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 GetExportedResourcesInternal(target, done, s, maxResults);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 void DatabaseWrapperBase::GetLastExportedResource(std::list<ExportedResource>& target)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 bool done; // Ignored
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 GetExportedResourcesInternal(target, done, s, 1);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 uint64_t DatabaseWrapperBase::GetTotalCompressedSize()
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(compressedSize) FROM AttachedFiles");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 return static_cast<uint64_t>(s.ColumnInt64(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 uint64_t DatabaseWrapperBase::GetTotalUncompressedSize()
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(uncompressedSize) FROM AttachedFiles");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 return static_cast<uint64_t>(s.ColumnInt64(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
538 void DatabaseWrapperBase::GetAllInternalIds(std::list<int64_t>& target,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
539 ResourceType resourceType)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
540 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
541 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT internalId FROM Resources WHERE resourceType=?");
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
542 s.BindInt(0, resourceType);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
543
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
544 target.clear();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
545 while (s.Step())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
546 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
547 target.push_back(s.ColumnInt64(0));
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
548 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
549 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
550
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
551
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 void DatabaseWrapperBase::GetAllPublicIds(std::list<std::string>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 ResourceType resourceType)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE resourceType=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 s.BindInt(0, resourceType);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 target.push_back(s.ColumnString(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 void DatabaseWrapperBase::GetAllPublicIds(std::list<std::string>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 ResourceType resourceType,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 size_t since,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 size_t limit)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 if (limit == 0)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 return;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Resources WHERE resourceType=? LIMIT ? OFFSET ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 s.BindInt(0, resourceType);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 s.BindInt64(1, limit);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 s.BindInt64(2, since);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 target.push_back(s.ColumnString(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 uint64_t DatabaseWrapperBase::GetResourceCount(ResourceType resourceType)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 "SELECT COUNT(*) FROM Resources WHERE resourceType=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 s.BindInt(0, resourceType);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
597 return 0;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 }
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
599 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
600 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
601 int64_t c = s.ColumnInt(0);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
602 assert(!s.Step());
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
603 return c;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
604 }
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 bool DatabaseWrapperBase::SelectPatientToRecycle(int64_t& internalId)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 // No patient remaining or all the patients are protected
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 internalId = s.ColumnInt(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 bool DatabaseWrapperBase::SelectPatientToRecycle(int64_t& internalId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 int64_t patientIdToAvoid)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 "SELECT patientId FROM PatientRecyclingOrder "
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 "WHERE patientId != ? ORDER BY seq ASC LIMIT 1");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 s.BindInt64(0, patientIdToAvoid);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 // No patient remaining or all the patients are protected
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 internalId = s.ColumnInt(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 bool DatabaseWrapperBase::IsProtectedPatient(int64_t internalId)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 s.BindInt64(0, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 return !s.Step();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 void DatabaseWrapperBase::SetProtectedPatient(int64_t internalId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 bool isProtected)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 if (isProtected)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM PatientRecyclingOrder WHERE patientId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 s.BindInt64(0, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 else if (IsProtectedPatient(internalId))
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO PatientRecyclingOrder VALUES(NULL, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 s.BindInt64(0, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 // Nothing to do: The patient is already unprotected
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 bool DatabaseWrapperBase::IsExistingResource(int64_t internalId)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 "SELECT * FROM Resources WHERE internalId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 s.BindInt64(0, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 return s.Step();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
685
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
686 void DatabaseWrapperBase::LookupIdentifier(std::list<int64_t>& target,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
687 ResourceType level,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
688 const DicomTag& tag,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
689 IdentifierConstraintType type,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
690 const std::string& value)
1729
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
691 {
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
692 static const char* COMMON = ("SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE "
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
693 "d.id = r.internalId AND r.resourceType=? AND "
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
694 "d.tagGroup=? AND d.tagElement=? AND ");
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
695
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
696 std::auto_ptr<SQLite::Statement> s;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
697
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
698 switch (type)
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
699 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
700 case IdentifierConstraintType_GreaterOrEqual:
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
701 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value>=?"));
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
702 break;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
703
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
704 case IdentifierConstraintType_SmallerOrEqual:
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
705 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value<=?"));
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
706 break;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
707
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
708 case IdentifierConstraintType_Wildcard:
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
709 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value GLOB ?"));
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
710 break;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
711
1761
f4286d99ee0a fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1760
diff changeset
712 case IdentifierConstraintType_Equal:
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
713 default:
1761
f4286d99ee0a fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1760
diff changeset
714 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value=?"));
f4286d99ee0a fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1760
diff changeset
715 break;
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
716 }
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
717
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
718 assert(s.get() != NULL);
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
719
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
720 s->BindInt(0, level);
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
721 s->BindInt(1, tag.GetGroup());
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
722 s->BindInt(2, tag.GetElement());
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
723 s->BindString(3, value);
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
724
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
725 target.clear();
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
726
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
727 while (s->Step())
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
728 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
729 target.push_back(s->ColumnInt64(0));
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
730 }
1729
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
731 }
2697
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
732
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
733
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
734 void DatabaseWrapperBase::LookupIdentifierRange(std::list<int64_t>& target,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
735 ResourceType level,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
736 const DicomTag& tag,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
737 const std::string& start,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
738 const std::string& end)
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
739 {
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
740 SQLite::Statement statement(db_, SQLITE_FROM_HERE,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
741 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE "
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
742 "d.id = r.internalId AND r.resourceType=? AND "
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
743 "d.tagGroup=? AND d.tagElement=? AND d.value>=? AND d.value<=?");
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
744
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
745 statement.BindInt(0, level);
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
746 statement.BindInt(1, tag.GetGroup());
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
747 statement.BindInt(2, tag.GetElement());
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
748 statement.BindString(3, start);
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
749 statement.BindString(4, end);
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
750
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
751 target.clear();
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
752
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
753 while (statement.Step())
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
754 {
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
755 target.push_back(statement.ColumnInt64(0));
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
756 }
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
757 }
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 }