Skip to content

Commit b67812e

Browse files
committed
fix TableRow index bounds check to use record length instead of column map size
1 parent 71d5975 commit b67812e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/utils/tablerow.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ func (row TableRow) Int64(columnName string) (int64, error) {
5353
func (row TableRow) Value(columnName string) (any, error) {
5454
if index, ok := row.columns[columnName]; !ok {
5555
return nil, fmt.Errorf("table doesn't have a column named [%s]", columnName)
56-
} else if count := len(row.columns); count <= index {
56+
} else if count := len(row.record.Values); count <= index {
5757
return nil, fmt.Errorf("column named [%s] has index %d but row only has %d values", columnName, index, count)
5858
} else {
5959
return row.record.Values[index], nil
6060
}
6161
}
6262

6363
func (row TableRow) ValueOrFallback(columnName string, fallback any) any {
64-
if index, ok := row.columns[columnName]; ok && index < len(row.columns) {
64+
if index, ok := row.columns[columnName]; ok && index < len(row.record.Values) {
6565
return row.record.Values[index]
6666
}
6767
return fallback
@@ -71,7 +71,7 @@ func Value[T any](row TableRow, columnName string) (T, error) {
7171
var zero T
7272
if index, ok := row.columns[columnName]; !ok {
7373
return zero, fmt.Errorf("table doesn't have a column named [%s]", columnName)
74-
} else if count := len(row.columns); count <= index {
74+
} else if count := len(row.record.Values); count <= index {
7575
return zero, fmt.Errorf("column named [%s] has index %d but row only has %d values", columnName, index, count)
7676
} else if v, ok := row.record.Values[index].(T); !ok {
7777
return zero, fmt.Errorf("expected column [%s] to be type %T; got type %[3]T with value %[3]v", columnName, zero, row.record.Values[index])
@@ -82,7 +82,7 @@ func Value[T any](row TableRow, columnName string) (T, error) {
8282

8383
func ValueOrFallback[T any](row TableRow, columnName string, fallback T, tryConvert bool) (T, error) {
8484
index, ok := row.columns[columnName]
85-
if !ok || index >= len(row.columns) || index < 0 {
85+
if !ok || index >= len(row.record.Values) || index < 0 {
8686
return fallback, fmt.Errorf("expected column [%s] does not exist", columnName)
8787
}
8888
v := row.record.Values[index]

0 commit comments

Comments
 (0)