Nikolaus Rath wrote:
> "Igor Tandetnik" <itandet...@mvps.org> writes:
>> Nikolaus Rath <nikol...@rath.org> wrote:
>>> How can I determine the rowid of the last insert if I am accessing
>>> the db from different threads? If I understand correctly,
>>> last_insert_rowid() won't work reliably in this case.
>>
>> Last inserted rowid is maintained per connection. Do your threads use
>> the same connection, or each create their own?
>
> Same connection, just different cursors.
>
>> If all threads share the same connection, it is your responsibility
>> to make "insert then retrieve last rowid" an atomic operation, using
>> thread synchronization mechanism of your choice. Just as with any
>> access to shared data.
>
> Is BEGIN ... COMMIT sufficient for that?

No. Transaction is also maintained per connection. Starting a 
transaction would prevent other connections from making concurrent 
changes, but wouldn't block other threads using the same connection.

> Or do I have to take care
> that no other thread is even attempting to execute some SQL?

It's OK to execute SQL - just not another INSERT.

Igor Tandetnik 



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

Reply via email to