|
|
@@ -93,21 +93,25 @@ - (FMDatabase*)db {
|
|
|
}
|
|
|
|
|
|
db = [FMDatabase databaseWithPath:_path];
|
|
|
-
|
|
|
- if ([db open]) {
|
|
|
- if ([_delegate respondsToSelector:@selector(databasePool:shouldAddDatabaseToPool:)] && ![_delegate databasePool:self shouldAddDatabaseToPool:db]) {
|
|
|
- [db close];
|
|
|
- db = 0x00;
|
|
|
- }
|
|
|
- else {
|
|
|
- [_databaseOutPool addObject:db];
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ //This ensures that the db is opened before returning
|
|
|
+ if ([db open]) {
|
|
|
+ if ([_delegate respondsToSelector:@selector(databasePool:shouldAddDatabaseToPool:)] && ![_delegate databasePool:self shouldAddDatabaseToPool:db]) {
|
|
|
+ [db close];
|
|
|
+ db = 0x00;
|
|
|
}
|
|
|
else {
|
|
|
- NSLog(@"Could not open up the database at path %@", _path);
|
|
|
- db = 0x00;
|
|
|
+ //It should not get added in the pool twice if lastObject was found
|
|
|
+ if (![_databaseOutPool containsObject:db]) {
|
|
|
+ [_databaseOutPool addObject:db];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ else {
|
|
|
+ NSLog(@"Could not open up the database at path %@", _path);
|
|
|
+ db = 0x00;
|
|
|
+ }
|
|
|
|
|
|
[db setPool:self];
|
|
|
}];
|