Skip to content

Commit 38614e0

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 580ca59 commit 38614e0

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

memory/table.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,12 +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-
}
1155-
11561150
// GetNextAutoIncrementValue gets the next auto increment value for the memory table the increment.
11571151
func (t *Table) GetNextAutoIncrementValue(ctx *sql.Context, insertVal interface{}) (uint64, error) {
11581152
data := t.sessionTableData(ctx)
@@ -1262,7 +1256,8 @@ func addColumnToSchema(ctx *sql.Context, data *TableData, newCol *sql.Column, or
12621256
data.autoIncVal = 0
12631257
}
12641258

1265-
if canIncrementAutoIncVal(ctx, newCol.Type, data.autoIncVal) {
1259+
nextVal := data.autoIncVal + 1
1260+
if _, inRange, err := newCol.Type.Convert(ctx, nextVal); err == nil && inRange == sql.InRange {
12661261
data.autoIncVal++
12671262
}
12681263
}

memory/table_editor.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ func (t *tableEditor) Insert(ctx *sql.Context, row sql.Row) error {
193193
return err
194194
}
195195
t.ea.TableData().autoIncVal = v.(uint64)
196-
if canIncrementAutoIncVal(ctx, autoCol.Type, v.(uint64)) {
196+
nextVal := v.(uint64) + 1
197+
if _, inRange, err := autoCol.Type.Convert(ctx, nextVal); err == nil && inRange == sql.InRange {
197198
t.ea.TableData().autoIncVal++
198199
}
199200
} else if cmp == 0 {
200-
if canIncrementAutoIncVal(ctx, autoCol.Type, t.ea.TableData().autoIncVal) {
201+
nextVal := t.ea.TableData().autoIncVal + 1
202+
if _, inRange, err := autoCol.Type.Convert(ctx, nextVal); err == nil && inRange == sql.InRange {
201203
t.ea.TableData().autoIncVal++
202204
}
203205
}

0 commit comments

Comments
 (0)