
Untitled
By: a guest on
May 20th, 2012 | syntax:
None | size: 0.98 KB | hits: 13 | expires: Never
+ (BOOL)checkIntegrity {
NSString *databasePath = [self databaseFilePath];
// File not exists = okay
if ( ! [[NSFileManager defaultManager] fileExistsAtPath:databasePath] ) {
return YES;
}
const char *filename = ( const char * )[databasePath cStringUsingEncoding:NSUTF8StringEncoding];
sqlite3 *database = NULL;
if ( sqlite3_open( filename, &database ) != SQLITE_OK ) {
sqlite3_close( database );
return NO;
}
BOOL integrityVerified = NO;
sqlite3_stmt *integrity = NULL;
if ( sqlite3_prepare_v2( database, "PRAGMA integrity_check;", -1, &integrity, NULL ) == SQLITE_OK ) {
while ( sqlite3_step( integrity ) == SQLITE_ROW ) {
const unsigned char *result = sqlite3_column_text( integrity, 0 );
if ( result && strcmp( ( const char * )result, (const char *)"ok" ) == 0 ) {
integrityVerified = YES;
break;
}
}
sqlite3_finalize( integrity );
}
sqlite3_close( database );
return integrityVerified;
}