Skip to content

Commit 69f9273

Browse files
authored
Merge pull request #130 from microsoft/shueybubbles/128
fix SQL_VARIANT type handling
2 parents 82dffe0 + 9064434 commit 69f9273

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pkg/sqlcmd/format.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,14 @@ func calcColumnDetails(cols []*sql.ColumnType, fixed int64, variable int64) ([]c
402402
} else {
403403
columnDetails[i].displayWidth = variable
404404
}
405+
case "SQL_VARIANT":
406+
if fixed > 0 {
407+
columnDetails[i].displayWidth = min64(fixed, 8000)
408+
} else {
409+
columnDetails[i].displayWidth = 8000
410+
}
405411
// Fixed length types
406-
case "CHAR", "NCHAR", "VARIANT":
412+
case "CHAR", "NCHAR":
407413
if fixed > 0 {
408414
length = min64(fixed, length)
409415
}

pkg/sqlcmd/sqlcmd_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,16 @@ func TestDateTimeFormats(t *testing.T) {
452452
}
453453
}
454454

455+
func TestQueryServerPropertyReturnsColumnName(t *testing.T) {
456+
s, buf := setupSqlCmdWithMemoryOutput(t)
457+
s.vars.Set(SQLCMDMAXVARTYPEWIDTH, "100")
458+
defer buf.Close()
459+
err := runSqlCmd(t, s, []string{"select SERVERPROPERTY('EngineEdition') AS DatabaseEngineEdition", "GO"})
460+
if assert.NoError(t, err, "select should succeed") {
461+
assert.Contains(t, buf.buf.String(), "DatabaseEngineEdition", "Column name missing from output")
462+
}
463+
}
464+
455465
// runSqlCmd uses lines as input for sqlcmd instead of relying on file or console input
456466
func runSqlCmd(t testing.TB, s *Sqlcmd, lines []string) error {
457467
t.Helper()

0 commit comments

Comments
 (0)