annotate OrthancServer/DatabaseWrapperBase.cpp @ 2451:a4032b162502

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