Skip to content

Commit c952165

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

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

LKDBHelper/Helper/LKDBHelper.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ - (void)dropAllTable
456456
NSString *dropTable = [NSString stringWithFormat:@"drop table %@", tableName];
457457
[db executeUpdate:dropTable];
458458
}
459+
460+
[self.createdTableNames removeAllObjects];
459461
}];
460-
461-
[_createdTableNames removeAllObjects];
462462
}
463463

464464
- (BOOL)dropTableWithClass:(Class)modelClass
@@ -474,7 +474,9 @@ - (BOOL)dropTableWithTableName:(NSString *)tableName
474474

475475
BOOL isDrop = [self executeSQL:dropTable arguments:nil];
476476

477+
[_threadLock lock];
477478
[_createdTableNames removeObject:tableName];
479+
[_threadLock unlock];
478480

479481
return isDrop;
480482
}
@@ -540,10 +542,13 @@ - (void)fixSqlColumnsWithClass:(Class)clazz tableName:(NSString *)tableName
540542
- (BOOL)_createTableWithModelClass:(Class)modelClass tableName:(NSString *)tableName
541543
{
542544
if ([self getTableCreatedWithTableName:tableName]) {
545+
543546
// 已创建表 就跳过
547+
[_threadLock lock];
544548
if ([_createdTableNames containsObject:tableName] == NO) {
545549
[_createdTableNames addObject:tableName];
546550
}
551+
[_threadLock unlock];
547552

548553
[self fixSqlColumnsWithClass:modelClass tableName:tableName];
549554
return YES;
@@ -634,10 +639,12 @@ - (BOOL)_createTableWithModelClass:(Class)modelClass tableName:(NSString *)table
634639

635640
BOOL isCreated = [self executeSQL:createTableSQL arguments:nil];
636641

642+
[_threadLock lock];
637643
if (isCreated) {
638644
[_createdTableNames addObject:tableName];
639645
[modelClass dbDidCreateTable:self tableName:tableName];
640646
}
647+
[_threadLock unlock];
641648

642649
return isCreated;
643650
}
@@ -1042,9 +1049,11 @@ - (BOOL)insertBase:(NSObject *)model
10421049
NSString *db_tableName = model.db_tableName ? :[modelClass getTableName];
10431050

10441051
// 检测是否创建过表
1052+
[_threadLock lock];
10451053
if ([_createdTableNames containsObject:db_tableName] == NO) {
10461054
[self _createTableWithModelClass:modelClass tableName:db_tableName];
10471055
}
1056+
[_threadLock unlock];
10481057

10491058
// --
10501059
LKModelInfos *infos = [modelClass getModelInfos];
@@ -1143,9 +1152,11 @@ - (BOOL)updateToDBBase:(NSObject *)model where:(id)where
11431152
NSString *db_tableName = model.db_tableName ? :[modelClass getTableName];
11441153

11451154
// 检测是否创建过表
1155+
[_threadLock lock];
11461156
if ([_createdTableNames containsObject:db_tableName] == NO) {
11471157
[self _createTableWithModelClass:modelClass tableName:db_tableName];
11481158
}
1159+
[_threadLock unlock];
11491160

11501161
LKModelInfos *infos = [modelClass getModelInfos];
11511162

0 commit comments

Comments
 (0)