Jump to content
Mujkoni

Delphi SQL Formatter

Recommended Posts

SQL to Delphi code
 
 
Default option is CommandText, but you can change it.
There is also option SQL.Add

3 (1).png

2 (1).png

1 (1).png

Edited by Mujkoni
  • Like 3

Share this post


Link to post

I think 5 function calls or 5 assigments is not the best code style. Consider these variants:

SQL.Add('SELECT EntCity, EntStageName' + sLineBreak
  + 'FROM Entertainers' + sLineBreak
  + 'WHERE 1=1' + sLineBreak
  + 'AND TEST=''TEST''' + sLineBreak
  + 'ORDER BY EntCity ASC, EntStageName ASC');
  
CommandText := 'SELECT EntCity, EntStageName' + sLineBreak
  + 'FROM Entertainers' + sLineBreak
  + 'WHERE 1=1' + sLineBreak
  + 'AND TEST=''TEST''' + sLineBreak
  + 'ORDER BY EntCity ASC, EntStageName ASC';

Optionally replace line breaks with spaces:

SQL.Add('SELECT EntCity, EntStageName '
  + 'FROM Entertainers '
  + 'WHERE 1=1 '
  + 'AND TEST=''TEST'' '
  + 'ORDER BY EntCity ASC, EntStageName ASC');

 

  • Like 5

Share this post


Link to post

Recent Delphi versions also allow something like this:

    SQL.AddStrings([
      'FROM Entertainers',
      'WHERE 1=1',
      'AND TEST=''TEST''',
      'ORDER BY EntCity ASC, EntStageName ASC'
      ]);

 

  • Like 3

Share this post


Link to post

SQL.Add (or AddStrings) does not clear the previous content of the SQL text possibly producing the incorrect result. Either explicitly clear the list with SQL.Clear before adding new lines or simply use the Text property: SQL.Text := ....

  • Thanks 1

Share this post


Link to post

Pretty handy, also if it could remove the Delphi formattings so I could easily take SQL and paste it then to SQL tool to tinker with...

Share this post


Link to post

Try GExperts -> Editor Experts -> Paste String As.

This is a gem from GExperts. Furthermore - you have 'Copy Raw Strings' which does the opposite.

  • Like 3

Share this post


Link to post
On 11/7/2018 at 1:30 PM, Edwin Yip said:

Try GExperts -> Editor Experts -> Paste String As.

This is a gem from GExperts. Furthermore - you have 'Copy Raw Strings' which does the opposite.

Is it possible to modify the templates? Or are they hardcoded? I mean I would like to paste my strings as '%s +', so without 'sLineBreak +' and similar. 

Share this post


Link to post
2 hours ago, CoMPi74 said:

Is it possible to modify the templates? Or are they hardcoded? I mean I would like to paste my strings as '%s +', so without 'sLineBreak +' and similar. 

There is the "Convert Strings", editor expert which allows for more complex conversions.

  • Thanks 1

Share this post


Link to post
On 7/7/2023 at 6:01 PM, dummzeuch said:

There is the "Convert Strings", editor expert which allows for more complex conversions.

@dummzeuch That is exactly what I need :) Thank you

Share this post


Link to post

Hello,

 

Isn't the download still available ?

Is there an alternative link ?

 

Many thanks

Alberto

Edited by Alberto Paganini

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×