annotate OrthancServer/Resources/Graveyard/DatabasePluginSample/DatabaseWrapperBase.cpp @ 5853:4d932683049d get-scu tip

very first implementation of C-Get SCU
author Alain Mazy <am@orthanc.team>
date Tue, 29 Oct 2024 17:25:49 +0100
parents f7adfb22e20e
children
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU General Public License as
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * License, or (at your option) any later version.
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * 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
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * General Public License for more details.
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
4050
cd363608551a fix paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
24 #include "../../../Sources/PrecompiledHeadersServer.h"
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "DatabaseWrapperBase.h"
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <stdio.h>
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
28 #include <memory>
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace Orthanc
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 void DatabaseWrapperBase::SetGlobalProperty(GlobalProperty property,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 const std::string& value)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 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
36 s.BindInt(0, property);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 s.BindString(1, value);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 s.Run();
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
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 bool DatabaseWrapperBase::LookupGlobalProperty(std::string& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 GlobalProperty property)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 "SELECT value FROM GlobalProperties WHERE property=?");
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
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 if (!s.Step())
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 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 else
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 target = s.ColumnString(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
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
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 int64_t DatabaseWrapperBase::CreateResource(const std::string& publicId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 ResourceType type)
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 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
63 s.BindInt(0, type);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 s.BindString(1, publicId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 return db_.GetLastInsertRowId();
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 bool DatabaseWrapperBase::LookupResource(int64_t& id,
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 const std::string& publicId)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 "SELECT internalId, resourceType FROM Resources WHERE publicId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 s.BindString(0, publicId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 if (!s.Step())
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 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 else
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 id = s.ColumnInt(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 type = static_cast<ResourceType>(s.ColumnInt(1));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 // Check whether there is a single resource with this public id
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 assert(!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 true;
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 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
93 ErrorCode DatabaseWrapperBase::LookupParent(bool& found,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
94 int64_t& parentId,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
95 int64_t resourceId)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 "SELECT parentId FROM Resources WHERE internalId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 s.BindInt64(0, resourceId);
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 if (!s.Step())
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 return ErrorCode_UnknownResource;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 if (s.ColumnIsNull(0))
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
108 found = false;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
112 found = true;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 parentId = s.ColumnInt(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
115
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
116 return ErrorCode_Success;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
119 bool DatabaseWrapperBase::GetPublicId(std::string& result,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
120 int64_t resourceId)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 "SELECT publicId FROM Resources WHERE internalId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 s.BindInt64(0, resourceId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
128 return false;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
130 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
131 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
132 result = s.ColumnString(0);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
133 return true;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
134 }
1670
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
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 ErrorCode DatabaseWrapperBase::GetResourceType(ResourceType& result,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
139 int64_t resourceId)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 "SELECT resourceType FROM Resources WHERE internalId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 s.BindInt64(0, resourceId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
145 if (s.Step())
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
146 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
147 result = static_cast<ResourceType>(s.ColumnInt(0));
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
148 return ErrorCode_Success;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
149 }
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
150 else
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
152 return ErrorCode_UnknownResource;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 void DatabaseWrapperBase::AttachChild(int64_t parent,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 int64_t child)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 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
161 s.BindInt64(0, parent);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 s.BindInt64(1, child);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 s.Run();
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::SetMetadata(int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 MetadataType type,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 const std::string& value)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR REPLACE INTO Metadata VALUES(?, ?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 s.BindInt(1, type);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 s.BindString(2, value);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 void DatabaseWrapperBase::DeleteMetadata(int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 MetadataType type)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 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
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.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
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 bool DatabaseWrapperBase::LookupMetadata(std::string& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 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,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 "SELECT value FROM Metadata WHERE id=? AND type=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 s.BindInt(1, type);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 target = s.ColumnString(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
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
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 void DatabaseWrapperBase::ListAvailableMetadata(std::list<MetadataType>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 int64_t id)
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 target.clear();
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 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
213 s.BindInt64(0, id);
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 while (s.Step())
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 target.push_back(static_cast<MetadataType>(s.ColumnInt(0)));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
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
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 void DatabaseWrapperBase::AddAttachment(int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 const FileInfo& attachment)
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 s.BindInt(1, attachment.GetContentType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 s.BindString(2, attachment.GetUuid());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 s.BindInt64(3, attachment.GetCompressedSize());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 s.BindInt64(4, attachment.GetUncompressedSize());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 s.BindInt(5, attachment.GetCompressionType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 s.BindString(6, attachment.GetUncompressedMD5());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 s.BindString(7, attachment.GetCompressedMD5());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 void DatabaseWrapperBase::DeleteAttachment(int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 FileContentType attachment)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 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
242 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 s.BindInt(1, attachment);
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
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 void DatabaseWrapperBase::ListAvailableAttachments(std::list<FileContentType>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 "SELECT fileType FROM AttachedFiles WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 s.BindInt64(0, id);
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 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 target.push_back(static_cast<FileContentType>(s.ColumnInt(0)));
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 }
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 bool DatabaseWrapperBase::LookupAttachment(FileInfo& attachment,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 int64_t id,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 FileContentType contentType)
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 "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
270 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 s.BindInt(1, contentType);
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 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 return false;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 attachment = FileInfo(s.ColumnString(0),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 contentType,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 s.ColumnInt64(1),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 s.ColumnString(4),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 static_cast<CompressionType>(s.ColumnInt(2)),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 s.ColumnInt64(3),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 s.ColumnString(5));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 return true;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 void DatabaseWrapperBase::ClearMainDicomTags(int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM DicomIdentifiers WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 s.Run();
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM MainDicomTags WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
1715
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
307 void DatabaseWrapperBase::SetMainDicomTag(int64_t id,
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
308 const DicomTag& tag,
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
309 const std::string& value)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 {
1715
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
311 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO MainDicomTags VALUES(?, ?, ?, ?)");
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 s.BindInt(1, tag.GetGroup());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 s.BindInt(2, tag.GetElement());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 s.BindString(3, value);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
1713
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
320 void DatabaseWrapperBase::SetIdentifierTag(int64_t id,
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
321 const DicomTag& tag,
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
322 const std::string& value)
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
323 {
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
324 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO DicomIdentifiers VALUES(?, ?, ?, ?)");
1715
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
325 s.BindInt64(0, id);
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
326 s.BindInt(1, tag.GetGroup());
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
327 s.BindInt(2, tag.GetElement());
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
328 s.BindString(3, value);
c3baf74e443f simplify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1713
diff changeset
329 s.Run();
1713
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
330 }
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
331
4db9200c7f46 SetIdentifierTag
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1711
diff changeset
332
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 void DatabaseWrapperBase::GetMainDicomTags(DicomMap& map,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 map.Clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT * FROM MainDicomTags WHERE id=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 s.BindInt64(0, id);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 map.SetValue(s.ColumnInt(1),
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 s.ColumnInt(2),
2007
655489d9165d DicomMap::ParseDicomMetaInformation()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
344 s.ColumnString(3), false);
1670
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 }
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
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 void DatabaseWrapperBase::GetChildrenPublicId(std::list<std::string>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 int64_t id)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 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
354 "WHERE a.parentId = b.internalId AND b.internalId = ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 s.BindInt64(0, id);
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 target.clear();
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 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 target.push_back(s.ColumnString(0));
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 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 void DatabaseWrapperBase::GetChildrenInternalId(std::list<int64_t>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 int64_t id)
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 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
370 "WHERE a.parentId = b.internalId AND b.internalId = ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 s.BindInt64(0, id);
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 target.clear();
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 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 target.push_back(s.ColumnInt64(0));
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 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 void DatabaseWrapperBase::LogChange(int64_t internalId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 const ServerIndexChange& change)
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Changes VALUES(NULL, ?, ?, ?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 s.BindInt(0, change.GetChangeType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 s.BindInt64(1, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 s.BindInt(2, change.GetResourceType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 s.BindString(3, change.GetDate());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
394 ErrorCode DatabaseWrapperBase::GetChangesInternal(std::list<ServerIndexChange>& target,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
395 bool& done,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
396 SQLite::Statement& s,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
397 uint32_t maxResults)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 while (target.size() < maxResults && s.Step())
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 int64_t seq = s.ColumnInt64(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 ChangeType changeType = static_cast<ChangeType>(s.ColumnInt(1));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(3));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 const std::string& date = s.ColumnString(4);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 int64_t internalId = s.ColumnInt64(2);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
409 std::string publicId;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
410 if (!GetPublicId(publicId, internalId))
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
411 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
412 return ErrorCode_UnknownResource;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
413 }
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 target.push_back(ServerIndexChange(seq, changeType, resourceType, publicId, date));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 }
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 done = !(target.size() == maxResults && s.Step());
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
419 return ErrorCode_Success;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
423 ErrorCode DatabaseWrapperBase::GetChanges(std::list<ServerIndexChange>& target,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
424 bool& done,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
425 int64_t since,
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
426 uint32_t maxResults)
1670
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 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
429 s.BindInt64(0, since);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 s.BindInt(1, maxResults + 1);
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
431 return GetChangesInternal(target, done, s, maxResults);
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
434 ErrorCode DatabaseWrapperBase::GetLastChange(std::list<ServerIndexChange>& target)
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 bool done; // Ignored
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 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
438 return GetChangesInternal(target, done, s, 1);
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 void DatabaseWrapperBase::LogExportedResource(const ExportedResource& resource)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 "INSERT INTO ExportedResources VALUES(NULL, ?, ?, ?, ?, ?, ?, ?, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 s.BindInt(0, resource.GetResourceType());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 s.BindString(1, resource.GetPublicId());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 s.BindString(2, resource.GetModality());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 s.BindString(3, resource.GetPatientId());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 s.BindString(4, resource.GetStudyInstanceUid());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 s.BindString(5, resource.GetSeriesInstanceUid());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 s.BindString(6, resource.GetSopInstanceUid());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 s.BindString(7, resource.GetDate());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 s.Run();
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
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 void DatabaseWrapperBase::GetExportedResourcesInternal(std::list<ExportedResource>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 bool& done,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 SQLite::Statement& s,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 uint32_t maxResults)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 while (target.size() < maxResults && s.Step())
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 int64_t seq = s.ColumnInt64(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 ResourceType resourceType = static_cast<ResourceType>(s.ColumnInt(1));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 std::string publicId = s.ColumnString(2);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 ExportedResource resource(seq,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 resourceType,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 publicId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 s.ColumnString(3), // modality
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 s.ColumnString(8), // date
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 s.ColumnString(4), // patient ID
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 s.ColumnString(5), // study instance UID
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 s.ColumnString(6), // series instance UID
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 s.ColumnString(7)); // sop instance UID
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 target.push_back(resource);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 done = !(target.size() == maxResults && s.Step());
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 void DatabaseWrapperBase::GetExportedResources(std::list<ExportedResource>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 bool& done,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 int64_t since,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 uint32_t maxResults)
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 "SELECT * FROM ExportedResources WHERE seq>? ORDER BY seq LIMIT ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 s.BindInt64(0, since);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 s.BindInt(1, maxResults + 1);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 GetExportedResourcesInternal(target, done, s, maxResults);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 void DatabaseWrapperBase::GetLastExportedResource(std::list<ExportedResource>& target)
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 bool done; // Ignored
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 "SELECT * FROM ExportedResources ORDER BY seq DESC LIMIT 1");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 GetExportedResourcesInternal(target, done, s, 1);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 }
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 uint64_t DatabaseWrapperBase::GetTotalCompressedSize()
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(compressedSize) FROM AttachedFiles");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 return static_cast<uint64_t>(s.ColumnInt64(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 }
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 uint64_t DatabaseWrapperBase::GetTotalUncompressedSize()
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 SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT SUM(uncompressedSize) FROM AttachedFiles");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 s.Run();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 return static_cast<uint64_t>(s.ColumnInt64(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
1750
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
527 void DatabaseWrapperBase::GetAllInternalIds(std::list<int64_t>& target,
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
528 ResourceType resourceType)
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
529 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
530 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
531 s.BindInt(0, resourceType);
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
532
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
533 target.clear();
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
534 while (s.Step())
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
535 {
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
536 target.push_back(s.ColumnInt64(0));
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
537 }
55d52567bebb LookupResource implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1746
diff changeset
538 }
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
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 void DatabaseWrapperBase::GetAllPublicIds(std::list<std::string>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 ResourceType resourceType)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 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
545 s.BindInt(0, resourceType);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 target.push_back(s.ColumnString(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 }
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 void DatabaseWrapperBase::GetAllPublicIds(std::list<std::string>& target,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 ResourceType resourceType,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 size_t since,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 size_t limit)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 if (limit == 0)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 return;
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 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
566 s.BindInt(0, resourceType);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 s.BindInt64(1, limit);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 s.BindInt64(2, since);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 target.clear();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 while (s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 target.push_back(s.ColumnString(0));
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 uint64_t DatabaseWrapperBase::GetResourceCount(ResourceType resourceType)
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 "SELECT COUNT(*) FROM Resources WHERE resourceType=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 s.BindInt(0, resourceType);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
586 return 0;
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 }
1671
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
588 else
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
589 {
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
590 int64_t c = s.ColumnInt(0);
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
591 assert(!s.Step());
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
592 return c;
2f2e2ec17bc4 sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1670
diff changeset
593 }
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 }
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 bool DatabaseWrapperBase::SelectPatientToRecycle(int64_t& internalId)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 "SELECT patientId FROM PatientRecyclingOrder ORDER BY seq ASC LIMIT 1");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 if (!s.Step())
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 // No patient remaining or all the patients are protected
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 return false;
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 else
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 internalId = s.ColumnInt(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 return true;
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 }
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 bool DatabaseWrapperBase::SelectPatientToRecycle(int64_t& internalId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 int64_t patientIdToAvoid)
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 "SELECT patientId FROM PatientRecyclingOrder "
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 "WHERE patientId != ? ORDER BY seq ASC LIMIT 1");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 s.BindInt64(0, patientIdToAvoid);
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 if (!s.Step())
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 // No patient remaining or all the patients are protected
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 return false;
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 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 internalId = s.ColumnInt(0);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 return true;
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 }
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 bool DatabaseWrapperBase::IsProtectedPatient(int64_t internalId)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 "SELECT * FROM PatientRecyclingOrder WHERE patientId = ?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 s.BindInt64(0, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 return !s.Step();
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 }
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 void DatabaseWrapperBase::SetProtectedPatient(int64_t internalId,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 bool isProtected)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 if (isProtected)
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE 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 s.Run();
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 else if (IsProtectedPatient(internalId))
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO PatientRecyclingOrder VALUES(NULL, ?)");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 s.BindInt64(0, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 s.Run();
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 else
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 {
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 // Nothing to do: The patient is already unprotected
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 }
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
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 bool DatabaseWrapperBase::IsExistingResource(int64_t internalId)
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 SQLite::Statement s(db_, SQLITE_FROM_HERE,
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 "SELECT * FROM Resources WHERE internalId=?");
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 s.BindInt64(0, internalId);
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 return s.Step();
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
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
674
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
675 void DatabaseWrapperBase::LookupIdentifier(std::list<int64_t>& target,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
676 ResourceType level,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
677 const DicomTag& tag,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
678 IdentifierConstraintType type,
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
679 const std::string& value)
1729
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
680 {
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
681 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
682 "d.id = r.internalId AND r.resourceType=? AND "
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
683 "d.tagGroup=? AND d.tagElement=? AND ");
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 std::auto_ptr<SQLite::Statement> s;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
686
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
687 switch (type)
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
688 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
689 case IdentifierConstraintType_GreaterOrEqual:
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
690 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value>=?"));
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
691 break;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
692
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
693 case IdentifierConstraintType_SmallerOrEqual:
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
694 s.reset(new SQLite::Statement(db_, std::string(COMMON) + "d.value<=?"));
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
695 break;
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 case IdentifierConstraintType_Wildcard:
1758
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1750
diff changeset
698 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
699 break;
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
700
1761
f4286d99ee0a fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1760
diff changeset
701 case IdentifierConstraintType_Equal:
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
702 default:
1761
f4286d99ee0a fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1760
diff changeset
703 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
704 break;
1746
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
705 }
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 assert(s.get() != NULL);
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
708
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
709 s->BindInt(0, level);
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
710 s->BindInt(1, tag.GetGroup());
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
711 s->BindInt(2, tag.GetElement());
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
712 s->BindString(3, value);
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
713
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
714 target.clear();
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 while (s->Step())
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
717 {
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
718 target.push_back(s->ColumnInt64(0));
d143db00a794 SetOfResources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1745
diff changeset
719 }
1729
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1728
diff changeset
720 }
2697
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
721
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
722
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
723 void DatabaseWrapperBase::LookupIdentifierRange(std::list<int64_t>& target,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
724 ResourceType level,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
725 const DicomTag& tag,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
726 const std::string& start,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
727 const std::string& end)
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
728 {
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
729 SQLite::Statement statement(db_, SQLITE_FROM_HERE,
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
730 "SELECT d.id FROM DicomIdentifiers AS d, Resources AS r WHERE "
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
731 "d.id = r.internalId AND r.resourceType=? AND "
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
732 "d.tagGroup=? AND d.tagElement=? AND d.value>=? AND d.value<=?");
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
733
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
734 statement.BindInt(0, level);
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
735 statement.BindInt(1, tag.GetGroup());
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
736 statement.BindInt(2, tag.GetElement());
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
737 statement.BindString(3, start);
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
738 statement.BindString(4, end);
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
739
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
740 target.clear();
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
741
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
742 while (statement.Step())
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
743 {
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
744 target.push_back(statement.ColumnInt64(0));
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
745 }
e583478e0c6c New primitive in database SDK: "lookupIdentifierRange" to speed up range searches
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
746 }
1670
16955f8fec4d refactoring: DatabaseWrapperBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 }