@@ -619,7 +619,8 @@ -(BOOL)getTableCreatedWithTableName:(NSString *)tableName
619
619
620
620
@implementation LKDBHelper (DatabaseExecute)
621
621
622
- -(id )modelValueWithProperty : (LKDBProperty *)property model : (NSObject *)model {
622
+ -(id )modelValueWithProperty : (LKDBProperty *)property model : (NSObject *)model
623
+ {
623
624
id value = nil ;
624
625
if (property.isUserCalculate )
625
626
{
@@ -1016,9 +1017,7 @@ -(BOOL)insertBase:(NSObject*)model{
1016
1017
NSMutableString * insertValuesString = [NSMutableString stringWithCapacity: 0 ];
1017
1018
NSMutableArray * insertValues = [NSMutableArray arrayWithCapacity: infos.count];
1018
1019
1019
-
1020
1020
LKDBProperty* primaryProperty = [model singlePrimaryKeyProperty ];
1021
-
1022
1021
for (NSInteger i=0 ; i<infos.count ; i++)
1023
1022
{
1024
1023
LKDBProperty* property = [infos objectWithIndex: i];
@@ -1035,6 +1034,13 @@ -(BOOL)insertBase:(NSObject*)model{
1035
1034
}
1036
1035
}
1037
1036
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
+
1038
1044
if (insertKey.length >0 )
1039
1045
{
1040
1046
[insertKey appendString: @" ," ];
@@ -1044,8 +1050,6 @@ -(BOOL)insertBase:(NSObject*)model{
1044
1050
[insertKey appendString: property.sqlColumnName];
1045
1051
[insertValuesString appendString: @" ?" ];
1046
1052
1047
- id value = [self modelValueWithProperty: property model: model];
1048
-
1049
1053
[insertValues addObject: value];
1050
1054
}
1051
1055
@@ -1116,12 +1120,23 @@ -(BOOL)updateToDBBase:(NSObject *)model where:(id)where
1116
1120
1117
1121
LKDBProperty* property = [infos objectWithIndex: i];
1118
1122
1119
- if (i> 0 )
1120
- [updateKey appendString: @" , " ];
1121
-
1122
- [updateKey appendFormat: @" %@ =? " ,property.sqlColumnName];
1123
+ if ([LKDBUtils checkStringIsEmpty: property.sqlColumnName] )
1124
+ {
1125
+ continue ;
1126
+ }
1123
1127
1124
1128
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];
1125
1140
1126
1141
[updateValues addObject: value];
1127
1142
}
0 commit comments