gpt4 book ai didi

ios - SQLite Drop Table导致Database is Locked错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:38 26 4
gpt4 key购买 nike

我创建了一个小的数据库升级工具来根据 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];
}

每次我尝试运行删除表命令时,执行都会失败并显示“数据库已锁定”,结果为 SQLITE_LOCKED。

所有其他命令都完全没问题。我试图一遍又一遍地阅读 SQL 文档,但没有成功。大家怎么看?

最佳答案

先行事务后缺少 sqlite3_finalize(statement) 会导致此错误。

关于ios - SQLite Drop Table导致Database is Locked错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24358947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com