sqlLiteralSubstitution property

Specifies whether to perform literal substitution. When this option is enabled, pureQuery Runtime attempts to replace literal values in SQL statements with parameter markers and capture the parameterized versions of the statements. Your application can then run those SQL statements statically and benefit from the security and speed of static SQL. If your application runs SQL statements that share the same syntax and differ only in the literal values that they contain, you can capture and consolidate those statements.

Your application might, for example, generate INSERT statements that are identical syntactically, but that include literal values that are provided by users in the fields of a form.

Normally, you would not be able to run these statements statically because they are generated at run time. However, pureQuery® client optimization can capture such statements by replacing the literal values with parameter markers and recognizing when the syntax of an SQL statement is identical to that of a statement that it already captured. You can therefore bind these SQL statements into DB2® packages.

When you run your application with the client optimization property executionMode set to STATIC, pureQuery can match SQL statements to the parameterized SQL statements that it captured. Matching statements run statically. The matched statements run on the database.

If your application runs SQL statements dynamically, you can benefit from the security of running only the captured statements with the literals replaced by parameter markers. You set the value of the pureQuery Runtime property capturedOnly to TRUE.

Topic sections

Example

When you set the client optimization properties before capturing SQL statements, set the property sqlLiteralSubstitution to ENABLE, as in this example:

pdqProperties=captureMode (ON), executionMode (DYNAMIC), 
pureQueryXml	(C:/workspace/capture_file.pdqxml), 
sqlLiteralSubstitution (ENABLE)

When your application runs an INSERT statement like the first statement in the next example, pureQuery captures it in the form of the second statement:

insert into EMPLOYEES/*inserting new row into EMPLOYEES table*/values('Dong','Margaret',NULL,60000,12)

insert into EMPLOYEES values(?,?,?,?,?)
Note: In the CLI application environment, the NULL is not replaced with parameter marker, and the comments within the SQL statement are not removed.

After you finish capturing statements, you can run the Configure utility on the capture_file.pdqxml file, and then run the StaticBinder utility to bind the statements into DB2 packages.

When you run the application with value of the executionMode property set to STATIC and the application issues the statement insert into EMPLOYEES values('Hinkis','Tali','R',68000,20), pureQuery matches the statement to the parameterized version in the pureQueryXML file and runs it statically.

However, you can tell pureQuery not to match SQL statements with parameterized statements in the capture_file.pdqxml file. Before you run the application, when you set executionMode to STATIC you can also set sqlLiteralSubstitution to DISABLE. When you run the application and it issues the INSERT statement in the previous paragraph, whether pureQuery runs the statement depends on the values of the client optimization properties capturedOnly and allowDynamicSQL.

Setting the values of the sqlLiteralSubstitution property

The following table lists the three values of the sqlLiteralSubstitution property and their effects when capturing SQL statements. The table also shows what happens when you do not set a value for this property.

Table 1. The effects of setting or not setting a value for the sqlLiteralSubstitution property
Value Effects when you capture statements for the first time Effects when you incrementally capture Effects when you run the application in either STATIC or DYNAMIC mode
ENABLE pureQuery replaces literal values with parameter markers.

pureQuery also captures the stack trace for the original SQL statements. If you want pureQuery to capture stack traces for all of the original SQL statements, you might need to increase the value of the property maxStackTracesCaptured.1

pureQuery does not count the original SQL statements against the value of the property maxNonParmSQL.

If pureQuery cannot parameterize an SQL statement and log level is FINE or FINER, it logs a warning message. For information about logged warning messages, see SQL literal replacement
The effects are the same as when you capture SQL statements for the first time. pureQuery tries to match SQL statements that the application attempts to run to parameterized SQL statements in a pureQueryXML file. 2
DISABLE pureQuery does not replace literal values with parameter markers. pureQuery does not replace literal values with parameter markers. pureQuery does not try to match SQL statements that the application attempts to run to parameterized SQL statements in a pureQueryXML file.
NOT_SET (or not specified) pureQuery does not replace literal values with parameter markers. If the value was ENABLE when pureQuery last captured statements in the specified pureQueryXML file, pureQuery replaces literal values with parameter markers when possible.

If the value was DISABLE or NOT_SET, pureQuery does not replace literal values with parameter markers.
If the value was ENABLE when pureQuery last captured statements in the specified pureQueryXML file, pureQuery tries to match SQL statements that the application attempts to run to parameterized SQL statements in a pureQueryXML file.

If the value was DISABLE or NOT_SET, pureQuery does not try to match SQL statements that the application attempts to run to parameterized SQL statements in a pureQueryXML file.
Note:
  1. The property maxStackTracesCaptured and stack traces are not supported in a CLI application environment.
  2. If pureQuery Runtime cannot match a parametrized SQL statement the pureQueryXML file, pureQuery Runtime behavior depends on the value of captureMode property:
    • If the value of captureMode is ON and pureQuery Runtime determines that literal substitution is supported for the SQL statement, pureQuery executes and captures the parameterized SQL statement.
    • If the value of captureMode is OFF, pureQuery Runtime then looks for the original (non-parametrized) SQL statement in the pureQueryXML file. pureQuery Runtime either executes the statement or throws an exception. The pureQuery action depends on whether it finds the statement in the file and on the values of the pureQuery Runtime properties allowDynamicSQL and capturedOnly.

    If you enable SQL statement literal substitution without specifying a pureQueryXML file, pureQuery Runtime replaces literal values in SQL statement with parameter markers before running the statement. You do not have to capture SQL statement and create a pureQueryXML file. The statements are run dynamically, they do not need to be run statically. However, you cannot enable other pureQuery Runtime options that require a pureQueryXML file such as capturedOnly and executionMode.

  3. For DB2 for z/OS V10 and above: If your application uses SET SESSION TIME ZONE and your environment has the sqlLiteralSubstitution property set to ENABLE, make sure that the setting for IMPLICIT_TIMEZONE in your DB2 for z/OS DSNHDECP structure is SESSION. Any other setting might cause incorrect values to be used as the TIME ZONE portion of a TIMESTAMP WITH TIME ZONE column or parameter.

Casting

Beginning with version 2.2.0.1, pureQuery Runtime supports two types of casting when replacing literal values with parameter markers.

SQL literal substitution for any of the parameters in CAST functions is not supported in a CLI application environment.

CAST function
When an SQL statement uses the CAST function to cast a literal value to a data type, pureQuery replaces that value with a parameter marker.

For example, if a statement contains the clause WHERE mySMALLINTcolumn=CAST(99 as INTEGER), the value 99 becomes a parameter marker when the statement is captured.

To take another example, if you use the CAST function CAST(6 as DECIMAL(7,3)), only the 6 becomes a parameter marker when the statement is captured.

User-defined external scalar functions that are named CAST are not supported.

Implicit casting
pureQuery Runtime performs implicit casting between string and datetime constants.
Converting strings to datetime constants
INSERT INTO DEPARTMENT VALUES(1,5,56,'000010','A00','aa','2008-09-09')

pureQuery Runtime does not perform any other types of implicit casting.

SQL literal replacement

DB2 CLI and IBM Data Server Driver usage notes

When using DB2 Call Level Interface (CLI) or the IBM Data Server Driver with pureQuery Runtime, you can use the pureQuery Runtime property as a configuration keyword.

IBM CLI keyword syntax
sqlLiteralSubstitution = ENABLE | DISABLE | NOT_SET
IBM Data Server Driver configuration syntax
<parameter name="sqlLiteralSubstitution" value="ENABLE | DISABLE | NOT_SET" />
Equivalent IBM Data Server Provider for .NET connection string keyword
sqlLiteralSubstitution=ENABLE | DISABLE | NOT_SET

Enabling SQL literal substitution without a pureQueryXML file

You can enable SQL literal substitution without specifying a pureQueryXML file. You do not have to capture SQL statement and create a pureQueryXML file. The statements are run dynamically, they do not need to be run statically.

The following sample db2dsdriver.cfg configuration file enables the sqlLiteralSubstitution keyword and does not contain the pureQueryXml keyword.
<configuration>
  <dsncollection>
    <dsn alias="sample",name="sample",host="server1.test.com", port="50001">
      <parameter name="sqlLiteralSubstitution", value="ENABLE"/>
    </dsn>
  </dsncollection>
  <databases>
    <database name="sample", host=" server1.test.com", port="50001">
    </database>
  </databases>
</configuration>
For CLI or .NET applications enabled with pureQuery client optimization, pureQuery Runtime replaces literal values in SQL statement with parameter marker before attempting to run the statement dynamically.

Feedback