Skip to content

Investigate ODBC compatibility mode via environment variable #660

@dlevy-msft-sql

Description

@dlevy-msft-sql

Summary

Investigate adding an environment variable (e.g., SQLCMD_ODBC_COMPAT=1) that would make go-sqlcmd behave exactly like the original ODBC sqlcmd for maximum backward compatibility.

Motivation

go-sqlcmd has intentionally diverged from ODBC sqlcmd in several areas to provide better defaults for modern usage. However, users migrating existing scripts or workflows may need exact behavioral compatibility with the original tool.

Potential Scope

When the compatibility mode is enabled, go-sqlcmd would match ODBC sqlcmd behavior in areas including:

Codepage Handling (PR #638)

Behavior go-sqlcmd (current) ODBC sqlcmd Compat mode
Default encoding UTF-8 Windows ANSI (system locale) ANSI
UTF-16 codepages (1200, 1201) Not supported Supported Supported
BOM detection Automatic Automatic Automatic

Other Potential Areas (to investigate)

  • Output formatting differences
  • Error message formatting
  • Exit code behavior
  • Variable expansion edge cases
  • Null handling in output
  • Column width calculations

Implementation Options

  1. Single env var: SQLCMD_ODBC_COMPAT=1 enables all compatibility behaviors
  2. Granular env vars: SQLCMD_CODEPAGE_COMPAT=1, SQLCMD_OUTPUT_COMPAT=1, etc.
  3. Command-line flag: --odbc-compat or -y (if available)

Tasks

  • Document all known behavioral differences between go-sqlcmd and ODBC sqlcmd
  • Evaluate which differences can reasonably be made configurable
  • Design the compatibility mode API (env var name, granularity)
  • Implement compatibility mode for codepage handling
  • Add tests for compatibility mode behavior
  • Update documentation

Related

Labels

enhancement, documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions