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