If you can guarantee that your ID
column is an auto-increment column, MAX(ID)
is fine.
But to cover any case, there's a specialized SQLite function called LAST_INSERT_ROWID()
:
SELECT LAST_INSERT_ROWID();
In FMDB, you use the -lastInsertRowId
method (which internally runs the above):
int lastId = [fmdb lastInsertRowId];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…