简体   繁体   English

从SQLITE数据库删除数据的Objective-C问题-结果代码5

[英]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. 我从iPhone上的SQLite数据库删除行/数据记录时遇到问题。 I followed advice given in the following post , but the result code from SQLite is 5. From the SQLite reference manual, 5 means: 我遵循了以下文章中给出的建议,但是SQLite的结果代码为5。从SQLite参考手册中,5表示:

SQLITE_BUSY 5 /* The database file is locked */ SQLITE_BUSY 5 / *数据库文件已锁定* /

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): 这是我的代码的摘录(dbrc设置为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. 当您从应用程序访问数据库时,如果尝试使用某些外部sqlite管理器更改内容,则会收到此繁忙错误。 The solution to this problem is,stop your app and try. 解决此问题的方法是,停止您的应用并尝试。

You problem is similar. 您的问题是相似的。 Your database is locked by some other process. 您的数据库已被其他进程锁定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM