Mercurial > hg > orthanc
changeset 6561:f2de0250584c
removed unused code: ApplyLookupResources & related functions that were only used in the unit tests
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Wed, 14 Jan 2026 19:06:30 +0100 |
| parents | ca3056469cea |
| children | d4a3c883f6c1 |
| files | OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h OrthancServer/Sources/Search/ISqlLookupFormatter.cpp OrthancServer/Sources/Search/ISqlLookupFormatter.h OrthancServer/UnitTestsSources/ServerIndexTests.cpp |
| diffstat | 5 files changed, 50 insertions(+), 182 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp Wed Jan 14 18:24:29 2026 +0100 +++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp Wed Jan 14 19:06:30 2026 +0100 @@ -441,48 +441,6 @@ s.Run(); } - virtual void ApplyLookupResources(std::list<std::string>& resourcesId, - std::list<std::string>* instancesId, - const DatabaseDicomTagConstraints& lookup, - ResourceType queryLevel, - const std::set<std::string>& labels, - LabelsConstraint labelsConstraint, - uint32_t limit) ORTHANC_OVERRIDE - { - LookupFormatter formatter; - - std::string sql; - LookupFormatter::Apply(sql, formatter, lookup, queryLevel, labels, labelsConstraint, limit); - - sql = "CREATE TEMPORARY TABLE Lookup AS " + sql; // TODO-FIND: use a CTE (or is this method obsolete ?) - - { - SQLite::Statement s(db_, SQLITE_FROM_HERE, "DROP TABLE IF EXISTS Lookup"); - s.Run(); - } - - { - SQLite::Statement statement(db_, sql); - formatter.Bind(statement); - statement.Run(); - } - - if (instancesId != NULL) - { - AnswerLookup(resourcesId, *instancesId, queryLevel); - } - else - { - resourcesId.clear(); - - SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT publicId FROM Lookup"); - - while (s.Step()) - { - resourcesId.push_back(s.ColumnString(0)); - } - } - } #define C0_QUERY_ID 0 #define C1_INTERNAL_ID 1
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h Wed Jan 14 18:24:29 2026 +0100 +++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h Wed Jan 14 19:06:30 2026 +0100 @@ -112,7 +112,7 @@ * "UnitTestsTransaction" give access to additional information * about the underlying SQLite database to be used in unit tests. **/ - class UnitTestsTransaction : public BaseCompatibilityTransaction + class UnitTestsTransaction : public BaseCompatibilityTransaction // TODO: replace by IDatabaseWrapper::ITransaction and remove all compatibility methods from the SQLiteDatabaseWrapper ? { protected: SQLite::Connection& db_; @@ -144,6 +144,17 @@ void SetMainDicomTag(int64_t id, const DicomTag& tag, const std::string& value); + + virtual void ApplyLookupResources(std::list<std::string>& resourcesId, + std::list<std::string>* instancesId, + const DatabaseDicomTagConstraints& lookup, + ResourceType queryLevel, + const std::set<std::string>& labels, + LabelsConstraint labelsConstraint, + uint32_t limit) ORTHANC_OVERRIDE + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); // this function is not supposed to be called with the SQLite engine + } }; }; }
--- a/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp Wed Jan 14 18:24:29 2026 +0100 +++ b/OrthancServer/Sources/Search/ISqlLookupFormatter.cpp Wed Jan 14 19:06:30 2026 +0100 @@ -609,120 +609,6 @@ void ISqlLookupFormatter::Apply(std::string& sql, ISqlLookupFormatter& formatter, - const DatabaseDicomTagConstraints& lookup, - ResourceType queryLevel, - const std::set<std::string>& labels, - LabelsConstraint labelsConstraint, - size_t limit) - { - // get the limit levels of the DICOM Tags lookup - ResourceType lowerLevel, upperLevel; - GetLookupLevels(lowerLevel, upperLevel, queryLevel, lookup); - - assert(upperLevel <= queryLevel && - queryLevel <= lowerLevel); - - const bool escapeBrackets = formatter.IsEscapeBrackets(); - - std::string joins, comparisons; - - size_t count = 0; - - for (size_t i = 0; i < lookup.GetSize(); i++) - { - const DatabaseDicomTagConstraint& constraint = lookup.GetConstraint(i); - - std::string comparison; - - if (FormatComparison(comparison, formatter, constraint, count, escapeBrackets)) - { - std::string join; - FormatJoin(join, constraint, count); - joins += join; - - if (!comparison.empty()) - { - comparisons += " AND " + comparison; - } - - count ++; - } - } - - sql = ("SELECT " + - FormatLevel(queryLevel) + ".publicId, " + - FormatLevel(queryLevel) + ".internalId" + - " FROM Resources AS " + FormatLevel(queryLevel)); - - for (int level = queryLevel - 1; level >= upperLevel; level--) - { - sql += (" INNER JOIN Resources " + - FormatLevel(static_cast<ResourceType>(level)) + " ON " + - FormatLevel(static_cast<ResourceType>(level)) + ".internalId=" + - FormatLevel(static_cast<ResourceType>(level + 1)) + ".parentId"); - } - - for (int level = queryLevel + 1; level <= lowerLevel; level++) - { - sql += (" INNER JOIN Resources " + - FormatLevel(static_cast<ResourceType>(level)) + " ON " + - FormatLevel(static_cast<ResourceType>(level - 1)) + ".internalId=" + - FormatLevel(static_cast<ResourceType>(level)) + ".parentId"); - } - - std::list<std::string> where; - where.push_back(FormatLevel(queryLevel) + ".resourceType = " + - formatter.FormatResourceType(queryLevel) + comparisons); - - if (!labels.empty()) - { - /** - * "In SQL Server, NOT EXISTS and NOT IN predicates are the best - * way to search for missing values, as long as both columns in - * question are NOT NULL." - * https://explainextended.com/2009/09/15/not-in-vs-not-exists-vs-left-join-is-null-sql-server/ - **/ - - std::list<std::string> formattedLabels; - for (std::set<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++it) - { - formattedLabels.push_back(formatter.GenerateParameter(*it)); - } - - std::string condition; - switch (labelsConstraint) - { - case LabelsConstraint_Any: - condition = "> 0"; - break; - - case LabelsConstraint_All: - condition = "= " + boost::lexical_cast<std::string>(labels.size()); - break; - - case LabelsConstraint_None: - condition = "= 0"; - break; - - default: - throw OrthancException(ErrorCode_ParameterOutOfRange); - } - - where.push_back("(SELECT COUNT(1) FROM Labels AS selectedLabels WHERE selectedLabels.id = " + FormatLevel(queryLevel) + - ".internalId AND selectedLabels.label IN (" + Join(formattedLabels, "", ", ") + ")) " + condition); - } - - sql += joins + Join(where, " WHERE ", " AND "); - - if (limit != 0) - { - sql += " LIMIT " + boost::lexical_cast<std::string>(limit); - } - } - - - void ISqlLookupFormatter::Apply(std::string& sql, - ISqlLookupFormatter& formatter, const FindRequest& request) { const bool escapeBrackets = formatter.IsEscapeBrackets();
--- a/OrthancServer/Sources/Search/ISqlLookupFormatter.h Wed Jan 14 18:24:29 2026 +0100 +++ b/OrthancServer/Sources/Search/ISqlLookupFormatter.h Wed Jan 14 19:06:30 2026 +0100 @@ -68,14 +68,6 @@ const ResourceType& queryLevel, const DatabaseDicomTagConstraints& lookup); - static void Apply(std::string& sql, - ISqlLookupFormatter& formatter, - const DatabaseDicomTagConstraints& lookup, - ResourceType queryLevel, - const std::set<std::string>& labels, // New in Orthanc 1.12.0 - LabelsConstraint labelsConstraint, // New in Orthanc 1.12.0 - size_t limit); - static void ApplySingleLevel(std::string& sql, ISqlLookupFormatter& formatter, const DatabaseDicomTagConstraints& lookup,
--- a/OrthancServer/UnitTestsSources/ServerIndexTests.cpp Wed Jan 14 18:24:29 2026 +0100 +++ b/OrthancServer/UnitTestsSources/ServerIndexTests.cpp Wed Jan 14 19:06:30 2026 +0100 @@ -164,15 +164,24 @@ const std::string& value) { assert(ServerToolbox::IsIdentifier(tag, level)); - - DicomTagConstraint c(tag, type, value, true, true); - - DatabaseDicomTagConstraints lookup; - bool isEquivalent; // unused - lookup.AddConstraint(c.ConvertToDatabaseConstraint(isEquivalent, level, DicomTagType_Identifier)); + result.clear(); + + std::vector<std::string> values; + values.push_back(value); + + std::unique_ptr<DatabaseDicomTagConstraint> lookup(new DatabaseDicomTagConstraint(level, tag, true, type, values, true, true)); - std::set<std::string> noLabel; - transaction_->ApplyLookupResources(result, NULL, lookup, level, noLabel, LabelsConstraint_All, 0 /* no limit */); + FindRequest request(level); + request.GetDicomTagConstraints().AddConstraint(lookup.release()); + + FindResponse response; + + transaction_->ExecuteFind(response, request, index_->GetDatabaseCapabilities()); + + for (size_t i = 0; i < response.GetSize(); ++i) + { + result.push_back(response.GetResourceByIndex(i).GetIdentifier()); + } } void DoLookupIdentifier2(std::list<std::string>& result, @@ -184,17 +193,29 @@ const std::string& value2) { assert(ServerToolbox::IsIdentifier(tag, level)); + result.clear(); + + std::vector<std::string> values1, values2; - DicomTagConstraint c1(tag, type1, value1, true, true); - DicomTagConstraint c2(tag, type2, value2, true, true); + values1.push_back(value1); + std::unique_ptr<DatabaseDicomTagConstraint> lookup1(new DatabaseDicomTagConstraint(level, tag, true, type1, values1, true, true)); + + values2.push_back(value2); + std::unique_ptr<DatabaseDicomTagConstraint> lookup2(new DatabaseDicomTagConstraint(level, tag, true, type2, values2, true, true)); - DatabaseDicomTagConstraints lookup; - bool isEquivalent; // unused - lookup.AddConstraint(c1.ConvertToDatabaseConstraint(isEquivalent, level, DicomTagType_Identifier)); - lookup.AddConstraint(c2.ConvertToDatabaseConstraint(isEquivalent, level, DicomTagType_Identifier)); - - std::set<std::string> noLabel; - transaction_->ApplyLookupResources(result, NULL, lookup, level, noLabel, LabelsConstraint_All, 0 /* no limit */); + FindRequest request(level); + request.GetDicomTagConstraints().AddConstraint(lookup1.release()); + request.GetDicomTagConstraints().AddConstraint(lookup2.release()); + + FindResponse response; + + transaction_->ExecuteFind(response, request, index_->GetDatabaseCapabilities()); + + for (size_t i = 0; i < response.GetSize(); ++i) + { + result.push_back(response.GetResourceByIndex(i).GetIdentifier()); + } + } };
