How do I get the auto-incrementing value of the last inserted record in SQLite?
Using sqlite3, I inserted a new row into table Foo.
INSERT INTO Foo VALUES (colX=?, colY=? colZ=?)
Then I bind and execute the query. This table contains an auto-incrementing column as the primary key. How do I get at this ID after a new row was added with开发者_StackOverflow社区out doing a query?
Use sqlite3_last_insert_rowid:
sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
This gets the last inserted id, just like you asked.
http://www.sqlite.org/c3ref/last_insert_rowid.html
精彩评论