vendredi 31 juillet 2015

sqlite DB is shows SQLITE_BUSY after the getting sqlite3_last_insert_rowid() objective c

I am trying to insert a member in sqlite DB member table. After inserting values if I take sqlite3_last_insert_rowid() I can't insert another member. the statement shows SQLITE_BUSY.Here is my code. Please anybody help.

-(NSInteger) saveMember:(TMMember *)member {
const char *dbPath = [databasePath UTF8String];
if (sqlite3_open(dbPath, &database) == SQLITE_OK)
{
    NSString *insertSQL = [NSString stringWithFormat:@"insert into members (memberName, memberAmount,shareFlag) values(\"%@\", \"%f\",%d)",member.memberName,member.amount,[[NSNumber numberWithBool:member.shareFlag]intValue]];
    const char *insert_stmt = [insertSQL UTF8String];
    sqlite3_prepare_v2(database, insert_stmt,-1, &statement, NULL);
    if(sqlite3_step(statement) == SQLITE_DONE)
    {
        NSInteger lastRowId = sqlite3_last_insert_rowid(database);
        member.memberId = lastRowId;
        NSLog(@"inserted member id = %ld",lastRowId);
        NSLog(@"member is added");
    }
    sqlite3_finalize(statement);
    statement = nil;
}
sqlite3_reset(statement);
sqlite3_close(database);
return 0;

}

Aucun commentaire:

Enregistrer un commentaire