I have an application that often accesses sqlite database. It works great most of the time, but sometimes in one of my database functions it fails and returns:
file is encrypted or not a database
I do not have encryption, but I can’t determine exactly how this happens. It is not always reproducible from accident logs, it happens on the main thread.
Thanks in advance.
@synchronized(self) {
sqlite3 *database = mydb;
int result = 0;
static sqlite3_stmt *stmt = nil;
if (stmt == nil) {
const char *sql = "select sum(not isAvailable) from table1 e inner join table2 f on e.key=f.pk where f.pk=? AND e.isDeleting=0;";
if (sqlite3_prepare_v2(database, sql, -1, &stmt, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
}
sqlite3_bind_int(stmt, 1, obj.primaryKey);
if (sqlite3_step(stmt) == SQLITE_ROW) {
int val = sqlite3_column_int(stmt, 0);
result = val;
} else {
[NSException raise:@"SQL Fail" format:@"SQL Failed: %s", sqlite3_errmsg(database)];
}
sqlite3_reset(stmt);
return result;
}
source
share