[v11.0.x] MSSQL: Add SQL_VARIANT converter and update test (#86469)

MSSQL: Add `SQL_VARIANT` converter and update test (#85823)

Add SQL_VARIANT converter and update test

(cherry picked from commit 420067a7e1)

Co-authored-by: Andreas Christou <andreas.christou@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-04-19 21:00:59 +01:00
committed by GitHub
co-authored by Andreas Christou
parent 8903bf3b01
commit 39ce4774f7
2 changed files with 18 additions and 1 deletions
+15
View File
@@ -403,5 +403,20 @@ func (t *mssqlQueryResultTransformer) GetConverterList() []sqlutil.StringConvert
},
},
},
{
Name: "handle SQL_VARIANT",
InputScanKind: reflect.Pointer,
InputTypeName: "SQL_VARIANT",
ConversionFunc: func(in *string) (*string, error) { return in, nil },
Replacer: &sqlutil.StringFieldReplacer{
OutputFieldType: data.FieldTypeNullableString,
ReplaceFunc: func(in *string) (any, error) {
if in == nil {
return nil, nil
}
return in, nil
},
},
},
}
}
+3 -1
View File
@@ -92,6 +92,7 @@ func TestMSSQL(t *testing.T) {
c_datetimeoffset datetimeoffset,
c_uuid uniqueidentifier
c_sql_variant sql_variant
)
`
@@ -114,7 +115,7 @@ func TestMSSQL(t *testing.T) {
'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'),
CONVERT(uniqueidentifier, '%s')
CONVERT(uniqueidentifier, '%s'), 'test-sql-variant'
`, d, d2, d, d, d, d2, uuid)
_, err = db.Exec(sql)
@@ -170,6 +171,7 @@ func TestMSSQL(t *testing.T) {
require.Equal(t, dt2.In(time.FixedZone("UTC-7", int(-7*60*60))).Unix(), (*frames[0].Fields[22].At(0).(*time.Time)).Unix())
require.Equal(t, uuid, *frames[0].Fields[23].At(0).(*string))
require.Equal(t, "test-sql-variant", *frames[0].Fields[24].At(0).(*string))
})
})