Fix yet another pointer
All checks were successful
Build / build (push) Successful in 41s

This commit is contained in:
Sebastiaan de Schaetzen 2025-05-09 10:54:42 +02:00
parent 029cf6ce01
commit 7daf1915a5
2 changed files with 24 additions and 0 deletions

View File

@ -50,6 +50,10 @@ func (q *Query) bindInto(into *int, args ...any) *Query {
}
v := reflect.ValueOf(arg)
if v.Kind() == reflect.Ptr {
if v.IsNil() {
q.stmt.BindNull(*into)
continue
}
arg = v.Elem().Interface()
}
if asString, ok := arg.(string); ok {

View File

@ -122,6 +122,26 @@ func TestUpdateQueryWithPointerValue(t *testing.T) {
require.Equal(t, "ipsum", value)
}
func TestUpdateQueryWithSetPointerValue(t *testing.T) {
type S struct {
value *string
}
db := openTestDb(t)
func() {
tx := db.MustBegin()
defer tx.MustRollback()
tx.Query("insert into mytable(key, value) values ('lorem', 'bar')").MustExec()
s := S{nil}
key := "lorem"
tx.Query("update mytable set value = ? where key = ?").Bind(s.value, key).MustExec()
tx.MustCommit()
}()
var value *string
db.Query("select value from mytable where key = 'lorem'").MustScanSingle(&value)
require.Equal(t, (*string)(nil), value)
}
func TestUpdateQueryWithNullValue(t *testing.T) {
db := openTestDb(t)
func() {