Add --no-bom flag for ODBC sqlcmd compatibility#637
Open
dlevy-msft-sql wants to merge 4 commits intomicrosoft:mainfrom
Open
Add --no-bom flag for ODBC sqlcmd compatibility#637dlevy-msft-sql wants to merge 4 commits intomicrosoft:mainfrom
dlevy-msft-sql wants to merge 4 commits intomicrosoft:mainfrom
Conversation
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 TestUnicodeOutputNoBOM test
There was a problem hiding this comment.
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
NoBOMfield to theSqlcmdstruct andSQLCmdArgumentsstruct 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-bomis 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 |
- Add validation that --no-bom requires -u (Unicode output file) - Add test case for --no-bom validation
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.
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.