fix(ActiveRecord): Error between Poco::ActiveRecord and Poco::Data::PostgreSQL #4450

This commit is contained in:
Günter Obiltschnig 2024-04-03 07:01:34 +02:00
parent 0818febed3
commit e428c4b46c
2 changed files with 9 additions and 5 deletions

View File

@ -240,23 +240,24 @@ template <typename IDType>
IDType ActiveRecord<IDType>::lastInsertID(Poco::Data::Session& session) IDType ActiveRecord<IDType>::lastInsertID(Poco::Data::Session& session)
{ {
using namespace Poco::Data::Keywords; using namespace Poco::Data::Keywords;
using namespace std::string_literals;
IDType id; IDType id;
if (session.connector() == "sqlite") if (Poco::icompare(session.connector(), "sqlite"s) == 0)
{ {
session session
<< "SELECT last_insert_rowid()", << "SELECT last_insert_rowid()",
into(id), into(id),
now; now;
} }
else if (session.connector() == "PostgreSQL") else if (Poco::icompare(session.connector(), "postgresql"s) == 0)
{ {
session session
<< "SELECT currval('id_seq')", << "SELECT lastval()",
into(id), into(id),
now; now;
} }
else if (session.connector() == "MySQL") else if (Poco::icompare(session.connector(), "mysql"s) == 0)
{ {
session session
<< "SELECT LAST_INSERT_ID()", << "SELECT LAST_INSERT_ID()",

View File

@ -15,6 +15,9 @@
#include "Poco/ActiveRecord/Context.h" #include "Poco/ActiveRecord/Context.h"
using namespace std::string_literals;
namespace Poco { namespace Poco {
namespace ActiveRecord { namespace ActiveRecord {
@ -33,7 +36,7 @@ Context::Context(const std::string& connector, const std::string& connectionStri
StatementPlaceholderProvider::Ptr Context::statementPlaceholderProvider() const StatementPlaceholderProvider::Ptr Context::statementPlaceholderProvider() const
{ {
if (_session.connector() == "postgresql") if (Poco::icompare(_session.connector(), "postgresql"s) == 0)
return std::make_unique<PostgresStatementPlaceholderProvider>(); return std::make_unique<PostgresStatementPlaceholderProvider>();
else else
return std::make_unique<DefaultStatementPlaceholderProvider>(); return std::make_unique<DefaultStatementPlaceholderProvider>();