Generating pureQuery code from single SQL statements

You can generate pureQuery code from a single SQL statement. The statement can be an SQL string in Java code, an SQL script that contains a single SQL statement, or part of an SQL script.

About this task

You can work with SQL scripts that are in pureQuery-enabled Java projects in the Java perspective and in data development projects in the SQL and Routine Development perspective. You also can work with scripts that are open in the SQL and XQuery editor.

You can use this process to generate pureQuery code only for a valid SELECT, INSERT, UPDATE, DELETE, or CALL statement. If a JDBC prepareStatement() method of the SQL statement results in errors, a message box displays the error message that is returned.

If you want to generate code from more than one SQL statement, see Generating pureQuery code from multiple SQL statements.

Procedure

To generate pureQuery code from a single SQL statement:

  1. Open the Generate pureQuery Code from an SQL Statement wizard by following one of these sets of steps:
    Option Description
    For an SQL string in Java code:
    1. Switch to the Java perspective.
    2. Open the .java file that contains the SQL string in the Java editor.
    3. In the editor, position the text cursor within the StringLiteral of a SELECT, INSERT, UPDATE, DELETE, or CALL statement, right-click, and then select Generate pureQuery Code.

    If the Generate pureQuery Code from a Table wizard opens instead, either the text cursor is not positioned in a StringLiteral or the text cursor is not positioned in one of the specific types of SQL statements.

    For an SQL statement in an SQL script that is open in the SQL and XQuery editor:
    1. In the editor, select an entire SELECT, INSERT, UPDATE, DELETE, or CALL statement.
    2. Right-click the selected statement, and then select Generate pureQuery Code.
    For an SQL statement in an SQL script in a pureQuery-enabled Java project:
    1. Switch to the Java perspective.
    2. Right-click the .sql file that contains the single SQL SELECT, INSERT, UPDATE, DELETE, or CALL statement, and then select Generate pureQuery Code.
    For an SQL statement in an SQL script in a data development project:
    1. Switch to the SQL and Routine Development perspective.
    2. Expand the SQL Scripts folder in the project.
    3. Right-click the script that contains the single SQL SELECT, INSERT, UPDATE, DELETE, or CALL statement, and then select Generate pureQuery Code.
    If the wizard does not open and a message box is displayed, review the error message to determine why the SQL statement is not valid.
  2. Complete the steps of the wizard. To see information about the fields in the wizard, press F1.
  3. Click Finish to generate the files that you specified.

Results

When you generate pureQuery code, the workbench creates a bean that you can use to access your database. For example, you can generate code from an UPDATE statement or a SELECT statement. When you generate code from a SELECT statement, the workbench creates a bean that you can use to hold query results. If you do not use AS clauses in SELECT statements that produce joins or unions, or that contain calculated columns, query results might contain columns with non-unique names. Whether the workbench is able to resolve this problem when generating a bean to represent query results depends on the type of database that your application uses.


Feedback