Skip to content

Commit

Permalink
Support for custom database class and vfsName
Browse files Browse the repository at this point in the history
Brings API in line with FMDatabaseQueue
  • Loading branch information
Pierre Bernard committed Apr 5, 2016
1 parent 4d7c884 commit 9c9e057
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
27 changes: 26 additions & 1 deletion src/fmdb/FMDatabasePool.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
__unsafe_unretained id _delegate;

NSUInteger _maximumNumberOfDatabasesToCreate;
int _openFlags;
int _openFlags;
NSString *_vfsName;
}

/** Database path */
Expand All @@ -58,6 +59,10 @@

@property (atomic, readonly) int openFlags;

/** Custom virtual file system name */

@property (atomic, copy) NSString *vfsName;


///---------------------
/// @name Initialization
Expand Down Expand Up @@ -101,6 +106,26 @@

- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags;

/** Create pool using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@param vfsName The name of a custom virtual file system
@return The `FMDatabasePool` object. `nil` on error.
*/

- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName;

/** Returns the Class of 'FMDatabase' subclass, that will be used to instantiate database object.
Subclasses can override this method to return specified Class of 'FMDatabase' subclass.
@return The Class of 'FMDatabase' subclass, that will be used to instantiate database object.
*/

+ (Class)databaseClass;

///------------------------------------------------
/// @name Keeping track of checked in/out databases
///------------------------------------------------
Expand Down
14 changes: 11 additions & 3 deletions src/fmdb/FMDatabasePool.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ + (instancetype)databasePoolWithPath:(NSString*)aPath flags:(int)openFlags {
return FMDBReturnAutoreleased([[self alloc] initWithPath:aPath flags:openFlags]);
}

- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags {
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName {

self = [super init];

Expand All @@ -48,11 +48,16 @@ - (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags {
_databaseInPool = FMDBReturnRetained([NSMutableArray array]);
_databaseOutPool = FMDBReturnRetained([NSMutableArray array]);
_openFlags = openFlags;
_vfsName = [vfsName copy];
}

return self;
}

- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags {
return [self initWithPath:aPath flags:openFlags vfs:nil];
}

- (instancetype)initWithPath:(NSString*)aPath
{
// default flags for sqlite3_open
Expand All @@ -63,6 +68,9 @@ - (instancetype)init {
return [self initWithPath:nil];
}

+ (Class)databaseClass {
return [FMDatabase class];
}

- (void)dealloc {

Expand Down Expand Up @@ -128,13 +136,13 @@ - (FMDatabase*)db {
}
}

db = [FMDatabase databaseWithPath:self->_path];
db = [[[self class] databaseClass] databaseWithPath:self->_path];
shouldNotifyDelegate = YES;
}

//This ensures that the db is opened before returning
#if SQLITE_VERSION_NUMBER >= 3005000
BOOL success = [db openWithFlags:self->_openFlags];
BOOL success = [db openWithFlags:self->_openFlags vfs:self->_vfsName];
#else
BOOL success = [db open];
#endif
Expand Down

0 comments on commit 9c9e057

Please sign in to comment.