Skip to content

Commit

Permalink
fix: support uint query params (#190)
Browse files Browse the repository at this point in the history
* fix: support uint query params

The driver did accept query parameters of type `uint`, but the
underlying Spanner client would not accept these. `uint` query
parameters therefore first need to be converted to `int64` and then sent
to the Spanner client.

* chore: fix imports
  • Loading branch information
olavloite committed Feb 5, 2024
1 parent d4373ed commit e3e2a9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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

0 comments on commit e3e2a9a

Please sign in to comment.