Fix call valuer interface when using nil value

This commit is contained in:
Jinzhu 2021-11-29 16:19:06 +08:00
parent 92d5a959a0
commit 45e804dd3f
2 changed files with 7 additions and 2 deletions

View File

@ -368,7 +368,7 @@ func (like Like) NegationBuild(builder Builder) {
} }
func eqNil(value interface{}) bool { func eqNil(value interface{}) bool {
if valuer, ok := value.(driver.Valuer); ok { if valuer, ok := value.(driver.Valuer); ok && !eqNilReflect(valuer) {
value, _ = valuer.Value() value, _ = valuer.Value()
} }

View File

@ -173,7 +173,12 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) {
case clause.Column, clause.Table: case clause.Column, clause.Table:
stmt.QuoteTo(writer, v) stmt.QuoteTo(writer, v)
case Valuer: case Valuer:
reflectValue := reflect.ValueOf(v)
if reflectValue.Kind() == reflect.Ptr && reflectValue.IsNil() {
stmt.AddVar(writer, nil)
} else {
stmt.AddVar(writer, v.GormValue(stmt.Context, stmt.DB)) stmt.AddVar(writer, v.GormValue(stmt.Context, stmt.DB))
}
case clause.Expr: case clause.Expr:
v.Build(stmt) v.Build(stmt)
case *clause.Expr: case *clause.Expr: