Fix queryinterface (#2562)

Fix #2543

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2562
This commit is contained in:
Lunny Xiao
2026-02-08 18:08:13 +00:00
parent cb78962e01
commit cda399819b
3 changed files with 8 additions and 4 deletions
+2 -2
View File
@@ -43,9 +43,9 @@ func Interface2Interface(userLocation *time.Location, v any) (any, error) {
return nil, nil
case *sql.NullTime:
if vv.Valid {
return vv.Time.In(userLocation).Format("2006-01-02 15:04:05"), nil
return vv.Time.In(userLocation), nil
}
return "", nil
return nil, nil
default:
return "", fmt.Errorf("convert assign string unsupported type: %#v", vv)
}
+3 -2
View File
@@ -722,10 +722,11 @@ func (p *odbcDriver) Parse(driverName, dataSourceName string) (*URI, error) {
func (p *odbcDriver) GenScanResult(colType string) (any, error) {
switch colType {
case "VARCHAR", "TEXT", "CHAR", "NVARCHAR", "NCHAR", "NTEXT":
fallthrough
case "DATE", "DATETIME", "DATETIME2", "TIME":
var s sql.NullString
return &s, nil
case "DATE", "DATETIME", "DATETIME2", "TIME":
var s sql.NullTime
return &s, nil
case "FLOAT", "REAL":
var s sql.NullFloat64
return &s, nil
+3
View File
@@ -111,6 +111,9 @@ func TestQueryInterface(t *testing.T) {
assert.Equal(t, "hi", records[0]["msg"])
assert.EqualValues(t, 28, records[0]["age"])
assert.EqualValues(t, 1.5, records[0]["money"])
createdAt, ok := records[0]["created"].(time.Time)
assert.True(t, ok)
assert.False(t, createdAt.IsZero())
}
func TestQueryNoParams(t *testing.T) {