Overview
Features
Download
Documentation
Community
Add-Ons & Services

Last inserted row id (SQLite)

Please post support and help requests here.

Last inserted row id (SQLite)

Postby TheRawGod » 19 Jun 2008, 15:14

Hi guys!

I'm currently using SQLite through Poco::Data and am not sure how to _properly_ get the last inserted row id (autogenerated INTEGER PRIMARY KEY column value of the last inserted row).

SQLite C interface has a func for that but I couldnt' find anything in Poco as well as I couldn't find any suggestions in the forums or manuals.

I would appreciate any help or links.

PS I know that in most cases SELECT MAX(col_name) would do the job (just a little synchronization overhead would be required + this extra SELECT) but still that's not the _proper_ way I think. And that won't work in true 100% of cases :)
TheRawGod
 
Posts: 6
Joined: 06 Dec 2006, 13:33
Location: Ukraine

Re: Last inserted row id (SQLite)

Postby alex » 19 Jun 2008, 17:54

SF tracker, item 1865864:

Code: Select all

int lastInsertID(Session& session)
{
    int id;
    session << "SELECT last_insert_rowid()", into(id), now;
    return id;
}
alex
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Re: Last inserted row id (SQLite)

Postby TheRawGod » 19 Jun 2008, 18:02

alex,

thanks a lot. That couldn't be easier :)

PS Haven't looked in SF (:confused:), sorry.
TheRawGod
 
Posts: 6
Joined: 06 Dec 2006, 13:33
Location: Ukraine


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron