-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/27/2010 11:41 AM, Scott A Mintz wrote:
> 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?
Use the last_insert_rowid() SQL level function and wrap in a transaction
(prevents other threads from making changes). I do it like this (Python
code, adapt as needed):
rowid=cursor.execute("""
BEGIN ;
INSERT INTO table ... ;
SELECT last_insert_rowid();
END""").fetchall()[0][0]
Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk0ZSkcACgkQmOOfHg372QQ0dQCg0F6r7uz46OeT6HlfbEKVj7Mt
aNAAnRGhOcrgJrLOiN1VFsCZhE+YXiP+
=1Jlk
-----END PGP SIGNATURE-----
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users