changeset 4817:b8fcd331b4b3

added ISqlLookupFormatter::IsEscapeBrackets()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 25 Nov 2021 13:09:15 +0100
parents 46bfa3a4fd63
children c0986ae1b9fc
files OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/Search/ISqlLookupFormatter.cpp OrthancServer/Sources/Search/ISqlLookupFormatter.h
diffstat 3 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Wed Nov 24 18:03:35 2021 +0100
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Thu Nov 25 13:09:15 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	Wed Nov 24 18:03:35 2021 +0100
+++ b/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp	Thu Nov 25 13:09:15 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	Wed Nov 24 18:03:35 2021 +0100
+++ b/OrthancServer/Sources/Search/ISqlLookupFormatter.h	Thu Nov 25 13:09:15 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,