Mercurial > hg > orthanc-databases
changeset 304:dd4b0edd1661
GenericFormatter::GetDialect()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Jul 2021 17:23:24 +0200 |
parents | 495b6f325e35 |
children | 87f0e29a1dc1 |
files | Framework/Common/GenericFormatter.cpp Framework/Common/GenericFormatter.h Framework/Plugins/IndexBackend.cpp |
diffstat | 3 files changed, 70 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Common/GenericFormatter.cpp Fri Jul 09 16:46:50 2021 +0200 +++ b/Framework/Common/GenericFormatter.cpp Fri Jul 09 17:23:24 2021 +0200 @@ -27,6 +27,21 @@ namespace OrthancDatabases { + Dialect GenericFormatter::GetDialect() const + { + if (autoincrementDialect_ != namedDialect_) + { + // The two dialects do not match because of a previous call to + // SetAutoincrementDialect() or SetNamedDialect() + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + return namedDialect_; + } + } + + void GenericFormatter::Format(std::string& target, const std::string& source, ValueType type)
--- a/Framework/Common/GenericFormatter.h Fri Jul 09 16:46:50 2021 +0200 +++ b/Framework/Common/GenericFormatter.h Fri Jul 09 17:23:24 2021 +0200 @@ -44,11 +44,23 @@ { } + Dialect GetDialect() const; + + Dialect GetAutoincrementDialect() const + { + return autoincrementDialect_; + } + void SetAutoincrementDialect(Dialect dialect) { autoincrementDialect_ = dialect; } + Dialect GetNamedDialect() const + { + return namedDialect_; + } + void SetNamedDialect(Dialect dialect) { namedDialect_ = dialect;
--- a/Framework/Plugins/IndexBackend.cpp Fri Jul 09 16:46:50 2021 +0200 +++ b/Framework/Plugins/IndexBackend.cpp Fri Jul 09 17:23:24 2021 +0200 @@ -433,8 +433,6 @@ DatabaseManager& manager, int64_t id) { - assert(manager.GetDialect() != Dialect_MySQL); - ClearDeletedFiles(manager); ClearDeletedResources(manager); @@ -552,19 +550,32 @@ int64_t since, uint32_t maxResults) { - DatabaseManager::CachedStatement statement( - STATEMENT_FROM_HERE, manager, - "SELECT * FROM Changes WHERE seq>${since} ORDER BY seq LIMIT ${limit}"); - - statement.SetReadOnly(true); - statement.SetParameterType("limit", ValueType_Integer64); - statement.SetParameterType("since", ValueType_Integer64); + std::unique_ptr<DatabaseManager::CachedStatement> statement; + + if (manager.GetDialect() == Dialect_MSSQL) + { + statement.reset( + new DatabaseManager::CachedStatement( + STATEMENT_FROM_HERE, manager, + "SELECT TOP(${limit}) * FROM Changes WHERE seq>${since} ORDER BY seq")); + } + else + { + statement.reset( + new DatabaseManager::CachedStatement( + STATEMENT_FROM_HERE, manager, + "SELECT * FROM Changes WHERE seq>${since} ORDER BY seq LIMIT ${limit}")); + } + + statement->SetReadOnly(true); + statement->SetParameterType("limit", ValueType_Integer64); + statement->SetParameterType("since", ValueType_Integer64); Dictionary args; args.SetIntegerValue("limit", maxResults + 1); args.SetIntegerValue("since", since); - ReadChangesInternal(output, done, manager, statement, args, maxResults); + ReadChangesInternal(output, done, manager, *statement, args, maxResults); } @@ -613,19 +624,32 @@ int64_t since, uint32_t maxResults) { - DatabaseManager::CachedStatement statement( - STATEMENT_FROM_HERE, manager, - "SELECT * FROM ExportedResources WHERE seq>${since} ORDER BY seq LIMIT ${limit}"); - - statement.SetReadOnly(true); - statement.SetParameterType("limit", ValueType_Integer64); - statement.SetParameterType("since", ValueType_Integer64); + std::unique_ptr<DatabaseManager::CachedStatement> statement; + + if (manager.GetDialect() == Dialect_MSSQL) + { + statement.reset( + new DatabaseManager::CachedStatement( + STATEMENT_FROM_HERE, manager, + "SELECT TOP(${limit}) * FROM ExportedResources WHERE seq>${since} ORDER BY seq")); + } + else + { + statement.reset( + new DatabaseManager::CachedStatement( + STATEMENT_FROM_HERE, manager, + "SELECT * FROM ExportedResources WHERE seq>${since} ORDER BY seq LIMIT ${limit}")); + } + + statement->SetReadOnly(true); + statement->SetParameterType("limit", ValueType_Integer64); + statement->SetParameterType("since", ValueType_Integer64); Dictionary args; args.SetIntegerValue("limit", maxResults + 1); args.SetIntegerValue("since", since); - ReadExportedResourcesInternal(output, done, statement, args, maxResults); + ReadExportedResourcesInternal(output, done, *statement, args, maxResults); } @@ -1838,6 +1862,7 @@ "SELECT CAST(COUNT(*) AS BIGINT) FROM PatientRecyclingOrder")); break; + case Dialect_MSSQL: case Dialect_SQLite: statement.reset(new DatabaseManager::CachedStatement( STATEMENT_FROM_HERE, manager,