Skip to content

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

Add support for the -p flag which prints performance statistics after
each batch execution:
- -p (or -p0): Standard human-readable format
- -p1: Colon-separated format for parsing

Statistics include network packet size, transaction count, and timing
information (total ms, average ms, transactions per second).

This improves compatibility with legacy ODBC sqlcmd.
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.

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