Skip to content

feat: add --no-bom flag for ODBC sqlcmd compatibility#637

Open
dlevy-msft-sql wants to merge 1 commit intomicrosoft:mainfrom
dlevy-msft-sql:no-bom-flag
Open

feat: add --no-bom flag for ODBC sqlcmd compatibility#637
dlevy-msft-sql wants to merge 1 commit intomicrosoft:mainfrom
dlevy-msft-sql:no-bom-flag

Conversation

@dlevy-msft-sql
Copy link
Contributor

By default, -u (unicode output) includes a UTF-16 LE BOM (FF FE) at the start of output files. ODBC sqlcmd does not write a BOM. This adds --no-bom flag to omit the BOM when strict ODBC compatibility is needed. Usage: sqlcmd -u --no-bom -o output.txt. Also updates README to document the difference.

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 a --no-bom flag to provide ODBC sqlcmd compatibility by omitting the UTF-16 Little-Endian BOM from Unicode output files. By default, when using -u (unicode output), go-sqlcmd writes a BOM (bytes FF FE) to output files, but ODBC sqlcmd does not. The new flag allows users to suppress the BOM when strict ODBC compatibility is needed.

Changes:

  • Added NoBOM field to the Sqlcmd struct and SQLCmdArguments struct to control BOM behavior
  • Updated the output file encoding logic to conditionally omit the BOM based on the flag
  • Added test coverage to verify the BOM is correctly omitted when --no-bom is used
  • Updated README documentation to explain the difference from ODBC sqlcmd and the new flag

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/sqlcmd/sqlcmd.go Added NoBOM boolean field to the Sqlcmd struct to control BOM output
pkg/sqlcmd/commands.go Updated outCommand to use unicode.IgnoreBOM when NoBOM is true, otherwise uses unicode.UseBOM
cmd/sqlcmd/sqlcmd.go Added NoBOM field to SQLCmdArguments, registered the --no-bom CLI flag, and passed the value to the Sqlcmd struct
cmd/sqlcmd/sqlcmd_test.go Added TestUnicodeOutputNoBOM test to verify BOM is not written when flag is set
README.md Updated documentation to explain that -u includes a BOM by default and how to use --no-bom for ODBC compatibility

dlevy-msft-sql added a commit to dlevy-msft-sql/go-sqlcmd that referenced this pull request Jan 25, 2026
- Add validation that --no-bom requires -u (Unicode output file)
- Add test case for --no-bom validation
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 1 comment.

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 1 comment.

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 changed the title Add --no-bom flag for ODBC sqlcmd compatibility feat: add --no-bom flag for ODBC sqlcmd compatibility Feb 5, 2026
@dlevy-msft-sql dlevy-msft-sql force-pushed the no-bom-flag branch 2 times, most recently from a605141 to 0ee79e4 Compare February 5, 2026 23:12
By default, -u (unicode output) includes a UTF-16 LE BOM (FF FE) at the
start of output files. ODBC sqlcmd does not write a BOM.

This adds --no-bom flag to omit the BOM when strict ODBC compatibility
is needed. Usage: sqlcmd -u --no-bom -o output.txt

Changes:
- Add NoBOM field to SQLCmdArguments and Sqlcmd structs
- Add --no-bom flag with descriptive help
- Conditionally use unicode.IgnoreBOM when flag is set
- Update README to document the difference and new flag
- Add tests for --no-bom flag
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