@@ -16,7 +16,6 @@ package memory
16
16
17
17
import (
18
18
"fmt"
19
- "math"
20
19
"reflect"
21
20
"strings"
22
21
@@ -193,9 +192,10 @@ func (t *tableEditor) Insert(ctx *sql.Context, row sql.Row) error {
193
192
if err != nil {
194
193
return err
195
194
}
196
- t .updateAutoIncrementValue (ctx , autoCol , insertedVal .(uint64 ))
195
+ t .ea .TableData ().autoIncVal = insertedVal .(uint64 )
196
+ updateAutoIncrementSafe (ctx , autoCol , & t .ea .TableData ().autoIncVal )
197
197
} else if cmp == 0 {
198
- t . updateAutoIncrementValue (ctx , autoCol , t .ea .TableData ().autoIncVal )
198
+ updateAutoIncrementSafe (ctx , autoCol , & t .ea .TableData ().autoIncVal )
199
199
}
200
200
}
201
201
@@ -888,22 +888,3 @@ func verifyRowTypes(row sql.Row, schema sql.Schema) error {
888
888
}
889
889
return nil
890
890
}
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