简体   繁体   中英

Python's equivalent of Java's statement.getGeneratedKeys()?

Is there an API in Python's sqlite3 module similar to Java's statement.getGeneratedKeys()? If not, what is the best way to get recently autogenerated keys in Python with sqlite3?

You need to use the SQLite function last_insert_rowid() . From the SQLite documentation :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM