On Thu, 27 Oct 2011 21:47:17 +0100, Simon Slavin <slav...@bigfraud.org> wrote:
> >On 27 Oct 2011, at 8:12pm, Tim Streater wrote: > >> Is there a way to get a unique id from a database >> without actually creating a new row? > > Sure. Do something like > > SELECT max(id) FROM mytab; > > Then in your own code, add 1 to it and use that as > the "id" for the row you're about to save. > Make sure you handle the NULL case (where mytab > doesn't have any rows in it yet) correctly. And wrap it all in an IMMEDIATE or EXCLUSIVE transaction, or you'll get a race condition if some other process tries to do the same at the same time. All processes have to behave, if there's one that does the SELECT above in uncommitted mode and proceeds to use it, you have a problem. So, better use AUTOINCREMENT. -- ( Kees Nuyt ) c[_] _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users