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
|
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"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"xorm.io/xorm/internal/utils"
|
"xorm.io/xorm/internal/utils"
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
|
@ -549,11 +550,18 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
||||||
} else if col.IsVersion && session.statement.CheckVersion {
|
} else if col.IsVersion && session.statement.CheckVersion {
|
||||||
args = append(args, 1)
|
args = append(args, 1)
|
||||||
} else {
|
} else {
|
||||||
arg, err := session.statement.Value2Interface(col, fieldValue)
|
fieldType := fieldValue.Type()
|
||||||
if err != nil {
|
if fieldType.ConvertibleTo(schemas.TimeType) && session.engine.dialect.URI().DBType == schemas.ORACLE {
|
||||||
return colNames, args, err
|
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 {
|
||||||
|
return colNames, args, err
|
||||||
|
}
|
||||||
|
args = append(args, arg)
|
||||||
}
|
}
|
||||||
args = append(args, arg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
colNames = append(colNames, col.Name)
|
colNames = append(colNames, col.Name)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
"xorm.io/xorm/caches"
|
"xorm.io/xorm/caches"
|
||||||
|
@ -519,11 +520,18 @@ func (session *Session) genUpdateColumns(bean interface{}) ([]string, []interfac
|
||||||
} else if col.IsVersion && session.statement.CheckVersion {
|
} else if col.IsVersion && session.statement.CheckVersion {
|
||||||
args = append(args, 1)
|
args = append(args, 1)
|
||||||
} else {
|
} else {
|
||||||
arg, err := session.statement.Value2Interface(col, fieldValue)
|
fieldType := fieldValue.Type()
|
||||||
if err != nil {
|
if fieldType.ConvertibleTo(schemas.TimeType) && session.engine.dialect.URI().DBType == schemas.ORACLE {
|
||||||
return colNames, args, err
|
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 {
|
||||||
|
return colNames, args, err
|
||||||
|
}
|
||||||
|
args = append(args, arg)
|
||||||
}
|
}
|
||||||
args = append(args, arg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
colNames = append(colNames, session.engine.Quote(col.Name)+" = ?")
|
colNames = append(colNames, session.engine.Quote(col.Name)+" = ?")
|
||||||
|
|
Loading…
Reference in New Issue