@@ -193,11 +193,9 @@ func (t *tableEditor) Insert(ctx *sql.Context, row sql.Row) error {
193
193
if err != nil {
194
194
return err
195
195
}
196
- currentAutoIncVal := insertedVal .(uint64 )
197
- t .ea .TableData ().autoIncVal = t .updateAutoIncrementValue (ctx , autoCol , currentAutoIncVal )
196
+ t .updateAutoIncrementValue (ctx , autoCol , insertedVal .(uint64 ))
198
197
} else if cmp == 0 {
199
- currentAutoIncVal := t .ea .TableData ().autoIncVal
200
- t .ea .TableData ().autoIncVal = t .updateAutoIncrementValue (ctx , autoCol , currentAutoIncVal )
198
+ t .updateAutoIncrementValue (ctx , autoCol , t .ea .TableData ().autoIncVal )
201
199
}
202
200
}
203
201
@@ -893,19 +891,19 @@ func verifyRowTypes(row sql.Row, schema sql.Schema) error {
893
891
894
892
// updateAutoIncrementValue safely increments the auto_increment value, handling overflow
895
893
// by ensuring it doesn't exceed the column type's maximum value or wrap around.
896
- // It returns the next valid auto_increment value for the given column type.
897
- func (t * tableEditor ) updateAutoIncrementValue (ctx * sql.Context , autoCol * sql.Column , currentVal uint64 ) uint64 {
894
+ func (t * tableEditor ) updateAutoIncrementValue (ctx * sql.Context , autoCol * sql.Column , currentVal uint64 ) {
898
895
// Check for arithmetic overflow before adding 1
899
896
if currentVal == math .MaxUint64 {
900
897
// At maximum uint64 value, can't increment further
901
- return currentVal
898
+ t .ea .TableData ().autoIncVal = currentVal
899
+ return
902
900
}
903
901
904
902
nextVal := currentVal + 1
905
903
if _ , inRange , err := autoCol .Type .Convert (ctx , nextVal ); err == nil && inRange == sql .InRange {
906
- return nextVal
904
+ t .ea .TableData ().autoIncVal = nextVal
905
+ } else {
906
+ // If next value would be out of range for the column type, stay at current value
907
+ t .ea .TableData ().autoIncVal = currentVal
907
908
}
908
-
909
- // If next value would be out of range for the column type, stay at current value
910
- return currentVal
911
909
}
0 commit comments