Skip to content
This repository

A small free .Net 2.0 library (with demo UI, command-line bulk formatter, SSMS/Visual Studio add-in, notepad++ plugin, winmerge plugin, and web service) for reformatting and coloring T-SQL code to the user's preferences.

branch: master

Github Issue #109 (Fix to Github Issue #86): Visual Studio 2012 suppo…

…rt was never tested before release, and turned out to be broken.
latest commit 4fd83bb2c0
Tao Klerks authored October 22, 2013
Octocat-spinner-32 ExternalBuildTools Build process error-handling fix + commenting + adding missing depend… November 11, 2012
Octocat-spinner-32 PoorMansTSqlFormatterCmdLine version 1.5.1 publish October 20, 2013
Octocat-spinner-32 PoorMansTSqlFormatterDemo version 1.5.1 publish October 20, 2013
Octocat-spinner-32 PoorMansTSqlFormatterLib version 1.5.1 publish October 20, 2013
Octocat-spinner-32 PoorMansTSqlFormatterNppPlugin version 1.5.1 publish October 20, 2013
Octocat-spinner-32 PoorMansTSqlFormatterPluginShared version 1.5.1 publish October 20, 2013
Octocat-spinner-32 PoorMansTSqlFormatterSSMSAddIn.Setup Github Issue #109 (Fix to Github Issue #86): Visual Studio 2012 suppo… October 22, 2013
Octocat-spinner-32 PoorMansTSqlFormatterSSMSAddIn Github Issue #109 (Fix to Github Issue #86): Visual Studio 2012 suppo… October 22, 2013
Octocat-spinner-32 PoorMansTSqlFormatterTest version 1.5.1 publish October 20, 2013
Octocat-spinner-32 PoorMansTSqlFormatterWebDemo version 1.5.1 publish October 20, 2013
Octocat-spinner-32 PoorMansTSqlFormatterWinMergePlugin.Setup version 1.5.1 publish October 20, 2013
Octocat-spinner-32 PoorMansTSqlFormatterWinMergePlugin Insignificant VB6 reference changes September 02, 2012
Octocat-spinner-32 .gitignore Add notepad++ autosave file exception February 26, 2012
Octocat-spinner-32 BUILDING.txt Publishing instructions update September 02, 2012
Octocat-spinner-32 CHANGELOG.md Github Issue #109 (Fix to Github Issue #86): Visual Studio 2012 suppo… October 22, 2013
Octocat-spinner-32 LICENSE.rtf V 0.9.6 - SSMS Addin completed May 15, 2011
Octocat-spinner-32 LICENSE.txt Initial Commit April 22, 2011
Octocat-spinner-32 PoorMansTSqlFormatter.sln Issue #47: Separate option for expanding IN lists October 12, 2013
Octocat-spinner-32 README.md version 1.5.1 publish October 20, 2013
README.md

Poor Man's T-SQL Formatter

This is a small free .Net 2.0 library (with demo winforms program, web service, SSMS and Visual Studio Addin, Command-line utility, Notepad++ plugin, and WinMerge plugin) for reformatting T-SQL code.

Features

  • Simple Xml-based parse tree
  • Extensible, with possibility of supporting other SQL dialects (but none implemented)
  • Configurable according to SQL formatting preferences
  • Handles "procedural" T-SQL; this is not just a SQL statement formatter, but it also formats entire batches, and multi-batch scripts.
  • Optional colorized HTML output
  • Fault-tolerant parsing and formatting - if some unknown SQL construct is encountered or a keyword is misinterpreted, parsing does not fail (but will simply not colorize or indent that portion correctly). If the parsing fails more catastrophically, a "best effort" will be made and warning displayed (or in the case of interactive use, eg in SSMS, the operation can be aborted).
  • Reasonably fast: reformatting 1,500 or so files totalling 4MB takes 30 seconds on a cheap atom-processor (2009) netbook.
  • Works in Microsoft .Net framework, as well as Mono. The Winforms Demo App is not (yet?) available in Mono, but the library itself is fully functional, as is the command-line bulk formatting tool.

General Limitations

  • This is NOT a full SQL-parsing solution: only "coarse" parsing is performed, the minimum necessary for re-formatting.
  • The standard formatter does not always maintain the order of comments in the code; a comment inside an "INNER JOIN" compound keyword, like "inner/*test*/join", would get moved out, to "INNER JOIN /*test*/". The original data is maintaned in the parse tree, but the standard formatter shuffles comments in cases like this for clarity.
  • DDL parsing, in particular, is VERY coarse - the bare minimum to display ordered table column and procedure parameter declarations.
  • No effort has been made to support compatibility level 70 (SQL Server 7)
  • Where there is ambiguity between different compatibility levels (eg cross apply parens in compatibility level 90 vs table hints without "WITH" keyword in compatibility level 80), no approach has been decided. For now, table hints without WITH are considered to be arguments to a function.

Known Issues / Todo

  • Handling of DDL Triggers (eg "FOR LOGON")
  • Formatting/indenting of ranking functions
  • FxCop checking
  • And other stuff that is tracked in the GitHub issues list

Longer-term enhancements / additions

  • Compiled mono library + bulk formatting tool download (eg for use on SVN server)
  • Documentation of Xml structure and class usage

License & Credits

This application and library is released under the GNU Affero GPL v3: http://www.gnu.org/licenses/agpl.txt

The homepage for this project is currently: http://www.architectshack.com/PoorMansTSqlFormatter.ashx

This project uses several external libraries:

  • NDesk.Options, for command-line parsing: The NDesk.Options library is licensed under the MIT/X11 license, and its homepage is here: http://www.ndesk.org/Options
  • LinqBridge, for convenience, supporting extension methods and Linq-to-Objects despite this being a .Net 2.0 library. LinqBridge is licensed under the BSD 3-clause license, and its homepage is here: http://code.google.com/p/linqbridge/
  • NUnit, for automated testing. NUnit is licensed under a custom open-source license based on the zlib/libpng license, and its homepage is: http://www.nunit.org/
  • DLLExport and Notepad++ C# plugin template, based on work by Robert Giesecke and UFO, available from the notepad++ plugin development forum.
  • ILRepack, by François Valdy, for assembly-merging, available from the github project page.

Special thanks to contributors that have given their time to make this library better:

  • Timothy Klenke

Also thanks to Adam Pawsey, who maintains the NuGet package.

Many of the features in this project result from feedback by multiple people, including but not limited to:

  • Loren Halvorson
  • Recep Guzel
  • Lane Duncan
  • Gokhan Varol
  • Pushpendra Rishi
  • Jonathan Fahey
  • Tim Costello
  • Jörg Burdorf
  • William Lin
  • Brad Wood
  • Richard King
  • Jeff Clark
  • Jarred Cleem
  • Paul Toms
  • Tom Holden
  • Marvin Eads
  • Bill Ruehle
  • Farzad Jalali
  • Sheldon Hull
  • Benjamin Solomon

Translation work on this project was originally facilitated by Amanuens, the online translation platform that is now sadly defunct.

Please contact me with any questions, concerns, or issues: my email address starts with tao, and is hosted at klerks dot biz.

Tao Klerks

Something went wrong with that request. Please try again.