AWSFMDatabasePool

Objective-C

@interface AWSFMDatabasePool : NSObject {
  NSString *_path;
  dispatch_queue_t _lockQueue;
  NSMutableArray *_databaseInPool;
  NSMutableArray *_databaseOutPool;
  id _delegate;
  NSUInteger _maximumNumberOfDatabasesToCreate;
  int _openFlags;
}

Swift

class AWSFMDatabasePool : NSObject

Pool of <FMDatabase> objects.

### See also

  • <FMDatabaseQueue>
  • <FMDatabase>

Warning

Before using FMDatabasePool, please consider using <FMDatabaseQueue> instead.

If you really really really know what you’re doing and FMDatabasePool is what you really really need (ie, you’re using a read only database), OK you can use it. But just be careful not to deadlock!

For an example on deadlocking, search for: ONLY_USE_THE_POOL_IF_YOU_ARE_DOING_READS_OTHERWISE_YOULL_DEADLOCK_USE_FMDATABASEQUEUE_INSTEAD in the main.m file.

  • Undocumented

    Declaration

    Objective-C

    NSString            *_path
  • Undocumented

    Declaration

    Objective-C

    dispatch_queue_t    _lockQueue
  • Undocumented

    Declaration

    Objective-C

    NSMutableArray      *_databaseInPool
  • Undocumented

    Declaration

    Objective-C

    NSMutableArray      *_databaseOutPool
  • Undocumented

    Declaration

    Objective-C

    __unsafe_unretained id _delegate
  • Undocumented

    Declaration

    Objective-C

    NSUInteger          _maximumNumberOfDatabasesToCreate
  • Undocumented

    Declaration

    Objective-C

    int                 _openFlags
  • Database path

    Declaration

    Objective-C

    @property (retain) NSString *path;

    Swift

    var path: String! { get set }
  • Delegate object

    Declaration

    Objective-C

    @property id delegate;

    Swift

    unowned(unsafe) var delegate: AnyObject! { get set }
  • Maximum number of databases to create

    Declaration

    Objective-C

    @property NSUInteger maximumNumberOfDatabasesToCreate;

    Swift

    var maximumNumberOfDatabasesToCreate: UInt { get set }
  • Open flags

    Declaration

    Objective-C

    @property (readonly) int openFlags;

    Swift

    var openFlags: Int32 { get }

Initialization

  • Create pool using path.

    Declaration

    Objective-C

    + (instancetype)databasePoolWithPath:(NSString *)aPath;

    Parameters

    aPath

    The file path of the database.

    Return Value

    The FMDatabasePool object. nil on error.

  • Create pool using path and specified flags

    Declaration

    Objective-C

    + (instancetype)databasePoolWithPath:(NSString *)aPath flags:(int)openFlags;

    Parameters

    aPath

    The file path of the database.

    openFlags

    Flags passed to the openWithFlags method of the database

    Return Value

    The FMDatabasePool object. nil on error.

  • Create pool using path.

    Declaration

    Objective-C

    - (instancetype)initWithPath:(NSString *)aPath;

    Swift

    init!(path aPath: String!)

    Parameters

    aPath

    The file path of the database.

    Return Value

    The FMDatabasePool object. nil on error.

  • Create pool using path and specified flags.

    Declaration

    Objective-C

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

    Swift

    init!(path aPath: String!, flags openFlags: Int32)

    Parameters

    aPath

    The file path of the database.

    openFlags

    Flags passed to the openWithFlags method of the database

    Return Value

    The FMDatabasePool object. nil on error.

Keeping track of checked in/out databases

  • Number of checked-in databases in pool

    @returns Number of databases

    Declaration

    Objective-C

    - (NSUInteger)countOfCheckedInDatabases;

    Swift

    func countOfCheckedInDatabases() -> UInt
  • Number of checked-out databases in pool

    @returns Number of databases

    Declaration

    Objective-C

    - (NSUInteger)countOfCheckedOutDatabases;

    Swift

    func countOfCheckedOutDatabases() -> UInt
  • Total number of databases in pool

    @returns Number of databases

    Declaration

    Objective-C

    - (NSUInteger)countOfOpenDatabases;

    Swift

    func countOfOpenDatabases() -> UInt
  • Release all databases in pool

    Declaration

    Objective-C

    - (void)releaseAllDatabases;

    Swift

    func releaseAllDatabases()

Perform database operations in pool

  • Synchronously perform database operations in pool.

    Declaration

    Objective-C

    - (void)inDatabase:(void (^)(AWSFMDatabase *))block;

    Swift

    func inDatabase(_ block: ((AWSFMDatabase?) -> Void)!)

    Parameters

    block

    The code to be run on the FMDatabasePool pool.

  • Synchronously perform database operations in pool using transaction.

    Declaration

    Objective-C

    - (void)inTransaction:(void (^)(AWSFMDatabase *, BOOL *))block;

    Swift

    func inTransaction(_ block: ((AWSFMDatabase?, UnsafeMutablePointer<ObjCBool>?) -> Void)!)

    Parameters

    block

    The code to be run on the FMDatabasePool pool.

  • Synchronously perform database operations in pool using deferred transaction.

    Declaration

    Objective-C

    - (void)inDeferredTransaction:(void (^)(AWSFMDatabase *, BOOL *))block;

    Swift

    func inDeferredTransaction(_ block: ((AWSFMDatabase?, UnsafeMutablePointer<ObjCBool>?) -> Void)!)

    Parameters

    block

    The code to be run on the FMDatabasePool pool.

  • Synchronously perform database operations in pool using save point.

    Warning

    You can not nest these, since calling it will pull another database out of the pool and you’ll get a deadlock. If you need to nest, use <[FMDatabase startSavePointWithName:error:]> instead.

    Declaration

    Objective-C

    - (NSError *)inSavePoint:(void (^)(AWSFMDatabase *, BOOL *))block;

    Swift

    func inSavePoint(_ block: ((AWSFMDatabase?, UnsafeMutablePointer<ObjCBool>?) -> Void)!) -> Error!

    Parameters

    block

    The code to be run on the FMDatabasePool pool.

    Return Value

    NSError object if error; nil if successful.

AWSHelpers

  • Convenience method to create a database pool with the SQLITE_OPEN_FULLMUTEX flag so it can be safely accessed across threads.

    Declaration

    Objective-C

    + (nonnull instancetype)serialDatabasePoolWithPath:(nonnull NSString *)aPath;

    Swift

    class func serialDatabasePool(withPath aPath: String) -> Self

    Parameters

    aPath

    The file path of the database.

    Return Value

    The FMDatabasePool object. nil on error.