# HG changeset patch # User Sebastien Jodogne # Date 1625840708 -7200 # Node ID 3a52e27a2d80c26c75d95b7922446837dea0bc77 # Parent 2447c290fc73b674850861bc98eee6be19f40109 in GenericFormatter, replaced ${} by ${AUTOINCREMENT} diff -r 2447c290fc73 -r 3a52e27a2d80 Framework/Common/GenericFormatter.cpp --- 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: diff -r 2447c290fc73 -r 3a52e27a2d80 Framework/Common/GenericFormatter.h --- 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 parametersName_; std::vector parametersType_; - std::set allNames_; public: explicit GenericFormatter(Dialect dialect) : diff -r 2447c290fc73 -r 3a52e27a2d80 Framework/Plugins/IndexBackend.cpp --- 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); diff -r 2447c290fc73 -r 3a52e27a2d80 MySQL/Plugins/MySQLIndex.cpp --- 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); diff -r 2447c290fc73 -r 3a52e27a2d80 PostgreSQL/Plugins/PostgreSQLIndex.cpp --- 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);