Search code examples
iossqlitefmdb

How can I get lastRowId correctly with FMDB?


How can I get lastRowId with FMDB? Method [db lastRowId] always returns 0 for me.


Solution

  • Finally I've found, that lastRowId can be retrieved while connection is opened

    [_database open];
    [_database executeUpdate:<some query>];
    
    int64_t lastInsertRowId = [_database lastInsertRowId];
    [_database close];
    
    return lastInsertRowId;