Tapatalk

SQL formatter (beautifier) plug-in or macro

SQL formatter (beautifier) plug-in or macro

9
NewbieNewbie
9

    Sep 08, 2012#1

    Is it possible to create a plug-in or macro for UltraEdit to beautify the SQL codes like the T-SQL Formatter does?
    It will automatically format the messy SQL codes into clean and readable format.

    Change from:

    Code: Select all

    SELECT X,Y,Z FROM FOO;
    To:

    Code: Select all

    SELECT
      X,
      Y,
      Z
    FROM
      FOO
      ;
    

    6,685587
    Grand MasterGrand Master
    6,685587

      Sep 08, 2012#2

      It should be no problem to create such scripts or macros. I don't know anything about SQL, but for your example following tagged regular expression Replace recorded into a macro converts the example line to the wanted output.

      Code: Select all

      InsertMode
      ColumnModeOff
      UltraEditReOn
      Find RegExp "SELECT[ ^t]+^(*,^)^(*,^)^(*^) FROM ^(*^);"
      Replace All "SELECT^p  ^1^p  ^2^p  ^3^pFROM^p  ^4^p  ;"
      

      2362
      MasterMaster
      2362

        Sep 08, 2012#3

        Also, instead of "re-inventing the wheel" by writing a macro or script, you could set up a user tool in UltraEdit to pass the current filename to a command line program.

        There is one such program at Architect Shack, if you scroll down on that page and locate "Command-line bulk formatting utility". The actual download is located here. There are others available, if you Google for it. That was just the first one I found. Seems there are a lot of "online" formatting utilities available, but doing it online is rather clumsy, as you have to cut and paste twice and must depend on another server being available, and it also will process the file much slower than a local executable.

        Best of luck.

        9
        NewbieNewbie
        9

          Sep 09, 2012#4

          I checked the site you suggested. They even have a plug-in for NotePad++! Wouldn't it be nice to be able to format only highlighted SQL codes (embedded within other program, like PHP, etc.) in UltraEdit using a plug-in? Or doing something like "HTML Tidy" within UE? Sorry. I forgot that we can do HTML Tidy in UE. I mean, automatically indent and format the SQL, HTML, etc. I think, I can live with an external code formatter for now. Thanks.