JDBC Query operator Invalid SQL error when using module parameters

JDBC Query operator Invalid SQL error when using module parameters

book

Article ID: KB0074037

calendar_today

Updated On:

Products Versions
TIBCO Streaming 7

Description

Given the SQL statement:
  select * from ${DB_NAME}.[dbo].${DB_TABLE} where [status] = 'ACTIVE' 

If DB_NAME and DB_TABLE are module parameters with valid default values, then typechecking will fail with this error:
    Invalid SQL expression 'select * from .[dbo]. where [status] = 'ACTIVE'': Incorrect syntax near the keyword 'where'. 

Issue/Introduction

Using module parameters in JDBC SQL statements requires also defining an output schema.

Resolution

Note: This issue has been corrected in TIBCO Streaming 10.6. It still affects TIBCO StreamBase 7.7 as of this writing.

If DB_NAME and DB_TABLE are module parameters with valid default values, those values are not available when the SQL statement is checked with the live JDBC database and 'null' values are substituted into the SQL statement.
    
If DB_NAME and DB_TABLE are global parameters with valid default values, then typechecking will succeed.
    
The reason is that Global parameters are substituted early in operator expressions and module parameters are substituted late. Global parameters are known immediately and module parameters are determined by their usage context after all parent and upstream settings are known. The SQL statement is typechecked before this has occurred.

As an alternative, you may use module parameters in the SQL statement when the Query operator output schema is known in advance by setting "SQL Result Fields" property to "Explicitly declare fields below". When this is set the SQL statement will not be checked. Its first use will be at run-time after the module has been compiled with module parameters known. At that time, the actual values of the module parameters as determined by the Module element in the parent application are available and will be used in the final SQL statement.