sqlsqlitepoco-libraries

How do I get the last inserted id in a generic way with Poco?


I have scoured the documentation for Poco but could not find a way to retrieve the last inserted id for an INSERT INTO Table operation.

The Statement::execute documentation says that it returns the number of records affected (which could be greater than one for a bulk insert).

If it makes any difference I'm currently using SQLite but would like a generic solution that works across different database engines.


Solution

  • For SQLite, execute a statement, SELECT last_insert_rowid()

    I know that isn't a generic answer.

    But, this is how they do it in Ti.Database module - which is a module for Titanium that uses poco. They select last_insert_rowid() and then set that as a property of the statement.