Skip to content

Commit 6cda646

Browse files
elianddbclaude
andcommitted
Remove unnecessary modularization from auto-increment overflow fix
Inlined bounds checking logic directly where used instead of helper function: - Removed canIncrementAutoIncVal() helper function from table.go - Inlined logic in table_editor.go Insert method (2 locations) - Inlined logic in table.go AddColumn method (1 location) - Used existing colType.Convert() pattern for type checking 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent a268496 commit 6cda646

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

memory/table.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,11 +1147,6 @@ func (t *Table) PeekNextAutoIncrementValue(ctx *sql.Context) (uint64, error) {
11471147
return data.autoIncVal, nil
11481148
}
11491149

1150-
func canIncrementAutoIncVal(ctx *sql.Context, colType sql.Type, currentVal uint64) bool {
1151-
nextVal := currentVal + 1
1152-
_, inRange, err := colType.Convert(ctx, nextVal)
1153-
return err == nil && inRange == sql.InRange
1154-
}
11551150

11561151
// GetNextAutoIncrementValue gets the next auto increment value for the memory table the increment.
11571152
func (t *Table) GetNextAutoIncrementValue(ctx *sql.Context, insertVal interface{}) (uint64, error) {
@@ -1262,7 +1257,8 @@ func addColumnToSchema(ctx *sql.Context, data *TableData, newCol *sql.Column, or
12621257
data.autoIncVal = 0
12631258
}
12641259

1265-
if canIncrementAutoIncVal(ctx, newCol.Type, data.autoIncVal) {
1260+
nextVal := data.autoIncVal + 1
1261+
if _, inRange, err := newCol.Type.Convert(ctx, nextVal); err == nil && inRange == sql.InRange {
12661262
data.autoIncVal++
12671263
}
12681264
}

memory/table_editor.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ func (t *tableEditor) Insert(ctx *sql.Context, row sql.Row) error {
191191
return err
192192
}
193193
t.ea.TableData().autoIncVal = v.(uint64)
194-
if canIncrementAutoIncVal(ctx, autoCol.Type, v.(uint64)) {
194+
nextVal := v.(uint64) + 1
195+
if _, inRange, err := autoCol.Type.Convert(ctx, nextVal); err == nil && inRange == sql.InRange {
195196
t.ea.TableData().autoIncVal++
196197
}
197198
} else if cmp == 0 {
198-
if canIncrementAutoIncVal(ctx, autoCol.Type, t.ea.TableData().autoIncVal) {
199+
nextVal := t.ea.TableData().autoIncVal + 1
200+
if _, inRange, err := autoCol.Type.Convert(ctx, nextVal); err == nil && inRange == sql.InRange {
199201
t.ea.TableData().autoIncVal++
200202
}
201203
}

0 commit comments

Comments
 (0)