From 51905216c5eacd33a16d7a9594483df9c07f764f Mon Sep 17 00:00:00 2001 From: lijianghuai Date: Wed, 23 Dec 2020 16:12:43 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90bugfix=E3=80=91bugly=20=E4=B8=AD?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=20insert=20=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E7=94=A8=20autorelease=20=E8=BF=98=E6=98=AF=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=20=20AutoreleasePoolPage::releaseUntil=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=97=AA=E9=80=80=EF=BC=8C=E5=B9=B6=E4=B8=94=20insert?= =?UTF-8?q?=20=E5=92=8C=20update=20=E4=B8=B4=E6=97=B6=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E5=B9=B6=E4=B8=8D=E5=AF=B9=EF=BC=8C=E6=89=80=E4=BB=A5=E4=B8=8D?= =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E5=8C=85=E5=9C=A8=20autorelease=20pool=20?= =?UTF-8?q?=E5=86=85=E3=80=82=20=09=09=E5=9C=A8=E5=8D=A1=E9=A1=BF=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E4=B8=AD=20NSNumberFormatter=20numberFromString=20?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E9=87=8F=E4=B9=9F=E4=B8=8D=E5=B0=91=EF=BC=8C?= =?UTF-8?q?=E4=BA=8E=E6=98=AF=E5=86=B3=E5=AE=9A=E7=9B=B4=E6=8E=A5=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20string=20=E7=9A=84=E7=9B=B8=E5=85=B3API=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=20NSNumber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LKDBHelper.podspec.json | 4 ++-- LKDBHelper/Helper/LKDBHelper.m | 20 ++++---------------- LKDBHelper/Helper/LKDBUtils.h | 26 ++++++++++++++++++++++---- LKDBHelper/Helper/LKDBUtils.m | 16 +++++----------- LKDBHelper/Helper/NSObject+LKModel.m | 4 ++-- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/LKDBHelper.podspec.json b/LKDBHelper.podspec.json index 454b2cc..89b06e9 100644 --- a/LKDBHelper.podspec.json +++ b/LKDBHelper.podspec.json @@ -1,6 +1,6 @@ { "name": "LKDBHelper", - "version": "2.5.6", + "version": "2.5.7", "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.6" + "tag": "2.5.7" }, "platforms": { "ios": "5.0", diff --git a/LKDBHelper/Helper/LKDBHelper.m b/LKDBHelper/Helper/LKDBHelper.m index cb37cb9..b4c213f 100644 --- a/LKDBHelper/Helper/LKDBHelper.m +++ b/LKDBHelper/Helper/LKDBHelper.m @@ -1178,19 +1178,13 @@ - (NSMutableArray *)executeResult:(FMResultSet *)set Class:(Class)modelClass tab #pragma mark - insert operation - (BOOL)insertToDB:(NSObject *)model { - __block BOOL success = NO; - [self inAutoReleaseExecuteBlock:^{ - success = [self insertBase:model]; - }]; + BOOL success = [self insertBase:model]; return success; } - (void)insertToDB:(NSObject *)model callback:(void (^)(BOOL))block { LKDBCode_Async_Begin; - __block BOOL success = NO; - [sself inAutoReleaseExecuteBlock:^{ - success = [sself insertBase:model]; - }]; + BOOL success = [sself insertBase:model]; if (block) { block(success); } @@ -1303,19 +1297,13 @@ - (BOOL)insertBase:(NSObject *)model { #pragma mark - update operation - (BOOL)updateToDB:(NSObject *)model where:(id)where { - __block BOOL success = NO; - [self inAutoReleaseExecuteBlock:^{ - success = [self updateToDBBase:model where:where]; - }]; + BOOL success = [self updateToDBBase:model where:where]; return success; } - (void)updateToDB:(NSObject *)model where:(id)where callback:(void (^)(BOOL))block { LKDBCode_Async_Begin; - __block BOOL success = NO; - [sself inAutoReleaseExecuteBlock:^{ - success = [sself updateToDBBase:model where:where]; - }]; + BOOL success = [sself updateToDBBase:model where:where]; if (block) { block(success); } diff --git a/LKDBHelper/Helper/LKDBUtils.h b/LKDBHelper/Helper/LKDBUtils.h index 6e93686..d805b56 100644 --- a/LKDBHelper/Helper/LKDBUtils.h +++ b/LKDBHelper/Helper/LKDBUtils.h @@ -43,17 +43,33 @@ NS_ASSUME_NONNULL_BEGIN @end + +#pragma mark - 数据格式化相关,可 method swizzle 做逻辑替换 + +@interface LKDateFormatter : NSDateFormatter + +///由于 NSDateFormatter 相关API 并不是线程安全的 +@property (nonatomic, assign) dispatch_semaphore_t lock; + +@end + +@interface LKNumberFormatter : NSNumberFormatter + +@end + /// 需要外部实现对应 API -@interface LKDBUtils (output) +@interface LKDBUtils (Events) // LKDateFormatter 创建完毕, 可以修改对应属性 -+ (void)onCreateWithDateFormatter:(NSDateFormatter *)dateFormatter; ++ (void)onCreateWithDateFormatter:(LKDateFormatter *)dateFormatter; -// NSNumberFormatter 创建完毕, 可以修改对应属性 -+ (void)onCreateWithNumberFormatter:(NSNumberFormatter *)numberFormatter; +// LKNumberFormatter 创建完毕, 可以修改对应属性 ++ (void)onCreateWithNumberFormatter:(LKNumberFormatter *)numberFormatter; @end +#pragma mark - Types + #ifdef DEBUG #ifdef NSLog #define LKErrorLog(fmt, ...) NSLog(@"#LKDBHelper ERROR:\n" fmt, ##__VA_ARGS__); @@ -101,6 +117,8 @@ static NSString *const LKDB_PValueKey = @"DB_PKeyValue"; ///Object-c type converted to SQLite type 把Object-c 类型 转换为sqlite 类型 extern NSString *LKSQLTypeFromObjcType(NSString *objcType); +#pragma mark - Search Utils + @interface LKDBQueryParams : NSObject ///columns or array diff --git a/LKDBHelper/Helper/LKDBUtils.m b/LKDBHelper/Helper/LKDBUtils.m index 6357a9b..1088815 100644 --- a/LKDBHelper/Helper/LKDBUtils.m +++ b/LKDBHelper/Helper/LKDBUtils.m @@ -8,10 +8,6 @@ #import "LKDBUtils.h" -@interface LKDateFormatter : NSDateFormatter -@property (nonatomic, assign) dispatch_semaphore_t lock; -@end - @implementation LKDateFormatter - (instancetype)init { @@ -51,10 +47,6 @@ - (NSString *)stringFromDate:(NSDate *)date { @end -@interface LKNumberFormatter : NSNumberFormatter - -@end - @implementation LKNumberFormatter - (instancetype)init { @@ -76,9 +68,11 @@ - (NSString *)stringFromNumber:(NSNumber *)number { } - (NSNumber *)numberFromString:(NSString *)string { - NSNumber *number = [super numberFromString:string]; - if (!number) { - number = @(string.doubleValue); + NSNumber *number = nil; + if ([string rangeOfString:@"."].length > 0) { + number = [NSNumber numberWithDouble:string.doubleValue]; + } else { + number = [NSNumber numberWithLongLong:string.longLongValue]; } return number; } diff --git a/LKDBHelper/Helper/NSObject+LKModel.m b/LKDBHelper/Helper/NSObject+LKModel.m index cc72710..4edc463 100644 --- a/LKDBHelper/Helper/NSObject+LKModel.m +++ b/LKDBHelper/Helper/NSObject+LKModel.m @@ -146,7 +146,7 @@ - (id)modelGetValue:(LKDBProperty *)property { #endif } else if ([value isKindOfClass:[LKDBImage class]]) { long random = arc4random(); - long date = [[NSDate date] timeIntervalSince1970]; + long date = CFAbsoluteTimeGetCurrent(); NSString *filename = [NSString stringWithFormat:@"img%ld%ld", date & 0xFFFFF, random & 0xFFF]; #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED @@ -163,7 +163,7 @@ - (id)modelGetValue:(LKDBProperty *)property { returnValue = filename; } else if ([value isKindOfClass:[NSData class]]) { long random = arc4random(); - long date = [[NSDate date] timeIntervalSince1970]; + long date = CFAbsoluteTimeGetCurrent(); NSString *filename = [NSString stringWithFormat:@"data%ld%ld", date & 0xFFFFF, random & 0xFFF]; [value writeToFile:[self.class getDBDataPathWithName:filename] atomically:YES];