comparison OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp @ 5221:d0f7c742d397 db-protobuf

started implementation of labels
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 03 Apr 2023 20:53:14 +0200
parents df39c7583a49
children 988dab8deb1c
comparison
equal deleted inserted replaced
5220:df39c7583a49 5221:d0f7c742d397
1082 1082
1083 1083
1084 virtual void AddLabel(int64_t resource, 1084 virtual void AddLabel(int64_t resource,
1085 const std::string& label) ORTHANC_OVERRIDE 1085 const std::string& label) ORTHANC_OVERRIDE
1086 { 1086 {
1087 throw OrthancException(ErrorCode_NotImplemented); 1087 if (label.empty())
1088 {
1089 throw OrthancException(ErrorCode_ParameterOutOfRange);
1090 }
1091 else
1092 {
1093 SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT INTO Labels (internalId, label) VALUES(?, ?)");
1094 s.BindInt64(0, resource);
1095 s.BindString(1, label);
1096 s.Run();
1097 }
1088 } 1098 }
1089 1099
1090 1100
1091 virtual void RemoveLabel(int64_t resource, 1101 virtual void RemoveLabel(int64_t resource,
1092 const std::string& label) ORTHANC_OVERRIDE 1102 const std::string& label) ORTHANC_OVERRIDE
1093 { 1103 {
1094 throw OrthancException(ErrorCode_NotImplemented); 1104 if (label.empty())
1095 } 1105 {
1096 1106 throw OrthancException(ErrorCode_ParameterOutOfRange);
1097 1107 }
1098 virtual void GetLabels(std::set<std::string>& target, 1108 else
1099 int64_t resource) ORTHANC_OVERRIDE 1109 {
1100 { 1110 SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Labels WHERE internalId=? AND label=?");
1101 throw OrthancException(ErrorCode_NotImplemented); 1111 s.BindInt64(0, resource);
1112 s.BindString(1, label);
1113 s.Run();
1114 }
1115 }
1116
1117
1118 virtual void ListLabels(std::set<std::string>& target,
1119 int64_t resource) ORTHANC_OVERRIDE
1120 {
1121 target.clear();
1122
1123 SQLite::Statement s(db_, SQLITE_FROM_HERE,
1124 "SELECT label FROM Labels WHERE internalId=?");
1125 s.BindInt64(0, resource);
1126
1127 while (s.Step())
1128 {
1129 target.insert(s.ColumnString(0));
1130 }
1102 } 1131 }
1103 }; 1132 };
1104 1133
1105 1134
1106 class SQLiteDatabaseWrapper::SignalFileDeleted : public SQLite::IScalarFunction 1135 class SQLiteDatabaseWrapper::SignalFileDeleted : public SQLite::IScalarFunction
1371 { 1400 {
1372 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion, 1401 throw OrthancException(ErrorCode_IncompatibleDatabaseVersion,
1373 "Incompatible version of the Orthanc database: " + tmp); 1402 "Incompatible version of the Orthanc database: " + tmp);
1374 } 1403 }
1375 1404
1376 // New in Orthanc 1.5.1
1377 if (version_ == 6) 1405 if (version_ == 6)
1378 { 1406 {
1407 // New in Orthanc 1.5.1
1379 if (!transaction->LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast, true /* unused in SQLite */) || 1408 if (!transaction->LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast, true /* unused in SQLite */) ||
1380 tmp != "1") 1409 tmp != "1")
1381 { 1410 {
1382 LOG(INFO) << "Installing the SQLite triggers to track the size of the attachments"; 1411 LOG(INFO) << "Installing the SQLite triggers to track the size of the attachments";
1383 std::string query; 1412 std::string query;
1384 ServerResources::GetFileResource(query, ServerResources::INSTALL_TRACK_ATTACHMENTS_SIZE); 1413 ServerResources::GetFileResource(query, ServerResources::INSTALL_TRACK_ATTACHMENTS_SIZE);
1414 db_.Execute(query);
1415 }
1416
1417 // New in Orthanc 1.12.0
1418 if (!db_.DoesTableExist("Labels"))
1419 {
1420 LOG(INFO) << "Installing the \"Labels\" table";
1421 std::string query;
1422 ServerResources::GetFileResource(query, ServerResources::INSTALL_LABELS_TABLE);
1385 db_.Execute(query); 1423 db_.Execute(query);
1386 } 1424 }
1387 } 1425 }
1388 1426
1389 transaction->Commit(0); 1427 transaction->Commit(0);