I’m looking for a solution that will format SQL statements from within a Delphi application.
No visual interface is required, just something that when passed a string containing an SQL query will return the same statement with some sort of sensible formatting.
Synedit has a sql
highlighter that I guess should be morphable into a pretty printer …
Maybe this is worth looking at …
GitHub - SqlToys/SqlFormatter: Command line version of SqlFormatter.
That one’s no good. The parser unit is provided in DCU form and he provides the DCU for just one Delphi version. He doesn’t even tell you which Delphi version the DCU is for. Too big a risk to rely on, even if he did supply versioned DCUs.
I have a very simple SQL formatter we used years ago. Not sure if it would work for you. Do you have a simple example I could run through it to see what it gives?
The HTML Component Library appears to have an SQL framework in it. This supposedly does SQL Formatting.
SQL Framework (delphihtmlcomponents.com)
sqlformat (exe) returns …
WHERE ( studentID BETWEEN 1 AND 5
OR studentID = 8
OR FullName LIKE '%Maximo%' )
AND sat_score NOT IN ( 1000, 1400 )
SynEdit highlights as … (new lines inserted by me)
Seems like even just (), SELECT, FROM, JOIN, WHERE, GROUP might get you a good way there.
sqlformat (exe) returns
Which one is that? If it’s the SqlToys/SqlFormatter repository on GitHub I’ve eliminated that one from consideration already due to the DCU issue but I’m curious about which Delphi version you built the EXE with.
That’s a very surprising inclusion to be in that library!
The HTML components themselves are excellent so this SQL framework definitely warrants a closer look.
After some investigation, it looks like the DCU is for XE7 (Win32?)
Yes - from the Github page as a .exe file.
I ran it to see what sort of output someone might want to aim for.
(Also … I did soon realise that my ‘example’ I gave was only a small subset of the SQL reserved words)