Skip to main content

Generate safe T-SQL stored-procedure debug harness scripts (analyze + DML previews)

Project description

sql-sp-harness

PyPI version Python 3.10|3.12|3.13

sql-sp-harness

T-SQL Stored Procedure Debug Harness — turn SQL Server stored procedures into safe, runnable debug scripts you can execute on a pre-production database without writing to real tables.

Documentation site: https://deeprajdeveloper.github.io/sql-sp-harness/ (GitHub Pages). Site styles: docs/scss/ → compile with npx sass docs/scss/styles.scss docs/scss/css/styles.css.

Not a live debugger. This tool generates a static test harness (DML previews + variable traces), not breakpoints or step-into debugging.

Not affiliated with Microsoft. "SQL Server" and T-SQL are used descriptively only.

What it does

Command Purpose
analyze See what keyword elements that procedure contains along with counts — DML, TRY/CATCH, loops, SET, line-level detail
generate Create a debug harness: real-table DML → SELECT previews, PRINT traces on variables

Output includes a banner on the top of the procedure stating: DEBUG HARNESS — DO NOT RUN ON PRODUCTION.

Install

pip install sql-sp-harness

Requires Python 3.10+.

Verify:

sql-sp-harness version
python -m sql_sp_harness version

Quick start

sql-sp-harness analyze -i MyProc.sql
sql-sp-harness generate -i MyProc.sql -o MyProc_debug.sql

With traces in the Messages tab (default):

sql-sp-harness generate -i MyProc.sql -o MyProc_debug.sql --trace-style print

By default, generate removes original line (--) and block (/* */) comments from the output. Use --keep-comments to preserve them (harness [DBG-*] markers are always added).

Deploy preamble (IF EXISTS / DROP PROCEDURE, SET ANSI_NULLS, SET QUOTED_IDENTIFIER) is removed for both analyze and generate. generate also rewrites CREATE PROCEDURE into DECLARE parameters so the script does not create the procedure on the server.

Step log (audit trail)

Use --log to write a timestamped log beside the input (MyProc.log), or --log-file path/to/run.log for a custom path. Works with both analyze and generate; logs file read, each transform step, DML stub line ranges, trace injection counts, and warnings.

sql-sp-harness generate -i MyProc.sql -o MyProc_debug.sql --log
sql-sp-harness analyze -i MyProc.sql --log-file /tmp/myproc-analyze.log

With --log, progress still prints to stderr unless you also pass --quiet (the log file always receives full detail).

Development

git clone https://github.com/DeeprajDeveloper/sql-sp-harness.git
cd sql-sp-harness
pip install -e ".[dev]"
pytest

Build for PyPI:

./scripts/publish-pypi.sh
./scripts/publish-pypi.sh upload

File encoding

SSMS often saves scripts as UTF-16 LE (Unicode). Older Windows exports may use Windows-1252 (smart quotes, en-dashes). The CLI auto-detects these; output is always UTF-8. Override with --encoding if needed:

sql-sp-harness generate -i MyProc.sql -o MyProc_debug.sql --encoding utf-16-le

Limitations

Pattern Behavior
Dynamic SQL Not analyzed
Encrypted procedures No source
Cursors Not rewritten
DDL inside proc Not stubbed

Always review generated scripts before running them on the database server.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sql_sp_harness-1.0.3.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sql_sp_harness-1.0.3-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file sql_sp_harness-1.0.3.tar.gz.

File metadata

  • Download URL: sql_sp_harness-1.0.3.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sql_sp_harness-1.0.3.tar.gz
Algorithm Hash digest
SHA256 9e0e36765cfe8779371962f944bce9cfaa7dbf8b973f09b25978ada7e9303617
MD5 c5c7b5f156baaccb62c669b0e60e5fb7
BLAKE2b-256 5db847bbd603b91fe2181108c77deb9b277f333bcb121354f5fd3d0eadf6df0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sql_sp_harness-1.0.3.tar.gz:

Publisher: publish-pypi.yml on DeeprajDeveloper/sql-sp-harness

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sql_sp_harness-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: sql_sp_harness-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sql_sp_harness-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9c1c48ac3c641faf7e32bd5960468db8e72dd1a2bfae6358c2c3a73233a81f29
MD5 7e55b1577a6a90b5f9dbfdaf6ce12a9a
BLAKE2b-256 df2424919559f9dcf1d5d36f726720642996c1c5fb4cfbc3060b99466a7cb158

See more details on using hashes here.

Provenance

The following attestation bundles were made for sql_sp_harness-1.0.3-py3-none-any.whl:

Publisher: publish-pypi.yml on DeeprajDeveloper/sql-sp-harness

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page