SQL formatter (beautifier) plug-in or macro

This forum is user-to-user based and not regularly monitored by IDM.
Please see the note at the top of this page on how to contact IDM.

SQL formatter (beautifier) plug-in or macro

Postby totolacat » Fri Sep 07, 2012 9:57 pm

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

Change from : SELECT X,Y,Z FROM FOO;
To:
SELECT
X,
Y,
Z
FROM
FOO
;
totolacat
Newbie
 
Posts: 4
Joined: Thu Jan 26, 2012 11:49 pm

Re: SQL formatter (beautifier) plug-in or macro

Postby Mofi » Sat Sep 08, 2012 5:12 am

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.

InsertMode
ColumnModeOff
HexOff
UltraEditReOn
Find RegExp "SELECT[ ^t]+^(*,^)^(*,^)^(*^) FROM ^(*^);"
Replace All "SELECT^p^1^p^2^p^3^pFROM^p^4^p;"
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: SQL formatter (beautifier) plug-in or macro

Postby rhapdog » Sat Sep 08, 2012 8:29 am

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.
User avatar
rhapdog
Master
Master
 
Posts: 271
Joined: Tue Apr 01, 2008 10:02 am
Location: Mississippi, USA

Re: SQL formatter (beautifier) plug-in or macro

Postby totolacat » Sun Sep 09, 2012 3:34 pm

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 UE using a plug-in? Or doing something like "HTML Tidy" within UE?
I think I can live with an external code formatter for now. Thanks
totolacat
Newbie
 
Posts: 4
Joined: Thu Jan 26, 2012 11:49 pm

Re: SQL formatter (beautifier) plug-in or macro

Postby totolacat » Sun Sep 09, 2012 3:39 pm

Sorry. I forgot that we can do HTML Tidy in UE. I mean, automatically indent and format the SQL, HTML, etc..
totolacat
Newbie
 
Posts: 4
Joined: Thu Jan 26, 2012 11:49 pm


Return to UltraEdit General Discussion