# HG changeset patch # User Sebastien Jodogne # Date 1547149176 -3600 # Node ID 48d445f756db7c10a5b4a4ff99f38ce7ca696476 # Parent d16e94157efed30b814658268159990cf47e24f7 new extension implemented for MySQL: GetLastChangeIndex diff -r d16e94157efe -r 48d445f756db MySQL/CMakeLists.txt --- a/MySQL/CMakeLists.txt Thu Jan 10 18:04:27 2019 +0100 +++ b/MySQL/CMakeLists.txt Thu Jan 10 20:39:36 2019 +0100 @@ -52,7 +52,8 @@ EmbedResources( - MYSQL_PREPARE_INDEX ${CMAKE_SOURCE_DIR}/Plugins/PrepareIndex.sql + MYSQL_PREPARE_INDEX ${CMAKE_SOURCE_DIR}/Plugins/PrepareIndex.sql + MYSQL_GET_LAST_CHANGE_INDEX ${CMAKE_SOURCE_DIR}/Plugins/GetLastChangeIndex.sql ) add_library(OrthancMySQLIndex SHARED diff -r d16e94157efe -r 48d445f756db MySQL/NEWS --- a/MySQL/NEWS Thu Jan 10 18:04:27 2019 +0100 +++ b/MySQL/NEWS Thu Jan 10 20:39:36 2019 +0100 @@ -1,6 +1,7 @@ Pending changes in the mainline =============================== +* Database optimizations by implementing new primitives of Orthanc SDK 1.5.2 * Characters "$" and "_" are allowed in MySQL database identifiers * Fix serialization of jobs if many of them diff -r d16e94157efe -r 48d445f756db MySQL/Plugins/GetLastChangeIndex.sql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MySQL/Plugins/GetLastChangeIndex.sql Thu Jan 10 20:39:36 2019 +0100 @@ -0,0 +1,16 @@ +CREATE TABLE GlobalIntegers( + property INTEGER PRIMARY KEY, + value BIGINT + ); + + +INSERT INTO GlobalIntegers +SELECT 0, COALESCE(MAX(seq), 0) FROM Changes; + + +CREATE TRIGGER ChangeAdded +AFTER INSERT ON Changes +FOR EACH ROW +BEGIN + UPDATE GlobalIntegers SET value = new.seq WHERE property = 0@ +END; diff -r d16e94157efe -r 48d445f756db MySQL/Plugins/MySQLIndex.cpp --- a/MySQL/Plugins/MySQLIndex.cpp Thu Jan 10 18:04:27 2019 +0100 +++ b/MySQL/Plugins/MySQLIndex.cpp Thu Jan 10 20:39:36 2019 +0100 @@ -128,7 +128,19 @@ SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision); } - if (revision != 2) + if (revision == 2) + { + std::string query; + + Orthanc::EmbeddedResources::GetFileResource + (query, Orthanc::EmbeddedResources::MYSQL_GET_LAST_CHANGE_INDEX); + db->Execute(query, true); + + revision = 3; + SetGlobalIntegerProperty(*db, t, Orthanc::GlobalProperty_DatabasePatchLevel, revision); + } + + if (revision != 3) { LOG(ERROR) << "MySQL plugin is incompatible with database schema revision: " << revision; throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); @@ -261,4 +273,17 @@ SignalDeletedFiles(); } + + + int64_t MySQLIndex::GetLastChangeIndex() + { + DatabaseManager::CachedStatement statement( + STATEMENT_FROM_HERE, GetManager(), + "SELECT value FROM GlobalIntegers WHERE property = 0"); + + statement.SetReadOnly(true); + statement.Execute(); + + return ReadInteger64(statement, 0); + } } diff -r d16e94157efe -r 48d445f756db MySQL/Plugins/MySQLIndex.h --- a/MySQL/Plugins/MySQLIndex.h Thu Jan 10 18:04:27 2019 +0100 +++ b/MySQL/Plugins/MySQLIndex.h Thu Jan 10 20:39:36 2019 +0100 @@ -74,5 +74,7 @@ OrthancPluginResourceType type); virtual void DeleteResource(int64_t id); + + virtual int64_t GetLastChangeIndex(); }; }