This commit is contained in:
parent
029cf6ce01
commit
7daf1915a5
4
query.go
4
query.go
@ -50,6 +50,10 @@ func (q *Query) bindInto(into *int, args ...any) *Query {
|
|||||||
}
|
}
|
||||||
v := reflect.ValueOf(arg)
|
v := reflect.ValueOf(arg)
|
||||||
if v.Kind() == reflect.Ptr {
|
if v.Kind() == reflect.Ptr {
|
||||||
|
if v.IsNil() {
|
||||||
|
q.stmt.BindNull(*into)
|
||||||
|
continue
|
||||||
|
}
|
||||||
arg = v.Elem().Interface()
|
arg = v.Elem().Interface()
|
||||||
}
|
}
|
||||||
if asString, ok := arg.(string); ok {
|
if asString, ok := arg.(string); ok {
|
||||||
|
@ -122,6 +122,26 @@ func TestUpdateQueryWithPointerValue(t *testing.T) {
|
|||||||
require.Equal(t, "ipsum", value)
|
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) {
|
func TestUpdateQueryWithNullValue(t *testing.T) {
|
||||||
db := openTestDb(t)
|
db := openTestDb(t)
|
||||||
func() {
|
func() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user