I have a sqlite3 database for an iOs application to provide offline system support.
It works great. But sometimes the .db file gets corrupted. And does not return results.
If I check the SELECT statement on the command line, I get the following error message:
sqllite Error: database disk image is malformed
Although undesirable, it becomes corrupt. A database is just an auxiliary system, which would be enough to detect in the iOS application that the file is damaged and restart the file.
But using sqlite3 statements, I did not get any exceptions. The code looks like this:
sqlRaw = @"SELECT ... "; const char *sql = [sqlRaw cStringUsingEncoding:NSUTF8StringEncoding]; if (sqlite3_prepare_v2(database, sql, -1, &date_statement, NULL) != SQLITE_OK) { NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); } NSMutableArray *entities = [[NSMutableArray alloc] initWithCapacity:0]; while (sqlite3_step(date_statement) == SQLITE_ROW) { NSData *entityXml = [[NSData alloc] initWithBytes:sqlite3_column_blob(date_statement, 0) length:sqlite3_column_bytes(date_statement, 0)]; [entities addObject:entityXml]; } sqlite3_finalize(date_statement);
When the application executes the previous code, it simply returns an empty array, no exception is thrown.
Does anyone know how to check the status of a .db file from sqlite3 statements?
Perhaps a different storage system is better for the user. Any recommendations?
source share