Skip to content

Commit 1aa336d

Browse files
ljhljh
ljh
authored and
ljh
committed
bug fixed
1 parent b4f4044 commit 1aa336d

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

LKDBHelper.podspec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "LKDBHelper",
3-
"version": "2.1.2",
3+
"version": "2.1.3",
44
"summary": "全自动的插入,查询,更新,删除, an automatic database operation thread-safe and not afraid of recursive deadlock",
55
"description": "全面支持 NSArray,NSDictionary, ModelClass, NSNumber, NSString, NSDate, NSData, UIColor, UIImage, CGRect, CGPoint, CGSize, NSRange, int,char,float, double, long.. 等属性的自动化操作(插入和查询)",
66
"homepage": "https://github.com/li6185377/LKDBHelper-SQLite-ORM",
@@ -10,7 +10,7 @@
1010
},
1111
"source": {
1212
"git": "https://github.com/li6185377/LKDBHelper-SQLite-ORM.git",
13-
"tag": "2.1.2"
13+
"tag": "2.1.3"
1414
},
1515
"platforms": {
1616
"ios": "4.3",

LKDBHelper/Helper/LKDBHelper.m

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,32 @@ + (NSMutableArray *)dbHelperSingleArray
6868
+ (LKDBHelper *)dbHelperWithPath:(NSString *)dbFilePath save:(LKDBHelper *)helper
6969
{
7070
NSMutableArray *dbArray = [self dbHelperSingleArray];
71-
72-
if (helper) {
73-
LKDBWeakObject *weakObj = [[LKDBWeakObject alloc] init];
74-
weakObj.obj = helper;
75-
[dbArray addObject:weakObj];
76-
} else if (dbFilePath) {
77-
LKDBHelper *instance = nil;
78-
@synchronized(dbArray) {
71+
LKDBHelper *instance = nil;
72+
@synchronized(dbArray) {
73+
if (helper)
74+
{
75+
LKDBWeakObject *weakObj = [[LKDBWeakObject alloc] init];
76+
weakObj.obj = helper;
77+
[dbArray addObject:weakObj];
78+
}
79+
else if (dbFilePath)
80+
{
7981
for (NSInteger i = 0; i < dbArray.count; ) {
8082
LKDBWeakObject *weakObj = [dbArray objectAtIndex:i];
81-
83+
8284
if (weakObj.obj == nil) {
8385
[dbArray removeObjectAtIndex:i];
8486
continue;
8587
} else if ([weakObj.obj.dbPath isEqualToString:dbFilePath]) {
8688
instance = weakObj.obj;
8789
break;
8890
}
89-
91+
9092
i++;
9193
}
9294
}
93-
return instance;
9495
}
95-
96-
return nil;
96+
return instance;
9797
}
9898

9999
- (instancetype)init
@@ -421,10 +421,12 @@ - (void)setEncryptionKey:(NSString *)encryptionKey
421421
- (void)dealloc
422422
{
423423
NSArray *array = [LKDBHelper dbHelperSingleArray];
424-
425-
for (LKDBWeakObject *weakObject in array) {
426-
if ([weakObject.obj isEqual:self]) {
427-
weakObject.obj = nil;
424+
425+
@synchronized(array) {
426+
for (LKDBWeakObject *weakObject in array) {
427+
if ([weakObject.obj isEqual:self]) {
428+
weakObject.obj = nil;
429+
}
428430
}
429431
}
430432

@@ -517,7 +519,7 @@ - (void)fixSqlColumnsWithClass:(Class)clazz tableName:(NSString *)tableName
517519
[addColumePars appendFormat:@" %@ %@", LKSQL_Attribute_Default, property.defaultValue];
518520
}
519521

520-
NSString * alertSQL = [NSString stringWithFormat:@"alter table %@ add column %@", tableName, addColumePars];
522+
NSString *alertSQL = [NSString stringWithFormat:@"alter table %@ add column %@", tableName, addColumePars];
521523
NSString *initColumnValue = [NSString stringWithFormat:@"update %@ set %@=%@", tableName, property.sqlColumnName, [property.sqlColumnType isEqualToString:LKSQL_Type_Text] ? @"''":@"0"];
522524

523525
BOOL success = [db executeUpdate:alertSQL];
@@ -651,12 +653,13 @@ - (BOOL)getTableCreatedWithTableName:(NSString *)tableName
651653

652654
[self executeDB:^(FMDatabase *db) {
653655
FMResultSet *set = [db executeQuery:@"select count(name) from sqlite_master where type='table' and name=?", tableName];
654-
if([set next])
655-
{
656+
657+
if ([set next]) {
656658
if ([set intForColumnIndex:0] > 0) {
657659
isTableCreated = YES;
658660
}
659661
}
662+
660663
[set close];
661664
}];
662665
return isTableCreated;
@@ -1159,21 +1162,18 @@ - (BOOL)updateToDBBase:(NSObject *)model where:(id)where
11591162
id value = [self modelValueWithProperty:property model:model];
11601163

11611164
///跳过 rowid = 0 的属性
1162-
if([property.sqlColumnName isEqualToString:@"rowid"])
1163-
{
1165+
if ([property.sqlColumnName isEqualToString:@"rowid"]) {
11641166
int rowid = [value intValue];
1165-
if(rowid > 0)
1166-
{
1167+
1168+
if (rowid > 0) {
11671169
///如果rowid 已经存在就不修改
1168-
NSString* rowidWhere = [NSString stringWithFormat:@"rowid=%d",rowid];
1170+
NSString *rowidWhere = [NSString stringWithFormat:@"rowid=%d", rowid];
11691171
NSInteger rowCount = [self rowCountWithTableName:db_tableName where:rowidWhere];
1170-
if(rowCount > 0)
1171-
{
1172+
1173+
if (rowCount > 0) {
11721174
continue;
11731175
}
1174-
}
1175-
else
1176-
{
1176+
} else {
11771177
continue;
11781178
}
11791179
}

0 commit comments

Comments
 (0)