# HG changeset patch # User Sebastien Jodogne # Date 1354024795 -3600 # Node ID 530a25320461daba02578ed66190ac1cc9815e41 # Parent 6d0225a26fd899fba6572a375b93e147a7f20440 removal of text as ids in sqlite db diff -r 6d0225a26fd8 -r 530a25320461 OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Fri Nov 16 08:23:05 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.cpp Tue Nov 27 14:59:55 2012 +0100 @@ -316,7 +316,7 @@ } void DatabaseWrapper::AttachFile(int64_t id, - const std::string& contentName, + AttachedFileType contentType, const std::string& fileUuid, uint64_t compressedSize, uint64_t uncompressedSize, @@ -324,7 +324,7 @@ { SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO AttachedFiles VALUES(?, ?, ?, ?, ?, ?)"); s.BindInt(0, id); - s.BindString(1, contentName); + s.BindInt(1, contentType); s.BindString(2, fileUuid); s.BindInt(3, compressedSize); s.BindInt(4, uncompressedSize); @@ -333,16 +333,16 @@ } bool DatabaseWrapper::LookupFile(int64_t id, - const std::string& contentName, + AttachedFileType contentType, std::string& fileUuid, uint64_t& compressedSize, uint64_t& uncompressedSize, CompressionType& compressionType) { SQLite::Statement s(db_, SQLITE_FROM_HERE, - "SELECT uuid, compressedSize, uncompressedSize, compressionType FROM AttachedFiles WHERE id=? AND contentName=?"); + "SELECT uuid, compressedSize, uncompressedSize, compressionType FROM AttachedFiles WHERE id=? AND fileType=?"); s.BindInt(0, id); - s.BindString(1, contentName); + s.BindInt(1, contentType); if (!s.Step()) { diff -r 6d0225a26fd8 -r 530a25320461 OrthancServer/DatabaseWrapper.h --- a/OrthancServer/DatabaseWrapper.h Fri Nov 16 08:23:05 2012 +0100 +++ b/OrthancServer/DatabaseWrapper.h Tue Nov 27 14:59:55 2012 +0100 @@ -99,22 +99,22 @@ const std::string& defaultValue = ""); void AttachFile(int64_t id, - const std::string& contentName, + AttachedFileType contentType, const std::string& fileUuid, uint64_t compressedSize, uint64_t uncompressedSize, CompressionType compressionType); void AttachFile(int64_t id, - const std::string& contentName, + AttachedFileType contentType, const std::string& fileUuid, uint64_t fileSize) { - AttachFile(id, contentName, fileUuid, fileSize, fileSize, CompressionType_None); + AttachFile(id, contentType, fileUuid, fileSize, fileSize, CompressionType_None); } bool LookupFile(int64_t id, - const std::string& contentName, + AttachedFileType contentType, std::string& fileUuid, uint64_t& compressedSize, uint64_t& uncompressedSize, diff -r 6d0225a26fd8 -r 530a25320461 OrthancServer/OrthancRestApi.cpp --- a/OrthancServer/OrthancRestApi.cpp Fri Nov 16 08:23:05 2012 +0100 +++ b/OrthancServer/OrthancRestApi.cpp Tue Nov 27 14:59:55 2012 +0100 @@ -572,14 +572,14 @@ std::string fileUuid, contentType, filename; if (uri[2] == "file") { - existingResource = index_.GetFile(fileUuid, compressionType, uri[1], "dicom"); + existingResource = index_.GetFile(fileUuid, compressionType, uri[1], AttachedFileType_Dicom); contentType = "application/dicom"; filename = fileUuid + ".dcm"; } else if (uri[2] == "tags" || uri[2] == "simplified-tags") { - existingResource = index_.GetFile(fileUuid, compressionType, uri[1], "json"); + existingResource = index_.GetFile(fileUuid, compressionType, uri[1], AttachedFileType_Json); contentType = "application/json"; filename = fileUuid + ".json"; } @@ -644,7 +644,7 @@ { std::string uuid; CompressionType compressionType; - existingResource = index_.GetFile(uuid, compressionType, uri[1], "dicom"); + existingResource = index_.GetFile(uuid, compressionType, uri[1], AttachedFileType_Dicom); std::string action = uri[2]; diff -r 6d0225a26fd8 -r 530a25320461 OrthancServer/PrepareDatabase2.sql --- a/OrthancServer/PrepareDatabase2.sql Fri Nov 16 08:23:05 2012 +0100 +++ b/OrthancServer/PrepareDatabase2.sql Tue Nov 27 14:59:55 2012 +0100 @@ -27,12 +27,12 @@ CREATE TABLE AttachedFiles( id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE, - contentName TEXT, + fileType INTEGER, uuid TEXT, compressedSize INTEGER, uncompressedSize INTEGER, compressionType INTEGER, - PRIMARY KEY(id, contentName) + PRIMARY KEY(id, fileType) ); CREATE TABLE Changes( diff -r 6d0225a26fd8 -r 530a25320461 OrthancServer/ServerEnumerations.h --- a/OrthancServer/ServerEnumerations.h Fri Nov 16 08:23:05 2012 +0100 +++ b/OrthancServer/ServerEnumerations.h Tue Nov 27 14:59:55 2012 +0100 @@ -29,7 +29,6 @@ * along with this program. If not, see . **/ - #pragma once namespace Orthanc @@ -81,4 +80,10 @@ ChangeType_NewStudy = 5, ChangeType_InvalidSeries = 6 }; + + enum AttachedFileType + { + AttachedFileType_Dicom = 1, + AttachedFileType_Json = 2 + }; } diff -r 6d0225a26fd8 -r 530a25320461 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Fri Nov 16 08:23:05 2012 +0100 +++ b/OrthancServer/ServerIndex.cpp Tue Nov 27 14:59:55 2012 +0100 @@ -589,8 +589,8 @@ } // Attach the files to the newly created instance - db2_->AttachFile(instance, "dicom", fileUuid, uncompressedFileSize); - db2_->AttachFile(instance, "json", jsonUuid, 0); // TODO "0" + db2_->AttachFile(instance, AttachedFileType_Dicom, fileUuid, uncompressedFileSize); + db2_->AttachFile(instance, AttachedFileType_Json, jsonUuid, 0); // TODO "0" // Attach the metadata db2_->SetMetadata(instance, MetadataType_Instance_ReceptionDate, Toolbox::GetNowIsoString()); @@ -946,7 +946,7 @@ bool ServerIndex::GetFile(std::string& fileUuid, CompressionType& compressionType, const std::string& instanceUuid, - const std::string& contentName) + AttachedFileType contentType) { boost::mutex::scoped_lock scoped_lock(mutex_); @@ -960,7 +960,7 @@ uint64_t compressedSize, uncompressedSize; - return db2_->LookupFile(id, contentName, fileUuid, compressedSize, uncompressedSize, compressionType); + return db2_->LookupFile(id, contentType, fileUuid, compressedSize, uncompressedSize, compressionType); } diff -r 6d0225a26fd8 -r 530a25320461 OrthancServer/ServerIndex.h --- a/OrthancServer/ServerIndex.h Fri Nov 16 08:23:05 2012 +0100 +++ b/OrthancServer/ServerIndex.h Tue Nov 27 14:59:55 2012 +0100 @@ -159,7 +159,7 @@ bool GetFile(std::string& fileUuid, CompressionType& compressionType, const std::string& instanceUuid, - const std::string& contentName); + AttachedFileType contentType); void GetAllUuids(Json::Value& target, ResourceType resourceType); diff -r 6d0225a26fd8 -r 530a25320461 UnitTests/ServerIndex.cpp --- a/UnitTests/ServerIndex.cpp Fri Nov 16 08:23:05 2012 +0100 +++ b/UnitTests/ServerIndex.cpp Tue Nov 27 14:59:55 2012 +0100 @@ -109,9 +109,9 @@ ASSERT_EQ("e", l.front()); } - index.AttachFile(a[4], "_json", "my json file", 21, 42, CompressionType_Zlib); - index.AttachFile(a[4], "_dicom", "my dicom file", 42); - index.AttachFile(a[6], "_hello", "world", 44); + index.AttachFile(a[4], AttachedFileType_Json, "my json file", 21, 42, CompressionType_Zlib); + index.AttachFile(a[4], AttachedFileType_Dicom, "my dicom file", 42); + index.AttachFile(a[6], AttachedFileType_Dicom, "world", 44); index.SetMetadata(a[4], MetadataType_Instance_RemoteAet, "PINNACLE"); ASSERT_EQ(21 + 42 + 44, index.GetTotalCompressedSize()); @@ -141,7 +141,7 @@ uint64_t us, cs; CompressionType ct; - ASSERT_TRUE(index.LookupFile(a[4], "_json", s, cs, us, ct)); + ASSERT_TRUE(index.LookupFile(a[4], AttachedFileType_Json, s, cs, us, ct)); ASSERT_EQ("my json file", s); ASSERT_EQ(21, cs); ASSERT_EQ(42, us);