I have created a little database upgrade tool to update our sqlite database tables based on PRAGMA user_version. It has been working well until recently I needed to drop a table entirely.
obviously the drop table command is
DROP TABLE tbl;
The sql instructions are executed using:
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];
}
Every time I try to run a drop table command, the execution fails with 'database is locked' with a result SQLITE_LOCKED.
All other commands are completely fine. I tried to read the SQL documentation over and over with no luck. What do you guys think?
A missing sqlite3_finalize(statement) after the antecedent transaction can cause this error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With