Menu

#53 Formatting SQL output

open
5
2009-03-25
2009-03-25
No

The output of the SQL Code (views) is almost unredable. It would be nice to format the SQL (like http://www.sqlinform.com/ or http://www.dpriver.com/pp/sqlformat.htm\)

Discussion

  • John Currier

    John Currier - 2009-03-25

    Those both require a for-purchase license. Are there open source solutions available that generate HTML?

     
  • Reiner Kräutle

    Reiner Kräutle - 2009-03-25

    I found an open source Java project for SQL code formatting (no hightlighting): http://code.google.com/p/simplesqlformatter/

     
  • John Currier

    John Currier - 2009-03-26

    Unfortunately that's distributed under a creative commons non-commercial license and doesn't generate HTML. It shouldn't be too difficult to do something similar. One issue, however, is that everyone has their own idea about what formatting approach is readable. The current approach assumes that the SQL in the view is formatted in a style that was deemed appropriate by the DBA.

    John

     
  • John Currier

    John Currier - 2009-06-15

    I looked more closely at http://www.dpriver.com/pp/sqlformat.htm and realized that most of these types of tools will build a parse tree of the SQL and then apply the formatting to that tree. That site, for example, wouldn't render some MySQL views that I have until I explicitly stated to use its MySQL parser.

    I'm hoping that this could be done in a database-independent manner, but that's beginning to appear unlikely.

    John

     
  • John Currier

    John Currier - 2010-04-30

    The latest beta version attempts to detect that the view SQL has already been formatted and presents it in it's original form when it is. Databases may or may not retain the original author's formatting details (MySQL does not), so it might be a pointless attempt.

    There are a few open source projects that attempt to do this type of formatting, but the task basically requires a complete project to do it. I've added a -sqlFormatter command-line option to let you plug-in your own formatter if desired.

    John

     

Log in to post a comment.