Răsfoiți Sursa

Fix for issue #211: Add 'databasePool:didAddDatabase:' method to FMDatabasePoolDelegate protocol

Timur Islamgulov 12 ani în urmă
părinte
comite
3f8cee50c4
2 a modificat fișierele cu 11 adăugiri și 0 ștergeri
  1. 6 0
      src/FMDatabasePool.h
  2. 5 0
      src/FMDatabasePool.m

+ 6 - 0
src/FMDatabasePool.h

@@ -161,7 +161,13 @@
 
 @interface NSObject (FMDatabasePoolDelegate)
 
+/** Asks the delegate whether database should be added to the pool. */
+
 - (BOOL)databasePool:(FMDatabasePool*)pool shouldAddDatabaseToPool:(FMDatabase*)database;
 
+/** Tells the delegate that database was added to the pool. */
+
+- (void)databasePool:(FMDatabasePool*)pool didAddDatabase:(FMDatabase*)database;
+
 @end
 

+ 5 - 0
src/FMDatabasePool.m

@@ -100,6 +100,7 @@ - (void)pushDatabaseBackInPool:(FMDatabase*)db {
 - (FMDatabase*)db {
     
     __block FMDatabase *db;
+    __block BOOL shouldNotifyDelegate = NO;
     
     [self executeLocked:^() {
         db = [_databaseInPool lastObject];
@@ -120,6 +121,7 @@ - (FMDatabase*)db {
             }
             
             db = [FMDatabase databaseWithPath:_path];
+            shouldNotifyDelegate = YES;
         }
         
         //This ensures that the db is opened before returning
@@ -136,6 +138,9 @@ - (FMDatabase*)db {
                 //It should not get added in the pool twice if lastObject was found
                 if (![_databaseOutPool containsObject:db]) {
                     [_databaseOutPool addObject:db];
+                    
+                    if ([_delegate respondsToSelector:@selector(databasePool:didAddDatabase:)] && shouldNotifyDelegate)
+                        [_delegate databasePool:self didAddDatabase:db];
                 }
             }
         }