Is there an sqlite equivalent to INSERT...;SELECT @@IDENTITY? If so, please show me the code or point me towards it.
Thanks!
Is there an sqlite equivalent to INSERT...;SELECT @@IDENTITY? If so, please show me the code or point me towards it.
Thanks!
>>> import sqlite3
>>> conn = sqlite3.connect(":memory:")
>>> c = conn.cursor()
>>> c.execute("create table t (id integer, some text);")
<sqlite3.Cursor object at 0x00C64CE0>
>>> c.execute("insert into t values(1,'a');")
<sqlite3.Cursor object at 0x00C64CE0>
>>> c.lastrowid
1
SELECT last_insert_rowid() -- same as select @@identity
last_insert_rowid() The last_insert_rowid() function returns the ROWID of the last row insert from the database connection which invoked the function. The last_insert_rowid() SQL function is a wrapper around the sqlite3_last_insert_rowid() C/C++ interface function.