SQLite删除表导致数据库被锁定错误

时间:2014-06-23 05:31:04

标签: ios iphone sqlite ipad

我创建了一个小型数据库升级工具,用于根据PRAGMA user_version更新我们的sqlite数据库表。它一直运作良好,直到最近我需要完全放弃一张桌子。

显然drop table命令是

DROP TABLE tbl;

使用以下命令执行sql指令:

NSString *currentUpdateStatement = [upgradeStatements objectAtIndex:statementNumber];
DLog(@"Update statement is: %@", currentUpdateStatement);
const char *sql_stmt = [currentUpdateStatement UTF8String];
char *errMsg;
//Start executing the upgrade command
if (sqlite3_exec(self.database, sql_stmt, NULL, NULL, &errMsg) == SQLITE_OK)
{
    DLog(@"Upgrade statement %i successful", statementNumber);
} else {
    NSString *errorMessage = [NSString stringWithUTF8String:errMsg];
    ELog(@"Upgrading failed at statement %i in version %i. Message: %@",
    statementNumber, newVersionNumber, errorMessage);
    [NSException raise:@"Database upgrade failed"
    format:@"Database could not be upgraded to version %i. "
    "Failed at command %i due to error '%@'",newVersionNumber, statementNumber, errorMessage];
 }

每当我尝试运行drop table命令时,执行失败,并且'database is locked'结果为SQLITE_LOCKED。

所有其他命令都完全正常。我试着一遍又一遍地阅读SQL文档而没有运气。 你们觉得怎么样?

1 个答案:

答案 0 :(得分:2)

在先行事务之后丢失sqlite3_finalize(语句)会导致此错误。