diff --git a/Incremental Store/EncryptedStore.m b/Incremental Store/EncryptedStore.m index aa7a382..7c2894e 100755 --- a/Incremental Store/EncryptedStore.m +++ b/Incremental Store/EncryptedStore.m @@ -861,6 +861,11 @@ - (BOOL)loadMetadata:(NSError **)error { database = NULL; return NO; } + if (![self configureNSSQLitePragmasOption]) { + sqlite3_close(database); + database = NULL; + return NO; + } // invoke vacuum if needed if ([self.options[NSSQLiteManualVacuumOption] boolValue]) { @@ -1253,6 +1258,26 @@ - (BOOL)changeDatabasePassphrase:(NSString *)oldPassphrase toNewPassphrase:(NSSt return result && (*error == nil); } +-(BOOL)configureNSSQLitePragmasOption +{ + NSDictionary *pragmasOption = [[self options] objectForKey:NSSQLitePragmasOption]; + if (pragmasOption != nil) { + for (NSString *pragmaKey in pragmasOption) { + NSString *pragmaValue = [pragmasOption objectForKey:pragmaKey]; + NSString *string = [NSString stringWithFormat:@"PRAGMA %@ = %@;", pragmaKey, pragmaValue]; + sqlite3_stmt *statement = [self preparedStatementForQuery:string]; + sqlite3_step(statement); + + if (statement == NULL || sqlite3_finalize(statement) != SQLITE_OK) { + // TO-DO: handle error with statement + NSLog(@"Error: statement is NULL or could not be finalized"); + return NO; + } + } + } + return YES; +} + -(BOOL)configureDatabaseCacheSize { NSNumber *cacheSize = [[self options] objectForKey:EncryptedStoreCacheSize];