Mercurial > hg > orthanc-databases
changeset 302:3a52e27a2d80
in GenericFormatter, replaced ${} by ${AUTOINCREMENT}
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Jul 2021 16:25:08 +0200 |
parents | 2447c290fc73 |
children | 495b6f325e35 |
files | Framework/Common/GenericFormatter.cpp Framework/Common/GenericFormatter.h Framework/Plugins/IndexBackend.cpp MySQL/Plugins/MySQLIndex.cpp PostgreSQL/Plugins/PostgreSQLIndex.cpp |
diffstat | 5 files changed, 22 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Common/GenericFormatter.cpp Thu Jul 08 18:28:47 2021 +0200 +++ b/Framework/Common/GenericFormatter.cpp Fri Jul 09 16:25:08 2021 +0200 @@ -33,16 +33,29 @@ { if (source.empty()) { - // This is the default parameter for INSERT + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + else if (source == "AUTOINCREMENT") + { + if (GetParametersCount() != 0) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, + "The AUTOINCREMENT argument must always be the first"); + } + switch (dialect_) { case Dialect_PostgreSQL: - target = "DEFAULT"; + target = "DEFAULT, "; break; case Dialect_MySQL: case Dialect_SQLite: - target = "NULL"; + target = "NULL, "; + break; + + case Dialect_MSSQL: + target.clear(); // The IDENTITY field must not be filled in MSSQL break; default: @@ -51,14 +64,6 @@ } else { - if (allNames_.find(source) != allNames_.end()) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls, - "Parameter ${" + source + "} registered twice"); - } - - allNames_.insert(source); - switch (dialect_) { case Dialect_PostgreSQL:
--- a/Framework/Common/GenericFormatter.h Thu Jul 08 18:28:47 2021 +0200 +++ b/Framework/Common/GenericFormatter.h Fri Jul 09 16:25:08 2021 +0200 @@ -35,7 +35,6 @@ Dialect dialect_; std::vector<std::string> parametersName_; std::vector<ValueType> parametersType_; - std::set<std::string> allNames_; public: explicit GenericFormatter(Dialect dialect) :
--- a/Framework/Plugins/IndexBackend.cpp Thu Jul 08 18:28:47 2021 +0200 +++ b/Framework/Plugins/IndexBackend.cpp Fri Jul 09 16:25:08 2021 +0200 @@ -942,7 +942,7 @@ { DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager, - "INSERT INTO Changes VALUES(${}, ${changeType}, ${id}, ${resourceType}, ${date})"); + "INSERT INTO Changes VALUES(${AUTOINCREMENT} ${changeType}, ${id}, ${resourceType}, ${date})"); statement.SetParameterType("changeType", ValueType_Integer64); statement.SetParameterType("id", ValueType_Integer64); @@ -964,7 +964,7 @@ { DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager, - "INSERT INTO ExportedResources VALUES(${}, ${type}, ${publicId}, " + "INSERT INTO ExportedResources VALUES(${AUTOINCREMENT} ${type}, ${publicId}, " "${modality}, ${patient}, ${study}, ${series}, ${instance}, ${date})"); statement.SetParameterType("type", ValueType_Integer64); @@ -1696,7 +1696,7 @@ { DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager, - "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})"); + "INSERT INTO PatientRecyclingOrder VALUES(${AUTOINCREMENT} ${id})"); statement.SetParameterType("id", ValueType_Integer64); @@ -2275,7 +2275,7 @@ { DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager, - "INSERT INTO PatientRecyclingOrder VALUES(${}, ${id})"); + "INSERT INTO PatientRecyclingOrder VALUES({AUTOINCREMENT} ${id})"); statement.SetParameterType("id", ValueType_Integer64);
--- a/MySQL/Plugins/MySQLIndex.cpp Thu Jul 08 18:28:47 2021 +0200 +++ b/MySQL/Plugins/MySQLIndex.cpp Fri Jul 09 16:25:08 2021 +0200 @@ -324,7 +324,7 @@ { DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager, - "INSERT INTO Resources VALUES(${}, ${type}, ${id}, NULL)"); + "INSERT INTO Resources VALUES(NULL, ${type}, ${id}, NULL)"); statement.SetParameterType("id", ValueType_Utf8String); statement.SetParameterType("type", ValueType_Integer64);
--- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp Thu Jul 08 18:28:47 2021 +0200 +++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp Fri Jul 09 16:25:08 2021 +0200 @@ -306,7 +306,7 @@ { DatabaseManager::CachedStatement statement( STATEMENT_FROM_HERE, manager, - "INSERT INTO Resources VALUES(${}, ${type}, ${id}, NULL) RETURNING internalId"); + "INSERT INTO Resources VALUES(DEFAULT, ${type}, ${id}, NULL) RETURNING internalId"); statement.SetParameterType("id", ValueType_Utf8String); statement.SetParameterType("type", ValueType_Integer64);