Compare commits
1 Commits
v0.11.1
...
637797116d
| Author | SHA1 | Date | |
|---|---|---|---|
| 637797116d |
6
query.go
6
query.go
@@ -44,17 +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()
|
||||
arg = v.Elem().Interface() // Dereference the pointer
|
||||
}
|
||||
if asString, ok := arg.(string); ok {
|
||||
q.stmt.BindText(*into, asString)
|
||||
|
||||
@@ -94,14 +94,9 @@ func TestUpdateQuery(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateQueryWithWrongArguments(t *testing.T) {
|
||||
type S struct {
|
||||
Field string
|
||||
}
|
||||
db := openTestDb(t)
|
||||
abc := S{
|
||||
Field: "ipsum",
|
||||
}
|
||||
err := db.Query("insert into mytable(key, value) values ('lorem', ?)").Bind(abc).Exec()
|
||||
value := "ipsum"
|
||||
err := db.Query("insert into mytable(key, value) values ('lorem', ?)").Bind(&value).Exec()
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
@@ -122,26 +117,6 @@ 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() {
|
||||
@@ -153,7 +128,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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user