简体   繁体   中英

Objective-C Issue with deleting data from SQLITE database - result code 5

I am experiencing issues with deleting a row / data record from an SQLite database located on the iPhone. I followed advice given in the following post , but the result code from SQLite is 5. From the SQLite reference manual, 5 means:

SQLITE_BUSY 5 /* The database file is locked */

Has anyone else come across this problem or have any ideas why this would be the case?

Here is an excerpt of my code (dbrc is set to 5):

    NSString *retrievedContactID = [archivedContact objectForKey:@"contact_id"];

    sqlite3 *database = [FollowUPAppDelegate checkAndCreateDatabase];
    NSString *deleteSQL = [NSString stringWithFormat:@"DELETE FROM Contacts WHERE contact_id = %@", retrievedContactID];

    const char *delete_stmt = [deleteSQL UTF8String];
    sqlite3_stmt *compiledStatement;
    int dbrc; //database return code

    dbrc = sqlite3_prepare_v2(database, delete_stmt, -1, &compiledStatement, NULL);
    dbrc = sqlite3_step(compiledStatement);
    sqlite3_finalize(compiledStatement);
    compiledStatement = NULL;


    if (dbrc != 101) {  //anything except 101 (SQLITE_DONE for delete, *not* SQLITE_OK)
        NSLog(@"Error deleting contact from database: result code %i", dbrc);
        return;
    }
    else {
        NSLog(@"deleted the customer from datasets");
    }

    sqlite3_close(database);

This means. your database is being used by some other process. you have to stop the other process and proceed. I can give you an example. when you are accessing a database from your app and if you try to change the content using some external sqlite manager you would get this busy error. The solution to this problem is,stop your app and try.

You problem is similar. Your database is locked by some other process.

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