changeset 4818:c0986ae1b9fc

merge
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 25 Nov 2021 13:09:27 +0100
parents b8fcd331b4b3 (diff) 58637d39ce88 (current diff)
children 70d2a97ca8cb 381c2ca04860
files
diffstat 3 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Thu Nov 25 12:14:14 2021 +0100
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Thu Nov 25 13:09:27 2021 +0100
@@ -74,6 +74,11 @@
       return "ESCAPE '\\'";
     }
 
+    virtual bool IsEscapeBrackets() const ORTHANC_OVERRIDE
+    {
+      return false;
+    }
+
     void Bind(SQLite::Statement& statement) const
     {
       size_t pos = 0;
--- a/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp	Thu Nov 25 12:14:14 2021 +0100
+++ b/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp	Thu Nov 25 13:09:27 2021 +0100
@@ -79,7 +79,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);
 
@@ -196,6 +197,14 @@
             {
               escaped += "\\\\";
             }
+            else if (escapeBrackets && value[i] == '[')
+            {
+              escaped += "\\[";
+            }
+            else if (escapeBrackets && value[i] == ']')
+            {
+              escaped += "\\]";
+            }
             else
             {
               escaped += value[i];
@@ -303,6 +312,8 @@
     assert(upperLevel <= queryLevel &&
            queryLevel <= lowerLevel);
 
+    const bool escapeBrackets = formatter.IsEscapeBrackets();
+    
     std::string joins, comparisons;
 
     size_t count = 0;
@@ -311,7 +322,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/OrthancServer/Sources/Search/ISqlLookupFormatter.h	Thu Nov 25 12:14:14 2021 +0100
+++ b/OrthancServer/Sources/Search/ISqlLookupFormatter.h	Thu Nov 25 13:09:27 2021 +0100
@@ -60,6 +60,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,