FMDatabasePool.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // FMDatabasePool.h
  3. // fmdb
  4. //
  5. // Created by August Mueller on 6/22/11.
  6. // Copyright 2011 Flying Meat Inc. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "sqlite3.h"
  10. @class FMDatabase;
  11. @interface FMDatabasePool : NSObject {
  12. NSString *_path;
  13. dispatch_queue_t _lockQueue;
  14. NSMutableArray *_databaseInPool;
  15. NSMutableArray *_databaseOutPool;
  16. __unsafe_unretained id _delegate;
  17. NSUInteger _maximumNumberOfDatabasesToCreate;
  18. }
  19. @property (retain) NSString *path;
  20. @property (assign) id delegate;
  21. @property (assign) NSUInteger maximumNumberOfDatabasesToCreate;
  22. + (id)databasePoolWithPath:(NSString*)aPath;
  23. - (id)initWithPath:(NSString*)aPath;
  24. - (void)pushDatabaseBackInPool:(FMDatabase*)db;
  25. - (FMDatabase*)db;
  26. - (NSUInteger)countOfCheckedInDatabases;
  27. - (NSUInteger)countOfCheckedOutDatabases;
  28. - (NSUInteger)countOfOpenDatabases;
  29. - (void)releaseAllDatabases;
  30. - (void)inDatabase:(void (^)(FMDatabase *db))block;
  31. - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
  32. - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
  33. #if SQLITE_VERSION_NUMBER >= 3007000
  34. // NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
  35. // If you need to nest, use FMDatabase's startSavePointWithName:error: instead.
  36. - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
  37. #endif
  38. @end
  39. @interface NSObject (FMDatabasePoolDelegate)
  40. - (BOOL)databasePool:(FMDatabasePool*)pool shouldAddDatabaseToPool:(FMDatabase*)database;
  41. @end