diff OrthancServer/Sources/Search/ISqlLookupFormatter.cpp @ 5256:261ce0ed85e6 db-protobuf

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Apr 2023 20:50:43 +0200
parents a7d95f951f8a
children 7f37233359aa
line wrap: on
line diff
--- 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 ");