changeset 5256:261ce0ed85e6 db-protobuf

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Apr 2023 20:50:43 +0200
parents f783b99e4738
children afe92108f463
files OrthancServer/Sources/Database/InstallLabelsTable.sql OrthancServer/Sources/Database/PrepareDatabase.sql OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/Sources/Search/ISqlLookupFormatter.cpp
diffstat 5 files changed, 14 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/InstallLabelsTable.sql	Tue Apr 11 16:28:28 2023 +0200
+++ b/OrthancServer/Sources/Database/InstallLabelsTable.sql	Tue Apr 11 20:50:43 2023 +0200
@@ -19,10 +19,10 @@
 
 
 CREATE TABLE Labels(
-       internalId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
+       id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
        label TEXT NOT NULL,
-       PRIMARY KEY(internalId, label)  -- Prevents duplicates
+       PRIMARY KEY(id, label)  -- Prevents duplicates
        );
 
-CREATE INDEX LabelsIndex1 ON Labels(internalId);
+CREATE INDEX LabelsIndex1 ON Labels(id);
 CREATE INDEX LabelsIndex2 ON Labels(label);  -- This index allows efficient lookups
--- a/OrthancServer/Sources/Database/PrepareDatabase.sql	Tue Apr 11 16:28:28 2023 +0200
+++ b/OrthancServer/Sources/Database/PrepareDatabase.sql	Tue Apr 11 20:50:43 2023 +0200
@@ -93,9 +93,9 @@
 
 -- New in Orthanc 1.12.0
 CREATE TABLE Labels(
-       internalId INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
+       id INTEGER REFERENCES Resources(internalId) ON DELETE CASCADE,
        label TEXT NOT NULL,
-       PRIMARY KEY(internalId, label)  -- Prevents duplicates
+       PRIMARY KEY(id, label)  -- Prevents duplicates
        );
 
 CREATE INDEX ChildrenIndex ON Resources(parentId);
@@ -116,7 +116,7 @@
 CREATE INDEX ChangesIndex ON Changes(internalId);
 
 -- New in Orthanc 1.12.0
-CREATE INDEX LabelsIndex1 ON Labels(internalId);
+CREATE INDEX LabelsIndex1 ON Labels(id);
 CREATE INDEX LabelsIndex2 ON Labels(label);  -- This index allows efficient lookups
 
 CREATE TRIGGER AttachedFileDeleted
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Tue Apr 11 16:28:28 2023 +0200
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Tue Apr 11 20:50:43 2023 +0200
@@ -1084,7 +1084,7 @@
       }
       else
       {
-        SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR IGNORE INTO Labels (internalId, label) VALUES(?, ?)");
+        SQLite::Statement s(db_, SQLITE_FROM_HERE, "INSERT OR IGNORE INTO Labels (id, label) VALUES(?, ?)");
         s.BindInt64(0, resource);
         s.BindString(1, label);
         s.Run();
@@ -1101,7 +1101,7 @@
       }
       else
       {
-        SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Labels WHERE internalId=? AND label=?");
+        SQLite::Statement s(db_, SQLITE_FROM_HERE, "DELETE FROM Labels WHERE id=? AND label=?");
         s.BindInt64(0, resource);
         s.BindString(1, label);
         s.Run();
@@ -1115,7 +1115,7 @@
       target.clear();
 
       SQLite::Statement s(db_, SQLITE_FROM_HERE, 
-                          "SELECT label FROM Labels WHERE internalId=?");
+                          "SELECT label FROM Labels WHERE id=?");
       s.BindInt64(0, resource);
 
       while (s.Step())
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp	Tue Apr 11 16:28:28 2023 +0200
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestModalities.cpp	Tue Apr 11 20:50:43 2023 +0200
@@ -1431,7 +1431,7 @@
                          "Host that is used for this commands, defaults to `Host` configuration option. "
                          "Allows you to overwrite the destination host for a specific operation.", false)
         .SetRequestField(KEY_PORT, RestApiCallDocumentation::Type_Number,
-                         "Port that is used for this commands, defaults to `Port` configuration option. "
+                         "Port that is used for this command, defaults to `Port` configuration option. "
                          "Allows you to overwrite the destination port for a specific operation.", false)
         .SetRequestField(KEY_MOVE_ORIGINATOR_AET, RestApiCallDocumentation::Type_String,
                          "Move originator AET that is used for this commands, in order to fake a C-MOVE SCU", false)
--- a/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp	Tue Apr 11 16:28:28 2023 +0200
+++ b/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp	Tue Apr 11 20:50:43 2023 +0200
@@ -383,6 +383,8 @@
     }
 
     std::list<std::string> where;
+    where.push_back(FormatLevel(queryLevel) + ".resourceType = " +
+                    formatter.FormatResourceType(queryLevel) + comparisons);
 
     if (!labels.empty())
     {
@@ -418,12 +420,9 @@
           throw OrthancException(ErrorCode_ParameterOutOfRange);
       }
       
-      where.push_back("(SELECT COUNT(1) FROM Labels WHERE internalId = " + FormatLevel(queryLevel) +
-                      ".internalId AND label IN (" + Join(formattedLabels, "", ", ") + ")) " + condition);
+      where.push_back("(SELECT COUNT(1) FROM Labels AS selectedLabels WHERE selectedLabels.id = " + FormatLevel(queryLevel) +
+                      ".internalId AND selectedLabels.label IN (" + Join(formattedLabels, "", ", ") + ")) " + condition);
     }
-    
-    where.push_back(FormatLevel(queryLevel) + ".resourceType = " +
-                    formatter.FormatResourceType(queryLevel) + comparisons);
 
     sql += joins + Join(where, " WHERE ", " AND ");