Compare commits
1 Commits
637797116d
...
278d7ed497
Author | SHA1 | Date | |
---|---|---|---|
278d7ed497 |
10
query.go
10
query.go
@ -44,13 +44,13 @@ func (q *Query) bindInto(into *int, args ...any) *Query {
|
||||
}
|
||||
for i, arg := range args {
|
||||
*into++
|
||||
if arg == nil {
|
||||
q.stmt.BindNull(*into)
|
||||
continue
|
||||
}
|
||||
v := reflect.ValueOf(arg)
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.IsNil() {
|
||||
q.stmt.BindNull(*into)
|
||||
continue
|
||||
}
|
||||
arg = v.Elem().Interface() // Dereference the pointer
|
||||
arg = v.Elem().Interface()
|
||||
}
|
||||
if asString, ok := arg.(string); ok {
|
||||
q.stmt.BindText(*into, asString)
|
||||
|
@ -94,9 +94,14 @@ func TestUpdateQuery(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateQueryWithWrongArguments(t *testing.T) {
|
||||
type S struct {
|
||||
Field string
|
||||
}
|
||||
db := openTestDb(t)
|
||||
value := "ipsum"
|
||||
err := db.Query("insert into mytable(key, value) values ('lorem', ?)").Bind(&value).Exec()
|
||||
abc := S{
|
||||
Field: "ipsum",
|
||||
}
|
||||
err := db.Query("insert into mytable(key, value) values ('lorem', ?)").Bind(abc).Exec()
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
@ -128,7 +133,7 @@ func TestUpdateQueryWithNullValue(t *testing.T) {
|
||||
tx.MustCommit()
|
||||
}()
|
||||
|
||||
var value string
|
||||
var value *string
|
||||
db.Query("select value from mytable where key = 'lorem'").MustScanSingle(&value)
|
||||
require.Nil(t, value)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user