Browse Source

Added a warning if there are result sets open when using the database queue.

August Mueller 14 years ago
parent
commit
2f0225b661
3 changed files with 16 additions and 1 deletions
  1. 1 0
      src/FMDatabase.h
  2. 4 0
      src/FMDatabase.m
  3. 11 1
      src/FMDatabaseQueue.m

+ 1 - 0
src/FMDatabase.h

@@ -58,6 +58,7 @@
 - (BOOL)goodConnection;
 - (void)clearCachedStatements;
 - (void)closeOpenResultSets;
+- (BOOL)hasOpenResultSets;
 
 // encryption methods.  You need to have purchased the sqlite encryption extensions for these to work.
 - (BOOL)setKey:(NSString*)key;

+ 4 - 0
src/FMDatabase.m

@@ -159,6 +159,10 @@ - (void)clearCachedStatements {
     [_cachedStatements removeAllObjects];
 }
 
+- (BOOL)hasOpenResultSets {
+    return [_openResultSets count] > 0;
+}
+
 - (void)closeOpenResultSets {
     
     //Copy the set so we don't get mutation errors

+ 11 - 1
src/FMDatabaseQueue.m

@@ -73,7 +73,17 @@ - (FMDatabase*)db {
 }
 
 - (void)inDatabase:(void (^)(FMDatabase *db))block {
-    dispatch_sync(_queue, ^() { block([self db]); });
+    
+    dispatch_sync(_queue, ^() {
+        
+        FMDatabase *db = [self db];
+        block(db);
+        
+        if ([db hasOpenResultSets]) {
+            NSLog(@"Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]");
+        }
+        
+    });
 }
 
 - (void)beginTransaction:(BOOL)useDeferred withBlock:(void (^)(FMDatabase *db, BOOL *rollback))block {