fix bug when update Time type for Oracle
This commit is contained in:
parent
1c620a905a
commit
aedf8032fb
|
@ -1342,3 +1342,12 @@ func (engine *Engine) Transaction(f func(*Session) (interface{}, error)) (interf
|
|||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// convertTime convert time
|
||||
func (engine *Engine) convertTime(col *schemas.Column, t time.Time) (interface{}, time.Time) {
|
||||
var tz = engine.DatabaseTZ
|
||||
if !col.DisableTimeZone && col.TimeZone != nil {
|
||||
tz = col.TimeZone
|
||||
}
|
||||
return dialects.FormatTime(engine.dialect, col.SQLType.Name, t.In(tz)), t.In(engine.TZLocation)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm/internal/utils"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
@ -548,6 +549,12 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
|||
})
|
||||
} else if col.IsVersion && session.statement.CheckVersion {
|
||||
args = append(args, 1)
|
||||
} else {
|
||||
fieldType := fieldValue.Type()
|
||||
if fieldType.ConvertibleTo(schemas.TimeType) && session.engine.dialect.URI().DBType == schemas.ORACLE {
|
||||
t := fieldValue.Convert(schemas.TimeType).Interface().(time.Time)
|
||||
_, t = session.engine.convertTime(col, t)
|
||||
args = append(args, t)
|
||||
} else {
|
||||
arg, err := session.statement.Value2Interface(col, fieldValue)
|
||||
if err != nil {
|
||||
|
@ -555,6 +562,7 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
|||
}
|
||||
args = append(args, arg)
|
||||
}
|
||||
}
|
||||
|
||||
colNames = append(colNames, col.Name)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm/caches"
|
||||
|
@ -518,6 +519,12 @@ func (session *Session) genUpdateColumns(bean interface{}) ([]string, []interfac
|
|||
})
|
||||
} else if col.IsVersion && session.statement.CheckVersion {
|
||||
args = append(args, 1)
|
||||
} else {
|
||||
fieldType := fieldValue.Type()
|
||||
if fieldType.ConvertibleTo(schemas.TimeType) && session.engine.dialect.URI().DBType == schemas.ORACLE {
|
||||
t := fieldValue.Convert(schemas.TimeType).Interface().(time.Time)
|
||||
_, t = session.engine.convertTime(col, t)
|
||||
args = append(args, t)
|
||||
} else {
|
||||
arg, err := session.statement.Value2Interface(col, fieldValue)
|
||||
if err != nil {
|
||||
|
@ -525,6 +532,7 @@ func (session *Session) genUpdateColumns(bean interface{}) ([]string, []interfac
|
|||
}
|
||||
args = append(args, arg)
|
||||
}
|
||||
}
|
||||
|
||||
colNames = append(colNames, session.engine.Quote(col.Name)+" = ?")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue