Mercurial > hg > orthanc
diff OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp @ 5080:d7274e43ea7c attach-custom-data
allow plugins to store a customData in the Attachments table to e.g. store custom paths without requiring an external DB
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 08 Sep 2022 17:42:08 +0200 |
parents | e6f26be401fa |
children | 9770d537880d |
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp Wed Aug 31 10:36:38 2022 +0200 +++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp Thu Sep 08 17:42:08 2022 +0200 @@ -324,7 +324,9 @@ int64_t revision) ORTHANC_OVERRIDE { // TODO - REVISIONS - SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?, ?, ?)"); + SQLite::Statement s(db_, SQLITE_FROM_HERE, + "INSERT INTO AttachedFiles (id, fileType, uuid, compressedSize, uncompressedSize, compressionType, uncompressedMD5, compressedMD5, customData) " + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"); s.BindInt64(0, id); s.BindInt(1, attachment.GetContentType()); s.BindString(2, attachment.GetUuid()); @@ -333,10 +335,10 @@ s.BindInt(5, attachment.GetCompressionType()); s.BindString(6, attachment.GetUncompressedMD5()); s.BindString(7, attachment.GetCompressedMD5()); + s.BindString(8, attachment.GetCustomData()); s.Run(); } - virtual void ApplyLookupResources(std::list<std::string>& resourcesId, std::list<std::string>* instancesId, const std::vector<DatabaseConstraint>& lookup, @@ -801,7 +803,7 @@ { SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT uuid, uncompressedSize, compressionType, compressedSize, " - "uncompressedMD5, compressedMD5 FROM AttachedFiles WHERE id=? AND fileType=?"); + "uncompressedMD5, compressedMD5, customData FROM AttachedFiles WHERE id=? AND fileType=?"); s.BindInt64(0, id); s.BindInt(1, contentType); @@ -817,7 +819,8 @@ s.ColumnString(4), static_cast<CompressionType>(s.ColumnInt(2)), s.ColumnInt64(3), - s.ColumnString(5)); + s.ColumnString(5), + s.ColumnString(6)); revision = 0; // TODO - REVISIONS return true; } @@ -1098,14 +1101,14 @@ virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE { - return 7; + return 8; } virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE { if (sqlite_.activeTransaction_ != NULL) { - std::string uncompressedMD5, compressedMD5; + std::string uncompressedMD5, compressedMD5, customData; if (!context.IsNullValue(5)) { @@ -1117,13 +1120,19 @@ compressedMD5 = context.GetStringValue(6); } + if (!context.IsNullValue(7)) + { + customData = context.GetStringValue(7); + } + FileInfo info(context.GetStringValue(0), static_cast<FileContentType>(context.GetIntValue(1)), static_cast<uint64_t>(context.GetInt64Value(2)), uncompressedMD5, static_cast<CompressionType>(context.GetIntValue(3)), static_cast<uint64_t>(context.GetInt64Value(4)), - compressedMD5); + compressedMD5, + customData); sqlite_.activeTransaction_->GetListener().SignalAttachmentDeleted(info); } @@ -1351,7 +1360,7 @@ } // New in Orthanc 1.5.1 - if (version_ == 6) + if (version_ >= 6) { if (!transaction->LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast, true /* unused in SQLite */) || tmp != "1") @@ -1393,7 +1402,7 @@ { boost::mutex::scoped_lock lock(mutex_); - if (targetVersion != 6) + if (targetVersion != 7) { throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); } @@ -1403,7 +1412,8 @@ if (version_ != 3 && version_ != 4 && version_ != 5 && - version_ != 6) + version_ != 6 && + version_ != 7) { throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); } @@ -1444,6 +1454,14 @@ version_ = 6; } + + if (version_ == 6) + { + LOG(WARNING) << "Upgrading database version from 6 to 7"; + ExecuteUpgradeScript(db_, ServerResources::UPGRADE_DATABASE_6_TO_7); + version_ = 7; + } + }