Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SystemDataModel opened this issue Feb 12, 2024 · 2 comments
Closed

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

SystemDataModel opened this issue Feb 12, 2024 · 2 comments
Assignees

Comments

@SystemDataModel
Copy link

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::SharedPtrPoco::Data::Session(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:

  • OS Type and Version : Oracle Linux 9.3
  • POCO Version : Last version from git repo
  • Third-party product (eg. database or library) type and version: PosrtgreSQL 16

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

@obiltschnig
Copy link
Member

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

@obiltschnig obiltschnig self-assigned this Feb 13, 2024
@obiltschnig obiltschnig added this to the Release 1.13.2 milestone Feb 13, 2024
@SystemDataModel
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants