@@ -193,11 +193,9 @@ func (t *tableEditor) Insert(ctx *sql.Context, row sql.Row) error {
193193 if err != nil {
194194 return err
195195 }
196- currentAutoIncVal := insertedVal .(uint64 )
197- t .ea .TableData ().autoIncVal = t .updateAutoIncrementValue (ctx , autoCol , currentAutoIncVal )
196+ t .updateAutoIncrementValue (ctx , autoCol , insertedVal .(uint64 ))
198197 } 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 )
201199 }
202200 }
203201
@@ -893,19 +891,19 @@ func verifyRowTypes(row sql.Row, schema sql.Schema) error {
893891
894892// updateAutoIncrementValue safely increments the auto_increment value, handling overflow
895893// 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 ) {
898895 // Check for arithmetic overflow before adding 1
899896 if currentVal == math .MaxUint64 {
900897 // At maximum uint64 value, can't increment further
901- return currentVal
898+ t .ea .TableData ().autoIncVal = currentVal
899+ return
902900 }
903901
904902 nextVal := currentVal + 1
905903 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
907908 }
908-
909- // If next value would be out of range for the column type, stay at current value
910- return currentVal
911909}
0 commit comments