The SQL Transformer performs certain transformations on SQL source code. The tool knows about a set of predefined transformations. Other transformations can be added upon request. The following example shows an SQL statement before and after transformation:
The main intention of this transformation is the replacement of comma-joins by JOIN operators. In order to accomplish this ambitious task, the transformation has been split into several smaller transformation steps:
- Elimination of superfluous parentheses
- Extraction of ON conditions from the WHERE clause
- Swapping of operands of certain conditions (see inserted ON conditions)
- Replacing of comma-joins by JOIN operators
- Insertion of ON conditions
Additionally, a qualifier has been added to the table names in this example.
The SQL Transformer works as follows: An SQL parser creates a tree representation of the source code. The transformation steps are performed on the tree structure resulting in a modified version of the tree. Finally, the new source code is emitted by unparsing the tree with our SQL Pretty-Printer.