Scott A Mintz <sami...@ra.rockwell.com> wrote:
> If I have a table with an INTEGER PRIMARY KEY column, and I INSERT a new
> row into the table with a NULL binding to that column, sqlite will
> generate a unique value for me.
> 
> I know that I can use sqlite3_last_insert_rowid() to retrieve the value.
> However, in a multi-threaded environment, it's possible for another thread
> to do an INSERT before I get the first result.  What's the best way to
> retrieve the rowid?

Basically, the same way you employ to make this work:

someGlobalVar = someGlobalVar + 1;

It's the responsibility of your application to protect operations that need to 
be atomic against concurrent access. I imagine your operating system provides a 
number of synchronization mechansisms in connection with its multithreading 
facilities.

The above asumes that all threads share the same database connection. If each 
thread is using its own separate connection, the problem fails to arise: last 
inserted rowid is maintained on a per-connection basis.
-- 
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to