feat: add ASCII table query output format#609
Conversation
|
thx for opening a PR! |
There was a problem hiding this comment.
Pull request overview
This pull request adds a new ASCII table output format to sqlcmd, providing a more visually structured alternative to the default horizontal format. The feature is activated via the --ascii command-line flag or by setting the SQLCMDFORMAT variable to "ascii".
- Introduces ASCII table formatter with automatic column wrapping for wide result sets
- Updates the formatter initialization pattern across the codebase to support format selection
- Adds comprehensive test coverage for the new formatter
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/sqlcmd/variables.go | Adds "ascii" case handling in Format() method and initializes SQLCMDFORMAT variable |
| pkg/sqlcmd/format.go | Updates NewSQLCmdDefaultFormatter to accept Variables parameter and delegate to ASCII formatter when appropriate |
| pkg/sqlcmd/format_ascii.go | Implements new asciiFormatter with table rendering, column wrapping, and numeric alignment |
| pkg/sqlcmd/format_ascii_test.go | Provides test coverage for ASCII formatter including basic output and column wrapping scenarios |
| pkg/sqlcmd/sqlcmd_test.go | Updates test helper functions to pass Variables to formatter constructor |
| pkg/sqlcmd/commands_test.go | Updates TestListColorPrintsStyleSamples to pass Variables to formatter constructor |
| cmd/sqlcmd/sqlcmd.go | Adds --ascii flag definition and implements format variable setting logic |
| internal/sql/mssql.go | Updates formatter initialization to pass Variables parameter |
| build/buildfast.cmd | Adds Windows build script for faster development builds |
| README.md | Documents the new --ascii option and ASCII table format feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
pkg/sqlcmd/format.go:101
- The
varsfield is not initialized in thesqlCmdFormatterTypestruct. This will cause a nil pointer dereference when methods likeScreenWidth()orColumnSeparator()are called onf.varsin the horizontal/vertical formatter. Addvars: vars,to fix this issue.
return &sqlCmdFormatterType{
removeTrailingSpaces: removeTrailingSpaces,
format: "horizontal",
colorizer: color.New(false),
ccb: ccb,
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
please resolve the comments that have been addressed |
All resolved. |
|
@shueybubbles There's still an issue: if a cell's content exceeds the terminal width, the output doesn't display well.
I can submit a new commit to limit the maximum column width to the terminal width and truncate any excess content. Any ideas? |
That sounds good. Truncate 3 columns short of the limit and add |
Implemented. |
…ed when using ASCII table format
Refactor deferred buffer closing to assert no error.
|
Re-reviewed at head 1. Missing copyright header on new filesBoth // Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package sqlcmd2.
|
|
Code modified based on the feedback. |
dlevy-msft-sql
left a comment
There was a problem hiding this comment.
Verified at head 9cc0e839. All three findings from my earlier comment are addressed:
format_ascii.go/format_ascii_test.go— Microsoft copyright headers added.asciiFormatter.AddRow—f.rowcount++added after successful scan.setupSqlCmdWithMemoryOutput— restored toassert.NoError(t, err, "s.ConnectDB").
Bonus: the Refactor buffer closure commit also asserts on buf.Close() in TestAsciiFormatterWrapping instead of swallowing the error. Nice.
Thanks for the fast turnaround. LGTM.
|
Do you have any screenshots of colorized output? I bet for some color schemes it looks very nice compared to ODBC format. |


This pull request adds a new ASCII table output format to sqlcmd, making it easier to read query results. It introduces the
--asciicommand-line option and updates the relevant code paths to support this feature.README.mdhas also been updated to reflect this option.If
--asciiis not used, sqlcmd behaves exactly the same as before.The new output format looks like this: