From 903523244fa8748885f9ff2e2494a5007249c975 Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Tue, 22 May 2018 16:24:57 -0600 Subject: [PATCH 1/2] Configure NSSQLitePragmasOption parameters on database open Handles "journal_mode" : "WAL" configuration option --- Incremental Store/EncryptedStore.m | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Incremental Store/EncryptedStore.m b/Incremental Store/EncryptedStore.m index aa7a382..1527b49 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,28 @@ - (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; + } else { + return YES; + } + } + } + return YES; +} + -(BOOL)configureDatabaseCacheSize { NSNumber *cacheSize = [[self options] objectForKey:EncryptedStoreCacheSize]; From 7315d8bed8c2c8b1466406723230eb8c76cd63bd Mon Sep 17 00:00:00 2001 From: Jeff Lockhart Date: Wed, 23 May 2018 10:19:38 -0600 Subject: [PATCH 2/2] Don't return too early --- Incremental Store/EncryptedStore.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/Incremental Store/EncryptedStore.m b/Incremental Store/EncryptedStore.m index 1527b49..7c2894e 100755 --- a/Incremental Store/EncryptedStore.m +++ b/Incremental Store/EncryptedStore.m @@ -1272,8 +1272,6 @@ -(BOOL)configureNSSQLitePragmasOption // TO-DO: handle error with statement NSLog(@"Error: statement is NULL or could not be finalized"); return NO; - } else { - return YES; } } }