Only in DbVisualizer Pro
This feature is only available in the DbVisualizer Pro edition.
The SQL Commander main menu on the (or right-click in the editor) and its Format SQL sub menu contains operations for formatting SQL statements.
- Format Buffer and Format Current formats the complete editor content or the current SQL (at cursor position) respectively.
- Copy Formatted and Paste Formatted are powerful tools for copying SQL statements between programs written in languages like Java, C#, PHP, VB, etc. and the SQL Editor. Both operations display a dialog where you can adjust some of the formatting options, most importantly the Target SQL option and the SQL is Between option. Target SQL can be set to a number of common programming language formats.
- Unformat Buffer and Unformat Current produces compact statements by removing unnecessary whitespace.
To copy an SQL statement and paste it as Java code for adding it to a Java StringBuffer:
- Select the statement. Example:
SELECT * FROM SAKILA.STAFF)
- Choose SQL->Format SQL->Copy Formatted,
- Set Target SQL to Java StringBuffer,
- Click Format to place the formatted statement on the system clipboard,
- Paste it into your Java code. Example:
StringBuffer sql = new StringBuffer();
sql.append(" * ");
To copy a statement wrapped in code from a program:
- Select the code containing an SQL statement in your program,
- Copy it to the system clipboard,
- Choose SQL->Format SQL->Paste Formatted,
- Check SQL is Between and enter the character enclosing the SQL statement in the code,
- Click Format to extract the SQL statement and paste the formatted SQL in the editor.
All formatting is done according to the settings defined in the Tool Properties dialog, in the SQL Commander/SQL Formatting category under the General tab.
There are many things you can configure; use the default example or your own SQL to check the effect of the settings. After making some changes, press Apply and format again to see the result.