mirror of
https://github.com/grafana/grafana.git
synced 2025-01-24 23:37:01 -06:00
MSSQL: Fix parsing of uniqueidentifier type (#25751)
Closes #17084 Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
parent
4422ba0f2d
commit
c22940fe35
@ -10,7 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
mssql "github.com/denisenkom/go-mssqldb"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/tsdb"
|
||||
@ -130,6 +130,13 @@ func (t *mssqlQueryResultTransformer) TransformQueryResult(columnTypes []*sql.Co
|
||||
} else {
|
||||
t.log.Debug("Rows", "Error converting numeric to float", value)
|
||||
}
|
||||
case "UNIQUEIDENTIFIER":
|
||||
uuid := &mssql.UniqueIdentifier{}
|
||||
if err := uuid.Scan(value); err == nil {
|
||||
values[i] = uuid.String()
|
||||
} else {
|
||||
t.log.Debug("Rows", "Error converting uniqueidentifier to string", value)
|
||||
}
|
||||
default:
|
||||
t.log.Debug("Rows", "Unknown database type", columnTypes[i].DatabaseTypeName(), "value", value)
|
||||
values[i] = string(value)
|
||||
|
@ -90,7 +90,9 @@ func TestMSSQL(t *testing.T) {
|
||||
c_smalldatetime smalldatetime,
|
||||
c_date date,
|
||||
c_time time,
|
||||
c_datetimeoffset datetimeoffset
|
||||
c_datetimeoffset datetimeoffset,
|
||||
|
||||
c_uuid uniqueidentifier
|
||||
)
|
||||
`
|
||||
|
||||
@ -103,6 +105,7 @@ func TestMSSQL(t *testing.T) {
|
||||
dt2 := time.Date(2018, 3, 14, 21, 20, 6, 8896406e2, time.UTC)
|
||||
dt2Format := "2006-01-02 15:04:05.999999999 -07:00"
|
||||
d2 := dt2.Format(dt2Format)
|
||||
uuid := "B33D42A3-AC5A-4D4C-81DD-72F3D5C49025"
|
||||
|
||||
sql = fmt.Sprintf(`
|
||||
INSERT INTO [mssql_types]
|
||||
@ -111,8 +114,9 @@ func TestMSSQL(t *testing.T) {
|
||||
1.11, 2.22, 3.33,
|
||||
'char10', 'varchar10', 'text',
|
||||
N'☺nchar12☺', N'☺nvarchar12☺', N'☺text☺',
|
||||
CAST('%s' AS DATETIME), CAST('%s' AS DATETIME2), CAST('%s' AS SMALLDATETIME), CAST('%s' AS DATE), CAST('%s' AS TIME), SWITCHOFFSET(CAST('%s' AS DATETIMEOFFSET), '-07:00')
|
||||
`, d, d2, d, d, d, d2)
|
||||
CAST('%s' AS DATETIME), CAST('%s' AS DATETIME2), CAST('%s' AS SMALLDATETIME), CAST('%s' AS DATE), CAST('%s' AS TIME), SWITCHOFFSET(CAST('%s' AS DATETIMEOFFSET), '-07:00'),
|
||||
CONVERT(uniqueidentifier, '%s')
|
||||
`, d, d2, d, d, d, d2, uuid)
|
||||
|
||||
_, err = sess.Exec(sql)
|
||||
So(err, ShouldBeNil)
|
||||
@ -164,6 +168,8 @@ func TestMSSQL(t *testing.T) {
|
||||
So(column[20].(time.Time), ShouldEqual, dt.Truncate(24*time.Hour))
|
||||
So(column[21].(time.Time), ShouldEqual, time.Date(1, 1, 1, dt.Hour(), dt.Minute(), dt.Second(), dt.Nanosecond(), time.UTC))
|
||||
So(column[22].(time.Time), ShouldEqual, dt2.In(time.FixedZone("UTC-7", int(-7*60*60))))
|
||||
|
||||
So(column[23].(string), ShouldEqual, uuid)
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user