"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? Or do I have to take care that
no other thread is even attempting to execute some SQL?


>> I can't believe that I really have to do a SELECT on the data that I
>> just INSERTed only to get the rowid...
>
> I'm not sure how this helps, if another thread can insert more data 
> between your INSERT and SELECT. Wouldn't that suffer from the same 
> problem?

Not in my case, because I can uniquely select the data that I have just
inserted. 


Best,

   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

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

Reply via email to