Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure pragmas option #300

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Incremental Store/EncryptedStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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];
Expand Down