microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
323 stars 56 forks source link

Crash when use q and Q #525

Open endo64 opened 2 months ago

endo64 commented 2 months ago

sqlcmd crashes when use both q and Q command line arguments at the same time. Version v1.6.0 on Windows 10 (x64)

PS C:\Users\myuser> sqlcmd -S myserver -E -d mydb -q "SELECT 1" -Q "SELECT 2"

-----------
          1

(1 row affected)
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x28 pc=0x16b027b]

goroutine 1 [running]:
github.com/microsoft/go-sqlcmd/pkg/sqlcmd.(*Sqlcmd).scanNext(0xf7edbc?)
        D:/a/1/s/pkg/sqlcmd/sqlcmd.go:114 +0x1b
github.com/microsoft/go-sqlcmd/pkg/sqlcmd.(*Batch).Next(0xc0000b2200)
        D:/a/1/s/pkg/sqlcmd/batch.go:81 +0x6a
github.com/microsoft/go-sqlcmd/pkg/sqlcmd.(*Sqlcmd).Run(0xc0000b8000, 0x90?, 0x0)
        D:/a/1/s/pkg/sqlcmd/sqlcmd.go:142 +0x27c
github.com/microsoft/go-sqlcmd/cmd/sqlcmd.run(0xc00040e028, 0x22430c0)
        D:/a/1/s/cmd/sqlcmd/sqlcmd.go:822 +0xcb3
github.com/microsoft/go-sqlcmd/cmd/sqlcmd.Execute.func2(0xc000028600?, {0xc0000a2000?, 0x9?, 0x10?})
        D:/a/1/s/cmd/sqlcmd/sqlcmd.go:249 +0x425
github.com/spf13/cobra.(*Command).execute(0xc000028600, {0xc000415e00, 0x9, 0x10})
        C:/Users/VssAdministrator/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:920 +0x847
github.com/spf13/cobra.(*Command).ExecuteC(0xc000028600)
        C:/Users/VssAdministrator/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:1044 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
        C:/Users/VssAdministrator/go/pkg/mod/github.com/spf13/cobra@v1.6.1/command.go:968
github.com/microsoft/go-sqlcmd/cmd/sqlcmd.Execute({0x1c1cda8, 0x6})
        D:/a/1/s/cmd/sqlcmd/sqlcmd.go:273 +0x1a5
main.main()
        D:/a/1/s/cmd/modern/main.go:52 +0x21f
shueybubbles commented 2 months ago

those switches are mutually exclusive. I agree sqlcmd shouldn't crash but it's not a supported parameter combination. EG the ODBC sqlcmd ignores the q:

sqlcmd -Q "select 1" -q "select 100"

-----------
          1

(1 rows affected)