Skip to content

feat: implement -p flag for print statistics#631

Open
dlevy-msft-sql wants to merge 1 commit intomicrosoft:mainfrom
dlevy-msft-sql:print-statistics
Open

feat: implement -p flag for print statistics#631
dlevy-msft-sql wants to merge 1 commit intomicrosoft:mainfrom
dlevy-msft-sql:print-statistics

Conversation

@dlevy-msft-sql
Copy link
Contributor

@dlevy-msft-sql dlevy-msft-sql commented Jan 25, 2026

Summary

Adds support for the -p flag which prints performance statistics after each batch execution, improving compatibility with legacy ODBC sqlcmd.

Changes

  • cmd/sqlcmd/sqlcmd.go: Added -p flag parsing with validation for values 0 or 1
  • pkg/sqlcmd/sqlcmd.go: Added timing measurement and printStatistics() method
  • pkg/sqlcmd/sqlcmd_test.go: Added unit tests for standard format, colon format, and disabled scenarios
  • README.md: Added documentation with usage example

Usage

# Standard format (default)
sqlcmd -S server -Q "SELECT 1" -p

# Colon-separated format
sqlcmd -S server -Q "SELECT 1" -p1

Output Formats

Standard format (-p or -p0)

Network packet size (bytes): 4096
1 xact[s]:
Clock Time (ms.): total         5  avg   5.00 (200.00 xacts per sec.)

Colon-separated format (-p1)

4096:1:5:5.00:200.00

Testing

  • All new tests pass
  • golangci-lint run passes
  • Build succeeds

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Sqlcmd engine with a PrintStatistics option and a printStatistics helper that measures batch execution time and prints statistics in standard or colon-separated format.
  • Wire the new -p/--print-statistics flag through the CLI argument parsing pipeline, including normalization and propagation into the Sqlcmd instance.
  • 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.

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
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@dlevy-msft-sql dlevy-msft-sql self-assigned this Jan 25, 2026
@dlevy-msft-sql dlevy-msft-sql added sqlcmd switch switch in existing sqlcmd Size: S Small issue (less than one week effort) labels Jan 25, 2026
@dlevy-msft-sql dlevy-msft-sql force-pushed the print-statistics branch 2 times, most recently from 0f6dab6 to 60d2a1c Compare February 5, 2026 19:56
@dlevy-msft-sql dlevy-msft-sql changed the title Implement -p flag for print statistics feat: implement -p flag for print statistics Feb 5, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size: S Small issue (less than one week effort) sqlcmd switch switch in existing sqlcmd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant