File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -1266,18 +1266,25 @@ public int Insert(object obj, string? modifier = null) {
1266
1266
}
1267
1267
}
1268
1268
1269
- object ? [ ] values = new object [ map . Columns . Length ] ;
1269
+ TableMapping . Column [ ] columns = map . Columns ;
1270
+
1271
+ // Don't insert auto-incremented columns (unless "OR REPLACE"/"OR IGNORE")
1272
+ if ( string . IsNullOrEmpty ( modifier ) ) {
1273
+ columns = [ .. columns . Where ( column => ! column . AutoIncrement ) ] ;
1274
+ }
1275
+
1276
+ object ? [ ] values = new object [ columns . Length ] ;
1270
1277
for ( int i = 0 ; i < values . Length ; i ++ ) {
1271
- values [ i ] = map . Columns [ i ] . GetValue ( obj ) ;
1278
+ values [ i ] = columns [ i ] . GetValue ( obj ) ;
1272
1279
}
1273
1280
1274
1281
string query ;
1275
- if ( map . Columns . Length == 0 ) {
1282
+ if ( columns . Length == 0 ) {
1276
1283
query = $ "insert { modifier } into \" { map . TableName } \" default values";
1277
1284
}
1278
1285
else {
1279
- string columnsSql = string . Join ( "," , map . Columns . Select ( column => "\" " + column . Name + "\" " ) ) ;
1280
- string valuesSql = string . Join ( "," , map . Columns . Select ( column => "?" ) ) ;
1286
+ string columnsSql = string . Join ( "," , columns . Select ( column => "\" " + column . Name + "\" " ) ) ;
1287
+ string valuesSql = string . Join ( "," , columns . Select ( column => "?" ) ) ;
1281
1288
query = $ "insert { modifier } into \" { map . TableName } \" ({ columnsSql } ) values ({ valuesSql } )";
1282
1289
}
1283
1290
You can’t perform that action at this time.
0 commit comments