Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed the condition to use the default value #409

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions table_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ func (t *TableMap) bindInsert(elem reflect.Value) (bindInstance, error) {
plan.autoIncrIdx = y
plan.autoIncrFieldName = col.fieldName
} else {
if col.DefaultValue == "" {
val := elem.FieldByName(col.fieldName).Interface()
var isZeroValue bool
if val != nil {
isZeroValue = reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface())
}
if (val == nil || isZeroValue) && col.DefaultValue != "" {
s2.WriteString(col.DefaultValue)
} else {
s2.WriteString(t.dbmap.Dialect.BindVar(x))
if col == t.version {
plan.versField = col.fieldName
Expand All @@ -136,8 +143,6 @@ func (t *TableMap) bindInsert(elem reflect.Value) (bindInstance, error) {
plan.argFields = append(plan.argFields, col.fieldName)
}
x++
} else {
s2.WriteString(col.DefaultValue)
}
}
first = false
Expand Down