@@ -16,7 +16,6 @@ package memory
1616
1717import (
1818 "fmt"
19- "math"
2019 "reflect"
2120 "strings"
2221
@@ -193,9 +192,10 @@ func (t *tableEditor) Insert(ctx *sql.Context, row sql.Row) error {
193192 if err != nil {
194193 return err
195194 }
196- t .updateAutoIncrementValue (ctx , autoCol , insertedVal .(uint64 ))
195+ t .ea .TableData ().autoIncVal = insertedVal .(uint64 )
196+ updateAutoIncrementSafe (ctx , autoCol , & t .ea .TableData ().autoIncVal )
197197 } else if cmp == 0 {
198- t . updateAutoIncrementValue (ctx , autoCol , t .ea .TableData ().autoIncVal )
198+ updateAutoIncrementSafe (ctx , autoCol , & t .ea .TableData ().autoIncVal )
199199 }
200200 }
201201
@@ -888,22 +888,3 @@ func verifyRowTypes(row sql.Row, schema sql.Schema) error {
888888 }
889889 return nil
890890}
891-
892- // updateAutoIncrementValue safely increments the auto_increment value, handling overflow
893- // by ensuring it doesn't exceed the column type's maximum value or wrap around.
894- func (t * tableEditor ) updateAutoIncrementValue (ctx * sql.Context , autoCol * sql.Column , currentVal uint64 ) {
895- // Check for arithmetic overflow before adding 1
896- if currentVal == math .MaxUint64 {
897- // At maximum uint64 value, can't increment further
898- t .ea .TableData ().autoIncVal = currentVal
899- return
900- }
901-
902- nextVal := currentVal + 1
903- if _ , inRange , err := autoCol .Type .Convert (ctx , nextVal ); err == nil && inRange == sql .InRange {
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
908- }
909- }
0 commit comments