# HG changeset patch # User Sebastien Jodogne # Date 1637842155 -3600 # Node ID b8fcd331b4b393d2aba9f659ce48c2907b622cc3 # Parent 46bfa3a4fd6329b58424c5ab2d67dc027e551196 added ISqlLookupFormatter::IsEscapeBrackets() diff -r 46bfa3a4fd63 -r b8fcd331b4b3 OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp --- 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; diff -r 46bfa3a4fd63 -r b8fcd331b4b3 OrthancServer/Sources/Search/ISqlLookupFormatter.cpp --- 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(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); diff -r 46bfa3a4fd63 -r b8fcd331b4b3 OrthancServer/Sources/Search/ISqlLookupFormatter.h --- 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& lookup,