Python / sqlite - select records after insertion

Is there an sqlite equivalent for INSERT ...; SELECT @@ IDENTITY? If yes, please show me the code or show me it.

Thanks!

+6
sqlite sqlite3
source share
2 answers

Cursor.lastrowid

 >>> 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 
+10
source share
 SELECT last_insert_rowid() -- same as select @@identity 

last_insert_rowid () The last_insert_rowid () function returns the ROWID of the last row inserted from the database connection that calls this function. The last_insert_rowid () SQL function is a wrapper around the C / C ++ sqlite3_last_insert_rowid () interface function.

+6
source share

All Articles