Mercurial > hg > orthanc-databases
annotate SQLite/Plugins/SQLiteIndex.cpp @ 378:9db9e0275ec0 db-protobuf
refactoring IndexBackend::LogExportedResource()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 29 Mar 2023 08:19:40 +0200 |
parents | 16aac0287485 |
children | 3d6886f3e5b3 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
359
16aac0287485
copyright upgraded to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
16aac0287485
copyright upgraded to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Affero General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "SQLiteIndex.h" | |
24 | |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
25 #include "../../Framework/Common/Integer64Value.h" |
0 | 26 #include "../../Framework/Plugins/GlobalProperties.h" |
27 #include "../../Framework/SQLite/SQLiteDatabase.h" | |
28 #include "../../Framework/SQLite/SQLiteTransaction.h" | |
29 | |
30 #include <EmbeddedResources.h> // Auto-generated file | |
31 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
32 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 33 #include <Logging.h> |
34 #include <OrthancException.h> | |
0 | 35 |
36 namespace OrthancDatabases | |
37 { | |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
38 IDatabaseFactory* SQLiteIndex::CreateDatabaseFactory() |
0 | 39 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
40 class Factory : public IDatabaseFactory |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
41 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
42 private: |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
43 std::string path_; |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
44 bool fast_; |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
45 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
46 public: |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
47 Factory(const std::string& path, |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
48 bool fast) : |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
49 path_(path), |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
50 fast_(fast) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
51 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
52 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
53 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
54 virtual IDatabase* Open() ORTHANC_OVERRIDE |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
55 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
56 std::unique_ptr<SQLiteDatabase> db(new SQLiteDatabase); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
57 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
58 if (path_.empty()) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
59 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
60 db->OpenInMemory(); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
61 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
62 else |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
63 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
64 db->Open(path_); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
65 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
66 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
67 db->Execute("PRAGMA ENCODING=\"UTF-8\";"); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
68 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
69 if (fast_) |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
70 { |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
71 // Performance tuning of SQLite with PRAGMAs |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
72 // http://www.sqlite.org/pragma.html |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
73 db->Execute("PRAGMA SYNCHRONOUS=NORMAL;"); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
74 db->Execute("PRAGMA JOURNAL_MODE=WAL;"); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
75 db->Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
76 db->Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
77 //db->Execute("PRAGMA TEMP_STORE=memory"); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
78 } |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
79 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
80 return db.release(); |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
81 } |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
82 }; |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
83 |
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
84 return new Factory(path_, fast_); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
85 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
86 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
87 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
88 void SQLiteIndex::ConfigureDatabase(DatabaseManager& manager) |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
89 { |
0 | 90 uint32_t expectedVersion = 6; |
199 | 91 |
92 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests | |
0 | 93 { |
199 | 94 expectedVersion = OrthancPluginGetExpectedDatabaseVersion(GetContext()); |
0 | 95 } |
96 | |
97 // Check the expected version of the database | |
98 if (expectedVersion != 6) | |
99 { | |
100 LOG(ERROR) << "This database plugin is incompatible with your version of Orthanc " | |
101 << "expecting the DB schema version " << expectedVersion | |
102 << ", but this plugin is only compatible with version 6"; | |
103 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); | |
104 } | |
105 | |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
106 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
107 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
0 | 108 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
109 if (!t.GetDatabaseTransaction().DoesTableExist("Resources")) |
0 | 110 { |
111 std::string query; | |
112 | |
113 Orthanc::EmbeddedResources::GetFileResource | |
114 (query, Orthanc::EmbeddedResources::SQLITE_PREPARE_INDEX); | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
115 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
116 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
117 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
118 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
119 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, 1); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
120 } |
0 | 121 |
122 t.Commit(); | |
123 } | |
124 | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
125 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
126 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
0 | 127 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
128 if (!t.GetDatabaseTransaction().DoesTableExist("Resources")) |
0 | 129 { |
130 LOG(ERROR) << "Corrupted SQLite database"; | |
131 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
132 } | |
133 | |
134 int version = 0; | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
135 if (!LookupGlobalIntegerProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion) || |
0 | 136 version != 6) |
137 { | |
138 LOG(ERROR) << "SQLite plugin is incompatible with database schema version: " << version; | |
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
140 } | |
141 | |
142 int revision; | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
143 if (!LookupGlobalIntegerProperty(revision, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel)) |
0 | 144 { |
145 revision = 1; | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
146 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
0 | 147 } |
148 | |
149 if (revision != 1) | |
150 { | |
151 LOG(ERROR) << "SQLite plugin is incompatible with database schema revision: " << revision; | |
152 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); | |
153 } | |
154 | |
155 t.Commit(); | |
156 } | |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
157 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
158 { |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
159 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
160 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
161 if (!t.GetDatabaseTransaction().DoesTableExist("ServerProperties")) |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
162 { |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
163 t.GetDatabaseTransaction().ExecuteMultiLines("CREATE TABLE ServerProperties(server TEXT, " |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
164 "property INTEGER, value TEXT, PRIMARY KEY(server, property))"); |
238
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
165 } |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
166 |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
167 t.Commit(); |
f033cc039264
new table: "ServerProperties"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
168 } |
0 | 169 } |
170 | |
171 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
172 SQLiteIndex::SQLiteIndex(OrthancPluginContext* context, |
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
173 const std::string& path) : |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
174 IndexBackend(context), |
0 | 175 path_(path), |
176 fast_(true) | |
177 { | |
178 if (path.empty()) | |
179 { | |
180 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
181 } | |
182 } | |
183 | |
184 | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
185 SQLiteIndex::SQLiteIndex(OrthancPluginContext* context) : |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
186 IndexBackend(context), |
0 | 187 fast_(true) |
188 { | |
189 } | |
190 | |
191 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
192 int64_t SQLiteIndex::CreateResource(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
193 const char* publicId, |
0 | 194 OrthancPluginResourceType type) |
195 { | |
196 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
197 STATEMENT_FROM_HERE, manager, |
0 | 198 "INSERT INTO Resources VALUES(NULL, ${type}, ${id}, NULL)"); |
199 | |
200 statement.SetParameterType("id", ValueType_Utf8String); | |
201 statement.SetParameterType("type", ValueType_Integer64); | |
202 | |
203 Dictionary args; | |
204 args.SetUtf8Value("id", publicId); | |
205 args.SetIntegerValue("type", static_cast<int>(type)); | |
206 | |
207 statement.Execute(args); | |
208 | |
209 return dynamic_cast<SQLiteDatabase&>(statement.GetDatabase()).GetLastInsertRowId(); | |
210 } | |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
211 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
212 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
213 int64_t SQLiteIndex::GetLastChangeIndex(DatabaseManager& manager) |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
214 { |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
215 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
216 STATEMENT_FROM_HERE, manager, |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
217 "SELECT seq FROM sqlite_sequence WHERE name='Changes'"); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
218 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
219 statement.SetReadOnly(true); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
220 statement.Execute(); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
221 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
222 if (statement.IsDone()) |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
223 { |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
224 // No change has been recorded so far in the database |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
225 return 0; |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
226 } |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
227 else |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
228 { |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
229 const IValue& value = statement.GetResultField(0); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
230 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
231 switch (value.GetType()) |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
232 { |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
233 case ValueType_Integer64: |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
234 return dynamic_cast<const Integer64Value&>(value).GetValue(); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
235 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
236 default: |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
237 //LOG(ERROR) << value.Format(); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
238 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
239 } |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
240 } |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
241 } |
0 | 242 } |