This commit is contained in:
John Guo 2023-04-17 17:44:24 +08:00 committed by GitHub
parent 6fb26c44d7
commit 3991eb053c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,43 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package clickhouse
import (
"github.com/shopspring/decimal"
"testing"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/gconv"
)
func Test_Issue2584(t *testing.T) {
type TDecimal struct {
F1 *decimal.Decimal `json:"f1"`
}
gtest.C(t, func(t *gtest.T) {
var (
p1 = TDecimal{}
data1 = g.Map{"f1": gvar.New(1111.111)}
err = gconv.Scan(data1, &p1)
)
t.AssertNil(err)
t.Assert(p1.F1, 1111.111)
})
gtest.C(t, func(t *gtest.T) {
var (
p2 = TDecimal{}
data2 = g.Map{"f1": gvar.New("2222.222")}
err = gconv.Scan(data2, &p2)
)
t.AssertNil(err)
t.Assert(p2.F1, 2222.222)
})
}

View File

@ -422,6 +422,8 @@ func bindVarToReflectValueWithInterfaceCheck(reflectValue reflect.Value, value i
valueBytes = b
} else if s, ok := value.(string); ok {
valueBytes = []byte(s)
} else if f, ok := value.(iString); ok {
valueBytes = []byte(f.String())
}
if len(valueBytes) > 0 {
return v.UnmarshalText(valueBytes), ok
@ -434,6 +436,8 @@ func bindVarToReflectValueWithInterfaceCheck(reflectValue reflect.Value, value i
valueBytes = b
} else if s, ok := value.(string); ok {
valueBytes = []byte(s)
} else if f, ok := value.(iString); ok {
valueBytes = []byte(f.String())
}
if len(valueBytes) > 0 {