Browse Source

Added an access method for the database, so you can do configuration stuff on it.

August Mueller 14 years ago
parent
commit
41146efc4e
2 changed files with 18 additions and 11 deletions
  1. 7 0
      src/FMDatabaseQueue.h
  2. 11 11
      src/FMDatabaseQueue.m

+ 7 - 0
src/FMDatabaseQueue.h

@@ -28,6 +28,13 @@
 - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
 - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
 
+/* the database is exposed so you can do things like turning on cached statements
+   or setup encryption or whatever.  Don't grab the database and start making
+   queries with it.  Use the block based access above instead (otherwise you're
+   going to deadlock and cause baby unicorns to cry.
+ */
+- (FMDatabase*)database;
+
 #if SQLITE_VERSION_NUMBER >= 3007000
 // NOTE: 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's startSavePointWithName:error: instead.

+ 11 - 11
src/FMDatabaseQueue.m

@@ -60,7 +60,7 @@ - (void)close {
     });
 }
 
-- (FMDatabase*)db {
+- (FMDatabase*)database {
     if (!_db) {
         _db = [[FMDatabase databaseWithPath:_path] retain];
         if (![_db open]) {
@@ -78,7 +78,7 @@ - (void)inDatabase:(void (^)(FMDatabase *db))block {
     
     dispatch_sync(_queue, ^() {
         
-        FMDatabase *db = [self db];
+        FMDatabase *db = [self database];
         block(db);
         
         if ([db hasOpenResultSets]) {
@@ -95,19 +95,19 @@ - (void)beginTransaction:(BOOL)useDeferred withBlock:(void (^)(FMDatabase *db, B
         BOOL shouldRollback = NO;
         
         if (useDeferred) {
-            [[self db] beginDeferredTransaction];
+            [[self database] beginDeferredTransaction];
         }
         else {
-            [[self db] beginTransaction];
+            [[self database] beginTransaction];
         }
         
-        block([self db], &shouldRollback);
+        block([self database], &shouldRollback);
         
         if (shouldRollback) {
-            [[self db] rollback];
+            [[self database] rollback];
         }
         else {
-            [[self db] commit];
+            [[self database] commit];
         }
     
     });
@@ -133,15 +133,15 @@ - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
         
         BOOL shouldRollback = NO;
         
-        if ([[self db] startSavePointWithName:name error:&err]) {
+        if ([[self database] startSavePointWithName:name error:&err]) {
             
-            block([self db], &shouldRollback);
+            block([self database], &shouldRollback);
             
             if (shouldRollback) {
-                [[self db] rollbackToSavePointWithName:name error:&err];
+                [[self database] rollbackToSavePointWithName:name error:&err];
             }
             else {
-                [[self db] releaseSavePointWithName:name error:&err];
+                [[self database] releaseSavePointWithName:name error:&err];
             }
             
         }