pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.33k stars 2.15k forks source link

Error between Poco::ActiveRecord and Poco::Data::PostgreSQL #4450

Closed SystemDataModel closed 6 months ago

SystemDataModel commented 7 months ago

Describe the bug I use Poco ActiveRecord with PostgreSQL 16.

I use ActiveRecord::lastInsertID(Poco::Data::Session& session) where Data::Session is a PostgreSQL Session.

In Data::Session, session.connector() returns "postgresql"

This method is used in ActiveRecord::lastInsertID and test with "if (session.connector() == "PostgreSQL")". This condition is not satisfied.

To Reproduce

m_pSession = Poco::SharedPtr(new Session(PostgreSQL::Connector::KEY, dbConnString)); Context::Ptr pContext = new Context(*m_pSession);

Use this context with ActiveRecord

Expected behavior

Change test "if (session.connector() == "PostgreSQL")" by "if (session.connector() == "postgresql")" in ActiveRecord::lastInsertID

Logs No Logs

Screenshots No screenshots

Please add relevant environment information:

Additional context I use Postgres tables with INHERITANCE relationship between tables. I use "bigserial" id as primary key in tables

obiltschnig commented 7 months ago

The comparison should be case insensitive, as connector names are case insensitive as well (see SessionFactory). The canonical name is "postgresql".

SystemDataModel commented 7 months ago

Another improvement

In Postgres, the name of the sequence is autogenerated and is always tablename_columnname_seq.

So, the code below generates an exception: session << "SELECT currval('id_seq')", into(id), now;

Everything works for me with the following fixes: else if (session.connector() == "postgresql") { session << "SELECT lastval()", into(id), now; }

Sincerely yours