# HG changeset patch # User Sebastien Jodogne # Date 1391603179 -3600 # Node ID 72dc919a028c06f905d83a0971247439a6618f1f # Parent 01d8611c4a60b7b4fc1f382f5954ea59e945915a upgrade database from v3 to v4 diff -r 01d8611c4a60 -r 72dc919a028c CMakeLists.txt --- a/CMakeLists.txt Tue Feb 04 17:52:51 2014 +0100 +++ b/CMakeLists.txt Wed Feb 05 13:26:19 2014 +0100 @@ -93,7 +93,7 @@ # Prepare the embedded files set(EMBEDDED_FILES PREPARE_DATABASE ${CMAKE_CURRENT_SOURCE_DIR}/OrthancServer/PrepareDatabase.sql - UPGRADE_3_TO_4 ${CMAKE_CURRENT_SOURCE_DIR}/OrthancServer/Upgrade3To4.sql + UPGRADE_DATABASE_3_TO_4 ${CMAKE_CURRENT_SOURCE_DIR}/OrthancServer/Upgrade3To4.sql CONFIGURATION_SAMPLE ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Configuration.json LUA_TOOLBOX ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Toolbox.lua ) diff -r 01d8611c4a60 -r 72dc919a028c Core/SQLite/FunctionContext.cpp --- a/Core/SQLite/FunctionContext.cpp Tue Feb 04 17:52:51 2014 +0100 +++ b/Core/SQLite/FunctionContext.cpp Wed Feb 05 13:26:19 2014 +0100 @@ -89,6 +89,12 @@ CheckIndex(index); return std::string(reinterpret_cast(sqlite3_value_text(argv_[index]))); } + + bool FunctionContext::IsNullValue(unsigned int index) const + { + CheckIndex(index); + return sqlite3_value_type(argv_[index]) == SQLITE_NULL; + } void FunctionContext::SetNullResult() { diff -r 01d8611c4a60 -r 72dc919a028c Core/SQLite/FunctionContext.h --- a/Core/SQLite/FunctionContext.h Tue Feb 04 17:52:51 2014 +0100 +++ b/Core/SQLite/FunctionContext.h Wed Feb 05 13:26:19 2014 +0100 @@ -74,6 +74,8 @@ double GetDoubleValue(unsigned int index) const; std::string GetStringValue(unsigned int index) const; + + bool IsNullValue(unsigned int index) const; void SetNullResult(); diff -r 01d8611c4a60 -r 72dc919a028c NEWS --- a/NEWS Tue Feb 04 17:52:51 2014 +0100 +++ b/NEWS Wed Feb 05 13:26:19 2014 +0100 @@ -4,9 +4,10 @@ * AET comparison is now case-insensitive by default * Possibility to disable the HTTP server or the DICOM server * Recover pixel data for more transfer syntaxes (notably JPEG) +* Automatic computation of MD5 hashes for the stored DICOM files * Maintenance tool to recover DICOM files compressed by Orthanc * The newline characters in the configuration file are fixed for Linux -* Capture of the SIGTERM signal +* Capture of the SIGTERM signal in Linux Version 0.7.2 (2013/11/08) diff -r 01d8611c4a60 -r 72dc919a028c OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Tue Feb 04 17:52:51 2014 +0100 +++ b/OrthancServer/DatabaseWrapper.cpp Wed Feb 05 13:26:19 2014 +0100 @@ -67,13 +67,25 @@ virtual void Compute(SQLite::FunctionContext& context) { + std::string uncompressedMD5, compressedMD5; + + if (!context.IsNullValue(5)) + { + uncompressedMD5 = context.GetStringValue(5); + } + + if (!context.IsNullValue(6)) + { + compressedMD5 = context.GetStringValue(6); + } + FileInfo info(context.GetStringValue(0), static_cast(context.GetIntValue(1)), static_cast(context.GetInt64Value(2)), - context.GetStringValue(5), + uncompressedMD5, static_cast(context.GetIntValue(3)), static_cast(context.GetInt64Value(4)), - context.GetStringValue(6)); + compressedMD5); listener_.SignalFileDeleted(info); } @@ -826,11 +838,24 @@ LOG(INFO) << "Version of the Orthanc database: " << version; unsigned int v = boost::lexical_cast(version); - // Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive) - // Version 4: from Orthanc 0.7.3 (inclusive) + /** + * History of the database versions: + * - Version 3: from Orthanc 0.3.2 to Orthanc 0.7.2 (inclusive) + * - Version 4: from Orthanc 0.7.3 (inclusive) + **/ + + // This version of Orthanc is only compatible with versions 3 of 4 of the DB schema + ok = (v == 3 || v == 4); - // This version of Orthanc is only compatible with version 4 of the DB schema - ok = (v == 4); + if (v == 3) + { + LOG(WARNING) << "Upgrading database version from 3 to 4"; + std::string upgrade; + EmbeddedResources::GetFileResource(upgrade, EmbeddedResources::UPGRADE_DATABASE_3_TO_4); + db_.BeginTransaction(); + db_.Execute(upgrade); + db_.CommitTransaction(); + } } catch (boost::bad_lexical_cast&) { diff -r 01d8611c4a60 -r 72dc919a028c OrthancServer/PrepareDatabase.sql --- a/OrthancServer/PrepareDatabase.sql Tue Feb 04 17:52:51 2014 +0100 +++ b/OrthancServer/PrepareDatabase.sql Wed Feb 05 13:26:19 2014 +0100 @@ -78,6 +78,7 @@ BEGIN SELECT SignalFileDeleted(old.uuid, old.fileType, old.uncompressedSize, old.compressionType, old.compressedSize, + -- These 2 arguments are new in Orthanc 0.7.3 (database v4) old.uncompressedMD5, old.compressedMD5); END; diff -r 01d8611c4a60 -r 72dc919a028c OrthancServer/Upgrade3To4.sql --- a/OrthancServer/Upgrade3To4.sql Tue Feb 04 17:52:51 2014 +0100 +++ b/OrthancServer/Upgrade3To4.sql Wed Feb 05 13:26:19 2014 +0100 @@ -1,3 +1,24 @@ --- Add 2 columns at "AttachedFiles" +-- This SQLite script updates the version of the Orthanc database from 3 to 4. + +-- Add 2 new columns at "AttachedFiles" + +ALTER TABLE AttachedFiles ADD COLUMN uncompressedMD5 TEXT; +ALTER TABLE AttachedFiles ADD COLUMN compressedMD5 TEXT; + +-- Update the "AttachedFileDeleted" trigger + +DROP TRIGGER AttachedFileDeleted; --- Delete & recreate trigger "AttachedFileDeleted" +CREATE TRIGGER AttachedFileDeleted +AFTER DELETE ON AttachedFiles +BEGIN + SELECT SignalFileDeleted(old.uuid, old.fileType, old.uncompressedSize, + old.compressionType, old.compressedSize, + -- These 2 arguments are new in Orthanc 0.7.3 (database v4) + old.uncompressedMD5, old.compressedMD5); +END; + +-- Change the database version +-- The "1" corresponds to the "GlobalProperty_DatabaseSchemaVersion" enumeration + +UPDATE GlobalProperties SET value="4" WHERE property=1;