Skip to content

Commit

Permalink
Fixed a crasher when trying to open up a temporary database.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed Feb 8, 2013
1 parent bbca642 commit e7b3d94
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/FMDatabase.m
Expand Up @@ -72,12 +72,26 @@ - (sqlite3*)sqliteHandle {
return _db;
}

- (const char*)sqlitePath {

if (!_databasePath) {
return ":memory:";
}

if ([_databasePath length] == 0) {
return ""; // this creates a temporary database (it's an sqlite thing).
}

return [_databasePath fileSystemRepresentation];

}

- (BOOL)open {
if (_db) {
return YES;
}

int err = sqlite3_open((_databasePath ? [_databasePath fileSystemRepresentation] : ":memory:"), &_db );
int err = sqlite3_open([self sqlitePath], &_db );
if(err != SQLITE_OK) {
NSLog(@"error opening!: %d", err);
return NO;
Expand All @@ -88,7 +102,7 @@ - (BOOL)open {

#if SQLITE_VERSION_NUMBER >= 3005000
- (BOOL)openWithFlags:(int)flags {
int err = sqlite3_open_v2((_databasePath ? [_databasePath fileSystemRepresentation] : ":memory:"), &_db, flags, NULL /* Name of VFS module to use */);
int err = sqlite3_open_v2([self sqlitePath], &_db, flags, NULL /* Name of VFS module to use */);
if(err != SQLITE_OK) {
NSLog(@"error opening!: %d", err);
return NO;
Expand Down

0 comments on commit e7b3d94

Please sign in to comment.