Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support uint query params #190

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion driver_with_mockserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func TestQueryWithAllTypes(t *testing.T) {
true,
"test",
[]byte("testbytes"),
int64(5),
uint(5),
3.14,
numeric("6.626"),
civil.Date{Year: 2021, Month: 7, Day: 21},
Expand Down
28 changes: 27 additions & 1 deletion stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,37 @@ func prepareSpannerStmt(q string, args []driver.NamedValue) (spanner.Statement,
if name == "" {
name = names[i]
}
ss.Params[name] = v.Value
ss.Params[name] = convertParam(v.Value)
}
return ss, nil
}

func convertParam(v driver.Value) driver.Value {
switch v.(type) {
default:
return v
case uint:
return int64(v.(uint))
case []uint:
vu := v.([]uint)
res := make([]int64, len(vu))
for i, val := range vu {
res[i] = int64(val)
}
return res
case *uint:
vi := int64(*v.(*uint))
return &vi
case *[]uint:
vu := v.(*[]uint)
res := make([]int64, len(*vu))
for i, val := range *vu {
res[i] = int64(val)
}
return &res
}
}

type result struct {
rowsAffected int64
}
Expand Down
Loading