feat: implement -p flag for print statistics#631
Open
dlevy-msft-sql wants to merge 1 commit intomicrosoft:mainfrom
Open
feat: implement -p flag for print statistics#631dlevy-msft-sql wants to merge 1 commit intomicrosoft:mainfrom
dlevy-msft-sql wants to merge 1 commit intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for a -p flag that prints per-batch performance statistics, improving compatibility with legacy ODBC sqlcmd and documenting the feature and its formats.
Changes:
- Extend the
Sqlcmdengine with aPrintStatisticsoption and aprintStatisticshelper that measures batch execution time and prints statistics in standard or colon-separated format. - Wire the new
-p/--print-statisticsflag through the CLI argument parsing pipeline, including normalization and propagation into theSqlcmdinstance. - Add unit tests for the statistics output formats and disabled behavior, and document usage and sample output in the README.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/sqlcmd/sqlcmd.go | Adds PrintStatistics support, measures batch duration in runQuery, and implements printStatistics for both human-readable and colon-separated output. |
| pkg/sqlcmd/sqlcmd_test.go | Adds tests that verify standard-format output, colon-separated output, and the disabled case when PrintStatistics is nil. |
| cmd/sqlcmd/sqlcmd.go | Introduces the -p/--print-statistics CLI flag, integrates it into argument parsing, normalization, and run, and passes the option into the Sqlcmd core. |
| README.md | Documents the new -p behavior and shows an example of the standard statistics output format. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jan 25, 2026
dlevy-msft-sql
added a commit
to dlevy-msft-sql/go-sqlcmd
that referenced
this pull request
Jan 25, 2026
- Add 'p' to checkDefaultValue for bare -p flag support - Fix error message to show both '0' and '1' as valid values - Remove trailing space in colon-separated format output - Add test cases for -p and -p 1 flags
0f6dab6 to
60d2a1c
Compare
Adds -p and -p1 flags to print execution statistics after each batch: - -p: Standard format with packet size, execution count, and timing - -p1: Colon-separated format for parsing (packetSize:batches:total:avg:rate) Uses new DefaultPacketSize constant (4096) instead of magic numbers.
47ef69f to
b7565f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for the
-pflag which prints performance statistics after each batch execution, improving compatibility with legacy ODBC sqlcmd.Changes
-pflag parsing with validation for values 0 or 1printStatistics()methodUsage
Output Formats
Standard format (
-por-p0)Colon-separated format (
-p1)Testing
golangci-lint runpasses