> i just (experimentally) > implemented a lookup on sqlite_sequence if the hint is provided, else > falling back to sqlite3_last_insert_id(). It "works for me", but if it's a > potential portability problem then i'll remove it.
If you read the link Simon gave you'll see that sqlite_sequence have records only for tables with AUTOINCREMENT ROWID. And that record doesn't necessarily contains value from some row that really existed at any point of time. In other words with this implementation your function may return incorrect value. Pavel On Sun, Apr 8, 2012 at 9:44 PM, Stephan Beal <[email protected]> wrote: > On Mon, Apr 9, 2012 at 3:25 AM, Simon Slavin <[email protected]> wrote: > >> The C function sqlite3_last_insert_id(), and the SQLite wrapper around it >> last_insert_rowid() are as good as it gets. You do have to be a little >> careful if you have a TRIGGER on an INSERT which does another INSERT. If >> you use TRIGGERs I suggest you test out the behaviour for yourself to >> figure out what it does. >> > > Thanks for that, Simon. A bit of background might help understand why i > ask: i have a db access abstraction API in C, and of course have an sqlite3 > driver/wrapper. The last-insert-id op in the API supports (but does not > require) that a table/sequence name argument be passed to it (my research > into several C db APIs showed that some drivers want/need this). Currently > the sqlite3 wrapper ignores that argument. i just (experimentally) > implemented a lookup on sqlite_sequence if the hint is provided, else > falling back to sqlite3_last_insert_id(). It "works for me", but if it's a > potential portability problem then i'll remove it. > > @Pavel: the id/trigger "problem" is not something i've seen personally - it > was reported by someone on this list some time last year, and i've just > always had it in the back of my mind (in the context of my db wrapper API). > i appreciate the link to the docs - that certainly clarifies it for me (as > a non-problem). > > -- > ----- stephan beal > http://wanderinghorse.net/home/stephan/ > http://gplus.to/sgbeal > _______________________________________________ > sqlite-users mailing list > [email protected] > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

