1

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);

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

How would another process on an iPhone lock the table?
You're right. I had SQLite Database Browser open on the actual database. Thanks. Data is now deleting.
@DarkDust I didn mean iphone. I meant any process. you may be accessing database via sqlite manager.
I once did the same thing.. took me three days to figure it out... :X

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.