FMDatabaseQueue.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 FMDatabaseQueue : NSObject {
  12. NSString *_path;
  13. dispatch_queue_t _queue;
  14. FMDatabase *_db;
  15. }
  16. @property (retain) NSString *path;
  17. + (id)databaseQueueWithPath:(NSString*)aPath;
  18. - (id)initWithPath:(NSString*)aPath;
  19. - (void)close;
  20. - (void)inDatabase:(void (^)(FMDatabase *db))block;
  21. - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
  22. - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
  23. /* the database is exposed so you can do things like turning on cached statements
  24. or setup encryption or whatever. Don't grab the database and start making
  25. queries with it. Use the block based access above instead (otherwise you're
  26. going to deadlock and cause baby unicorns to cry.
  27. */
  28. - (FMDatabase*)database;
  29. #if SQLITE_VERSION_NUMBER >= 3007000
  30. // NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
  31. // If you need to nest, use FMDatabase's startSavePointWithName:error: instead.
  32. - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
  33. #endif
  34. @end