changeset 354:2a3bbb4104fa

fix changeset 389c037387ea
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 25 Nov 2021 13:17:51 +0100
parents 389c037387ea
children 0513c1b7988b
files Framework/Plugins/IndexBackend.cpp Resources/Orthanc/CMake/DownloadOrthancFramework.cmake Resources/Orthanc/Databases/ISqlLookupFormatter.cpp Resources/Orthanc/Databases/ISqlLookupFormatter.h
diffstat 4 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/IndexBackend.cpp	Mon Nov 15 12:22:44 2021 +0100
+++ b/Framework/Plugins/IndexBackend.cpp	Thu Nov 25 13:17:51 2021 +0100
@@ -2025,6 +2025,13 @@
       }
     }
 
+    virtual bool IsEscapeBrackets() const
+    {
+      // This was initially done at a bad location by the following changeset:
+      // https://hg.orthanc-server.com/orthanc-databases/rev/389c037387ea
+      return (dialect_ == Dialect_MSSQL);
+    }
+
     void PrepareStatement(DatabaseManager::StandaloneStatement& statement) const
     {
       statement.SetReadOnly(true);
--- a/Resources/Orthanc/CMake/DownloadOrthancFramework.cmake	Mon Nov 15 12:22:44 2021 +0100
+++ b/Resources/Orthanc/CMake/DownloadOrthancFramework.cmake	Thu Nov 25 13:17:51 2021 +0100
@@ -136,6 +136,8 @@
         set(ORTHANC_FRAMEWORK_MD5 "10fc64de1254a095e5d3ed3931f0cfbb")
       elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.9.6")
         set(ORTHANC_FRAMEWORK_MD5 "4b5d05683d747c29b2860ad79d11e62e")
+      elseif (ORTHANC_FRAMEWORK_VERSION STREQUAL "1.9.7")
+        set(ORTHANC_FRAMEWORK_MD5 "c912bbb860d640d3ae3003b5c9698205")
 
       # Below this point are development snapshots that were used to
       # release some plugin, before an official release of the Orthanc
--- a/Resources/Orthanc/Databases/ISqlLookupFormatter.cpp	Mon Nov 15 12:22:44 2021 +0100
+++ b/Resources/Orthanc/Databases/ISqlLookupFormatter.cpp	Thu Nov 25 13:17:51 2021 +0100
@@ -67,7 +67,8 @@
   static bool FormatComparison(std::string& target,
                                ISqlLookupFormatter& formatter,
                                const DatabaseConstraint& constraint,
-                               size_t index)
+                               size_t index,
+                               bool escapeBrackets)
   {
     std::string tag = "t" + boost::lexical_cast<std::string>(index);
 
@@ -172,14 +173,6 @@
             {
               escaped += "_";
             }
-            else if (value[i] == '[')
-            {
-              escaped += "\\[";
-            }
-            else if (value[i] == ']')
-            {
-              escaped += "\\]";
-            }
             else if (value[i] == '%')
             {
               escaped += "\\%";
@@ -192,6 +185,14 @@
             {
               escaped += "\\\\";
             }
+            else if (escapeBrackets && value[i] == '[')
+            {
+              escaped += "\\[";
+            }
+            else if (escapeBrackets && value[i] == ']')
+            {
+              escaped += "\\]";
+            }
             else
             {
               escaped += value[i];
@@ -299,6 +300,8 @@
     assert(upperLevel <= queryLevel &&
            queryLevel <= lowerLevel);
 
+    const bool escapeBrackets = formatter.IsEscapeBrackets();
+    
     std::string joins, comparisons;
 
     size_t count = 0;
@@ -307,7 +310,7 @@
     {
       std::string comparison;
       
-      if (FormatComparison(comparison, formatter, lookup[i], count))
+      if (FormatComparison(comparison, formatter, lookup[i], count, escapeBrackets))
       {
         std::string join;
         FormatJoin(join, lookup[i], count);
--- a/Resources/Orthanc/Databases/ISqlLookupFormatter.h	Mon Nov 15 12:22:44 2021 +0100
+++ b/Resources/Orthanc/Databases/ISqlLookupFormatter.h	Thu Nov 25 13:17:51 2021 +0100
@@ -48,6 +48,13 @@
 
     virtual std::string FormatWildcardEscape() = 0;
 
+    /**
+     * Whether to escape '[' and ']', which is only needed for
+     * MSSQL. New in Orthanc 1.9.8, from the following changeset:
+     * https://hg.orthanc-server.com/orthanc-databases/rev/389c037387ea
+     **/
+    virtual bool IsEscapeBrackets() const = 0;
+
     static void Apply(std::string& sql,
                       ISqlLookupFormatter& formatter,
                       const std::vector<DatabaseConstraint>& lookup,