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
334 stars 58 forks source link

Vertical option for results not working in context #321

Closed way0utwest closed 1 year ago

way0utwest commented 1 year ago

The docs and readme seem to indicate that I can get vertical results from go-sqlcmd. This works interactively, but if I have a context, this doesn't work.

I tried setting a SET variable to vertical, but that didn't work either. My expectation is I can set this for the context, or I can add this flag to a query and get vertical results.

2023-04-11 17_20_29-cmd

shueybubbles commented 1 year ago

thx for the issues @way0utwest Could you please paste the repro steps as text instead of pictures? It'll help accelerate the investigations.

shueybubbles commented 1 year ago

the query command currently lacks access to the custom output formatting options available to non-context-based invocations. @apoorvdeshmukh - didn't we merge a PR that will use the current default context as SQLCMDSERVER such that a user can run sqlcmd in backward-compat mode without needing to provide the server name and credentials?

apoorvdeshmukh commented 1 year ago

@shueybubbles Yes. That is correct. If current-context is not nil then user can simply invoke sqlcmd with backward compat flags to execute query against current-context Example

\git\go-sqlcmd>.\sqlcmd.exe create mssql --accept-eula
Downloading mcr.microsoft.com/mssql/server:latest
Starting mcr.microsoft.com/mssql/server:latest
Created context "mssql" in "C:\Users\apdeshmukh\.sqlcmd\sqlconfig", configuring user account...
Disabled "sa" account (and rotated "sa" password). Creating user "apdeshmukh"
Now ready for client connections on port 1435

HINT:
  1. Open in Azure Data Studio: sqlcmd open ads
  2. Run a query:               sqlcmd query "SELECT @@version"
  3. Start interactive session: sqlcmd query
  4. View sqlcmd configuration: sqlcmd config view
  5. See connection strings:    sqlcmd config connection-strings
  6. Remove:                    sqlcmd delete

git\go-sqlcmd>.\sqlcmd.exe -F vertical -Q "select @@version, @@servername, suser_name(), user_name()"
 Microsoft SQL Server 2022 (RTM-CU2) (KB5023127) - 16.0.4015.1 (X64)
        Feb 27 2023 15:40:01
        Copyright (C) 2022 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Ubuntu 20.04.5 LTS) <X64>
 26f6fd67ecc0
 apoorvdeshmukh
 dbo

(1 row affected)
way0utwest commented 1 year ago

This is a great workaround.

Not sure why go-sqlcmd can't acccess results in context. If that is a design decision, that seems poor. If it's something not yet implemented, I understand.

You can close this issue as the workaround is fine.