Ok - yes that works. Actually my problem was that I was using one of the GUI client interfaces to SQL lite, and it doesn't display returned results from SELECT statements when using transactions. I had actually tried the transaction approach but thought nothing was getting returned. Doh... Doing the UPDATE + SELECT in C++ gives me back the next id properly :)
Thanks for the help. -Dave -----Original Message----- From: Steve O'Hara [mailto:[EMAIL PROTECTED] Sent: Monday, February 21, 2005 3:07 AM To: sqlite-users@sqlite.org Subject: RE: [sqlite] Making a SEQUENCE? Hi Dave, Wrap your update and select inside a transaction - the transaction is atomic in this regard and locks the table after the update and doesn't let it go until the commit/rollback. Others can read (they get the uncommitted values of course) but can't update. You will always get the latest uncommitted values from selects within the transaction. Steve -----Original Message----- From: Ulrik Petersen [mailto:[EMAIL PROTECTED] Sent: 21 February 2005 10:21 To: sqlite-users@sqlite.org Subject: Re: [sqlite] Making a SEQUENCE? Hi Dave, Brown, Dave wrote: >I read that faq, but I dont see how that solves this yet. I understand >how the insert will autoincrement, but I need to do "increment + return >new value" in one atomic operation. If I just issue an insert, then try >to use the new value from that table, I'm not guaranteed that someone >else hasn't also incremented it further before I got to it. > >Do you see what I mean? > > Yes. If you are using SQLite 2.8.X, then use: int sqlite_last_insert_rowid(sqlite*); http://www.sqlite.org/c_interface.html Section 3.0 If you are using SQLite 3, then there is an analogous function: http://www.sqlite.org/capi3ref.html#sqlite3_last_insert_rowid /Ulrik -- Ulrik Petersen, MA, B.Sc. University of Aalborg, Denmark Homepage: http://ulrikp.org