@@ -68,32 +68,32 @@ + (NSMutableArray *)dbHelperSingleArray
68
68
+ (LKDBHelper *)dbHelperWithPath : (NSString *)dbFilePath save : (LKDBHelper *)helper
69
69
{
70
70
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
+ {
79
81
for (NSInteger i = 0 ; i < dbArray.count ; ) {
80
82
LKDBWeakObject *weakObj = [dbArray objectAtIndex: i];
81
-
83
+
82
84
if (weakObj.obj == nil ) {
83
85
[dbArray removeObjectAtIndex: i];
84
86
continue ;
85
87
} else if ([weakObj.obj.dbPath isEqualToString: dbFilePath]) {
86
88
instance = weakObj.obj ;
87
89
break ;
88
90
}
89
-
91
+
90
92
i++;
91
93
}
92
94
}
93
- return instance;
94
95
}
95
-
96
- return nil ;
96
+ return instance;
97
97
}
98
98
99
99
- (instancetype )init
@@ -421,10 +421,12 @@ - (void)setEncryptionKey:(NSString *)encryptionKey
421
421
- (void )dealloc
422
422
{
423
423
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
+ }
428
430
}
429
431
}
430
432
@@ -517,7 +519,7 @@ - (void)fixSqlColumnsWithClass:(Class)clazz tableName:(NSString *)tableName
517
519
[addColumePars appendFormat: @" %@ %@ " , LKSQL_Attribute_Default, property.defaultValue];
518
520
}
519
521
520
- NSString * alertSQL = [NSString stringWithFormat: @" alter table %@ add column %@ " , tableName, addColumePars];
522
+ NSString *alertSQL = [NSString stringWithFormat: @" alter table %@ add column %@ " , tableName, addColumePars];
521
523
NSString *initColumnValue = [NSString stringWithFormat: @" update %@ set %@ =%@ " , tableName, property.sqlColumnName, [property.sqlColumnType isEqualToString: LKSQL_Type_Text] ? @" ''" :@" 0" ];
522
524
523
525
BOOL success = [db executeUpdate: alertSQL];
@@ -651,12 +653,13 @@ - (BOOL)getTableCreatedWithTableName:(NSString *)tableName
651
653
652
654
[self executeDB: ^(FMDatabase *db) {
653
655
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 ]) {
656
658
if ([set intForColumnIndex: 0 ] > 0 ) {
657
659
isTableCreated = YES ;
658
660
}
659
661
}
662
+
660
663
[set close ];
661
664
}];
662
665
return isTableCreated;
@@ -1159,21 +1162,18 @@ - (BOOL)updateToDBBase:(NSObject *)model where:(id)where
1159
1162
id value = [self modelValueWithProperty: property model: model];
1160
1163
1161
1164
// /跳过 rowid = 0 的属性
1162
- if ([property.sqlColumnName isEqualToString: @" rowid" ])
1163
- {
1165
+ if ([property.sqlColumnName isEqualToString: @" rowid" ]) {
1164
1166
int rowid = [value intValue ];
1165
- if (rowid > 0 )
1166
- {
1167
+
1168
+ if (rowid > 0 ) {
1167
1169
// /如果rowid 已经存在就不修改
1168
- NSString * rowidWhere = [NSString stringWithFormat: @" rowid=%d " ,rowid];
1170
+ NSString * rowidWhere = [NSString stringWithFormat: @" rowid=%d " , rowid];
1169
1171
NSInteger rowCount = [self rowCountWithTableName: db_tableName where: rowidWhere];
1170
- if (rowCount > 0 )
1171
- {
1172
+
1173
+ if (rowCount > 0 ) {
1172
1174
continue ;
1173
1175
}
1174
- }
1175
- else
1176
- {
1176
+ } else {
1177
1177
continue ;
1178
1178
}
1179
1179
}
0 commit comments