Mercurial > hg > orthanc-databases
changeset 794:b3ee20f1bb83
fix case sensitive search for MySQL
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Tue, 20 Jan 2026 16:41:54 +0100 |
| parents | 15f949790d84 |
| children | 14ca14e0fd1e |
| files | Framework/Plugins/ISqlLookupFormatter.cpp Framework/Plugins/ISqlLookupFormatter.h Framework/Plugins/IndexBackend.cpp |
| diffstat | 3 files changed, 41 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Plugins/ISqlLookupFormatter.cpp Thu Jan 15 12:38:01 2026 +0100 +++ b/Framework/Plugins/ISqlLookupFormatter.cpp Tue Jan 20 16:41:54 2026 +0100 @@ -228,17 +228,9 @@ } std::string parameter = formatter.GenerateParameter(escaped); - - if (isCaseSensitive) - { - comparison = (tag + ".value LIKE " + parameter + " " + - formatter.FormatWildcardEscape()); - } - else - { - comparison = ("lower(" + tag + ".value) LIKE lower(" + - parameter + ") " + formatter.FormatWildcardEscape()); - } + comparison = formatter.FormatLike(isCaseSensitive, + tag + ".value", + parameter); } break; @@ -644,15 +636,9 @@ } std::string parameter = formatter.GenerateParameter(escaped); - - if (constraint.IsCaseSensitive()) - { - comparison = " AND value LIKE " + parameter + " " + formatter.FormatWildcardEscape(); - } - else - { - comparison = " AND lower(value) LIKE lower(" + parameter + ") " + formatter.FormatWildcardEscape(); - } + comparison = " AND " + formatter.FormatLike(constraint.IsCaseSensitive(), + "value", + parameter); } break; @@ -1130,7 +1116,7 @@ where.push_back("(SELECT COUNT(1) FROM Labels AS selectedLabels WHERE selectedLabels.id = " + strQueryLevel + ".internalId AND selectedLabels.label IN (" + Join(formattedLabels, "", ", ") + ")) " + condition); } - else if (request.labels_constraint() == LabelsConstraint_None) // from 1.12.11, 'None' with an empty labels list means "list all resources without any labels" + else if (request.labels_constraint() == ::Orthanc::DatabasePluginMessages::LabelsConstraintType::LABELS_CONSTRAINT_NONE) // from 1.12.11, 'None' with an empty labels list means "list all resources without any labels" { where.push_back("(SELECT COUNT(1) FROM Labels WHERE id = " + FormatLevel(queryLevel) + ".internalId) = 0"); }
--- a/Framework/Plugins/ISqlLookupFormatter.h Thu Jan 15 12:38:01 2026 +0100 +++ b/Framework/Plugins/ISqlLookupFormatter.h Tue Jan 20 16:41:54 2026 +0100 @@ -67,6 +67,8 @@ virtual std::string FormatNull(const char* type) = 0; + virtual std::string FormatLike(bool isCaseSensitive, const std::string& a, const std::string& b) = 0; + /** * Whether to escape '[' and ']', which is only needed for * MSSQL. New in Orthanc 1.10.0, from the following changeset:
--- a/Framework/Plugins/IndexBackend.cpp Thu Jan 15 12:38:01 2026 +0100 +++ b/Framework/Plugins/IndexBackend.cpp Tue Jan 20 16:41:54 2026 +0100 @@ -2226,6 +2226,38 @@ } } + virtual std::string FormatLike(bool isCaseSensitive, const std::string& a, const std::string& b) + { + switch (dialect_) + { + case Dialect_MySQL: // LIKE is case insensitive by default ! + { + if (isCaseSensitive) + { + return a + " LIKE BINARY " + b + " " + FormatWildcardEscape(); + } + else + { + return a + " LIKE " + b + " " + FormatWildcardEscape(); + } + }; break; + case Dialect_PostgreSQL: // LIKE is case sensitive by default ! + { + if (isCaseSensitive) + { + return a + " LIKE " + b + " " + FormatWildcardEscape(); + } + else + { + return "lower(" + a + ") LIKE lower(" + b + ") " + FormatWildcardEscape(); + } + }; break; + case Dialect_MSSQL: + case Dialect_SQLite: + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); + } + } virtual std::string FormatLimits(uint64_t since, uint64_t count) {
