diff --git a/LKDBHelper.podspec.json b/LKDBHelper.podspec.json index 2b78cdb..454b2cc 100644 --- a/LKDBHelper.podspec.json +++ b/LKDBHelper.podspec.json @@ -1,6 +1,6 @@ { "name": "LKDBHelper", - "version": "2.5.5", + "version": "2.5.6", "summary": "全自动的插入,查询,更新,删除, an automatic database operation thread-safe and not afraid of recursive deadlock", "description": "全面支持 NSArray,NSDictionary, ModelClass, NSNumber, NSString, NSDate, NSData, UIColor, UIImage, CGRect, CGPoint, CGSize, NSRange, int,char,float, double, long.. 等属性的自动化操作(插入和查询)", "homepage": "https://github.com/li6185377/LKDBHelper-SQLite-ORM", @@ -10,7 +10,7 @@ }, "source": { "git": "https://github.com/li6185377/LKDBHelper-SQLite-ORM.git", - "tag": "2.5.5" + "tag": "2.5.6" }, "platforms": { "ios": "5.0", diff --git a/LKDBHelper/Helper/LKDBHelper.m b/LKDBHelper/Helper/LKDBHelper.m index 525020a..cb37cb9 100644 --- a/LKDBHelper/Helper/LKDBHelper.m +++ b/LKDBHelper/Helper/LKDBHelper.m @@ -64,6 +64,8 @@ @interface LKDBHelper () @property (nonatomic, assign) BOOL runingAutoCloseTimer; @property (nonatomic, assign) NSInteger autoCloseDBDelayTime; +@property (nonatomic, assign) BOOL inAutoReleasePool; + @end @implementation LKDBHelper @@ -1093,14 +1095,25 @@ - (NSMutableArray *)executeOneColumnResult:(FMResultSet *)set { return array; } -- (void)foreachResultSet:(FMResultSet *)set block:(void(^)(void))block { - while ([set next]) { +- (void)inAutoReleaseExecuteBlock:(void(^)(void))block { + if (self.inAutoReleasePool) { + // 已在 @autoreleasepool 范围内 + block(); + } else { @autoreleasepool { + self.inAutoReleasePool = YES; block(); + self.inAutoReleasePool = NO; } } } +- (void)foreachResultSet:(FMResultSet *)set block:(void(^)(void))block { + while ([set next]) { + [self inAutoReleaseExecuteBlock:block]; + } +} + - (NSMutableArray *)executeResult:(FMResultSet *)set Class:(Class)modelClass tableName:(NSString *)tableName { NSMutableArray *array = [NSMutableArray arrayWithCapacity:0]; if (!modelClass) { @@ -1165,19 +1178,19 @@ - (NSMutableArray *)executeResult:(FMResultSet *)set Class:(Class)modelClass tab #pragma mark - insert operation - (BOOL)insertToDB:(NSObject *)model { - BOOL success = NO; - @autoreleasepool { + __block BOOL success = NO; + [self inAutoReleaseExecuteBlock:^{ success = [self insertBase:model]; - } + }]; return success; } - (void)insertToDB:(NSObject *)model callback:(void (^)(BOOL))block { LKDBCode_Async_Begin; - BOOL success = NO; - @autoreleasepool { + __block BOOL success = NO; + [sself inAutoReleaseExecuteBlock:^{ success = [sself insertBase:model]; - } + }]; if (block) { block(success); } @@ -1290,19 +1303,19 @@ - (BOOL)insertBase:(NSObject *)model { #pragma mark - update operation - (BOOL)updateToDB:(NSObject *)model where:(id)where { - BOOL success = NO; - @autoreleasepool { + __block BOOL success = NO; + [self inAutoReleaseExecuteBlock:^{ success = [self updateToDBBase:model where:where]; - } + }]; return success; } - (void)updateToDB:(NSObject *)model where:(id)where callback:(void (^)(BOOL))block { LKDBCode_Async_Begin; - BOOL success = NO; - @autoreleasepool { + __block BOOL success = NO; + [sself inAutoReleaseExecuteBlock:^{ success = [sself updateToDBBase:model where:where]; - } + }]; if (block) { block(success); }