Skip to content

Commit 6384646

Browse files
committed
当 rowid == 0 时不加入到 replace 或者 update 语句当中
1 parent 7ece68d commit 6384646

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

LKDBHelper/Helper/LKDBHelper.m

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ -(BOOL)getTableCreatedWithTableName:(NSString *)tableName
619619

620620
@implementation LKDBHelper(DatabaseExecute)
621621

622-
-(id)modelValueWithProperty:(LKDBProperty *)property model:(NSObject *)model {
622+
-(id)modelValueWithProperty:(LKDBProperty *)property model:(NSObject *)model
623+
{
623624
id value = nil;
624625
if(property.isUserCalculate)
625626
{
@@ -1016,9 +1017,7 @@ -(BOOL)insertBase:(NSObject*)model{
10161017
NSMutableString* insertValuesString = [NSMutableString stringWithCapacity:0];
10171018
NSMutableArray* insertValues = [NSMutableArray arrayWithCapacity:infos.count];
10181019

1019-
10201020
LKDBProperty* primaryProperty = [model singlePrimaryKeyProperty];
1021-
10221021
for (NSInteger i=0; i<infos.count; i++)
10231022
{
10241023
LKDBProperty* property = [infos objectWithIndex:i];
@@ -1035,6 +1034,13 @@ -(BOOL)insertBase:(NSObject*)model{
10351034
}
10361035
}
10371036

1037+
id value = [self modelValueWithProperty:property model:model];
1038+
///跳过 rowid = 0 的属性
1039+
if([property.sqlColumnName isEqualToString:@"rowid"] && [value intValue] == 0)
1040+
{
1041+
continue;
1042+
}
1043+
10381044
if(insertKey.length>0)
10391045
{
10401046
[insertKey appendString:@","];
@@ -1044,8 +1050,6 @@ -(BOOL)insertBase:(NSObject*)model{
10441050
[insertKey appendString:property.sqlColumnName];
10451051
[insertValuesString appendString:@"?"];
10461052

1047-
id value = [self modelValueWithProperty:property model:model];
1048-
10491053
[insertValues addObject:value];
10501054
}
10511055

@@ -1116,12 +1120,23 @@ -(BOOL)updateToDBBase:(NSObject *)model where:(id)where
11161120

11171121
LKDBProperty* property = [infos objectWithIndex:i];
11181122

1119-
if(i>0)
1120-
[updateKey appendString:@","];
1121-
1122-
[updateKey appendFormat:@"%@=?",property.sqlColumnName];
1123+
if([LKDBUtils checkStringIsEmpty:property.sqlColumnName])
1124+
{
1125+
continue;
1126+
}
11231127

11241128
id value = [self modelValueWithProperty:property model:model];
1129+
///跳过 rowid = 0 的属性
1130+
if([property.sqlColumnName isEqualToString:@"rowid"] && [value intValue] == 0)
1131+
{
1132+
continue;
1133+
}
1134+
1135+
if(updateKey.length > 0)
1136+
{
1137+
[updateKey appendString:@","];
1138+
}
1139+
[updateKey appendFormat:@"%@=?",property.sqlColumnName];
11251140

11261141
[updateValues addObject:value];
11271142
}

0 commit comments

Comments
 (0)