SQL Formatter Options
Options
Extract / Generate Source Code
The Extract & Generate Options in the SQL Formatter Tool provide functionality to extract SQL statements from source code (e.g., Java, C#) and generate source code in various programming languages based on formatted SQL. These features are essential for integrating SQL with application code efficiently.
Extract SQL from Source Code
SQL in Source Code Between
- Defines the delimiters or markers that indicate the start and end of SQL code within the source code.
- Example: SQL statements in Java might be enclosed in double quotes (
"SELECT * FROM table;"
).
Always „Extract SQL“ Before „Format SQL“
- When enabled, the tool will automatically extract SQL from the source code before applying any formatting.
- This ensures that only valid SQL statements are formatted.
Extract SQL
- Click this button to extract SQL code from the source code based on the specified delimiters.
- The extracted SQL can then be formatted using the tool.
Generate Source Code
Always „Generate Code“ After „Format SQL“
- When enabled, the tool automatically generates source code after formatting the SQL.
- This ensures that the formatted SQL is seamlessly reintegrated into the source code.
Language
- Select the target programming language for generating source code (e.g., Java, C#, etc.).
- This setting adapts the generated code to match the syntax and conventions of the chosen language.
Generate
- Click this button to generate source code based on the formatted SQL and the selected programming language.
- The tool ensures proper escaping and syntax adjustments for the target language.
Simulation
- Allows you to simulate the source code generation process without making any actual changes.
- Useful for previewing the generated output before applying it to your project.
How to Use These Features
Extracting SQL
- Specify the delimiters used in your source code to enclose SQL statements in the SQL in Source Code Between field.
- Click Extract SQL to pull out the SQL statements, which can then be formatted.
Formatting SQL
- Use the standard formatting options in the tool to format the extracted SQL statements.
- Ensure Always „Extract SQL“ Before „Format SQL“ is enabled for automatic extraction during formatting.
Generating Source Code
- Select the desired target language in the Language dropdown.
- Click Generate to create source code with the formatted SQL embedded, using the syntax and conventions of the chosen language.
- Use the Simulation button to preview the generated source code before applying it.
Automating the Workflow
- Enable Always „Generate Code“ After „Format SQL“ to streamline the process of formatting SQL and generating source code in one step.
Tips for Optimal Usage
- Delimiters: Ensure the correct delimiters are set in the SQL in Source Code Between field to accurately extract SQL from your source code.
- Language Selection: Choose the appropriate language in the Language dropdown to ensure compatibility with your application code.
- Simulation: Use the Simulation option to verify the generated code before applying it, avoiding potential integration issues.
- Automation: Enable the Always „Extract SQL“ Before „Format SQL“ and Always „Generate Code“ After „Format SQL“ options to automate and speed up repetitive tasks.