Mercurial > hg > orthanc-databases
comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 85:1012fe77241c db-changes
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Jan 2019 18:04:12 +0100 |
parents | cb0aac9bbada |
children | eb08ec14fb04 |
comparison
equal
deleted
inserted
replaced
82:122f22550521 | 85:1012fe77241c |
---|---|
35 { | 35 { |
36 // Some aliases for internal properties | 36 // Some aliases for internal properties |
37 static const GlobalProperty GlobalProperty_HasTrigramIndex = GlobalProperty_DatabaseInternal0; | 37 static const GlobalProperty GlobalProperty_HasTrigramIndex = GlobalProperty_DatabaseInternal0; |
38 static const GlobalProperty GlobalProperty_HasCreateInstance = GlobalProperty_DatabaseInternal1; | 38 static const GlobalProperty GlobalProperty_HasCreateInstance = GlobalProperty_DatabaseInternal1; |
39 static const GlobalProperty GlobalProperty_HasFastCountResources = GlobalProperty_DatabaseInternal2; | 39 static const GlobalProperty GlobalProperty_HasFastCountResources = GlobalProperty_DatabaseInternal2; |
40 static const GlobalProperty GlobalProperty_GetLastChangeIndex = GlobalProperty_DatabaseInternal3; | |
40 } | 41 } |
41 | 42 |
42 | 43 |
43 namespace OrthancDatabases | 44 namespace OrthancDatabases |
44 { | 45 { |
234 } | 235 } |
235 | 236 |
236 t.Commit(); | 237 t.Commit(); |
237 } | 238 } |
238 | 239 |
240 { | |
241 PostgreSQLTransaction t(*db); | |
242 | |
243 // Installing this extension requires the "GlobalIntegers" table | |
244 // created by the "GetLastChangeIndex" extension | |
245 int property = 0; | |
246 if (!LookupGlobalIntegerProperty(property, *db, t, | |
247 Orthanc::GlobalProperty_GetLastChangeIndex) || | |
248 property != 1) | |
249 { | |
250 LOG(INFO) << "Installing the GetLastChangeIndex extension"; | |
251 | |
252 std::string query; | |
253 Orthanc::EmbeddedResources::GetFileResource | |
254 (query, Orthanc::EmbeddedResources::POSTGRESQL_GET_LAST_CHANGE_INDEX); | |
255 db->Execute(query); | |
256 | |
257 SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_GetLastChangeIndex, 1); | |
258 } | |
259 | |
260 t.Commit(); | |
261 } | |
262 | |
239 return db.release(); | 263 return db.release(); |
240 } | 264 } |
241 | 265 |
242 | 266 |
243 PostgreSQLIndex::PostgreSQLIndex(const PostgreSQLParameters& parameters) : | 267 PostgreSQLIndex::PostgreSQLIndex(const PostgreSQLParameters& parameters) : |
392 } | 416 } |
393 | 417 |
394 assert(result == IndexBackend::GetResourceCount(resourceType)); | 418 assert(result == IndexBackend::GetResourceCount(resourceType)); |
395 return result; | 419 return result; |
396 } | 420 } |
421 | |
422 | |
423 int64_t PostgreSQLIndex::GetLastChangeIndex() | |
424 { | |
425 DatabaseManager::CachedStatement statement( | |
426 STATEMENT_FROM_HERE, GetManager(), | |
427 "SELECT value FROM GlobalIntegers WHERE key = 6"); | |
428 | |
429 statement.SetReadOnly(true); | |
430 statement.Execute(); | |
431 | |
432 return ReadInteger64(statement, 0); | |
433 } | |
397 } | 434 } |