我创建了一个小型的数据库升级工具,根据PRAGMA user_version更新我们的sqlite数据库表。一直以来都运行良好,直到最近我需要完全删除一个表。
显然,删除表的命令是
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];
}
每次我尝试运行一个删除表的命令时,执行都会失败,并显示 'database is locked' 的结果,错误代码为 SQLITE_LOCKED。
所有其他命令都没问题。我尝试反复阅读SQL文档,但没有任何收获。 你们认为是什么原因呢?