Was this helpful?
How the ~V Mechanism Works
In place of dynamic parameter markers (?) and embedded host variables (:host_var), you can form a query using the parameter marker ~V. A ~V marker can appear any place a dynamic parameter marker or embedded host variable is allowed. The ~V marker must be preceded and followed by a space character. Values for the parameter markers are sent with the query using IIapi_setDescriptor() and IIapi_putParms(), in the same order the parameter markers appear in the query text.
As an example, the following query:
select * from employee where dept = ~V and age > ~V
when sent with parameter values of 'admin' and 35 is identical to the query:
select * from employee where dept = 'admin' and age > 35
The advantage is that the query using ~V does not require the application to build the query text at runtime using values not available at compile time; neither does it require the use of a cursor to perform the query dynamically (prepared select statements can be executed only by opening a cursor for the prepared select statement).
Evaluation of a ~V marker occurs when the statement containing the marker is parsed. This occurs when the statement is executed directly, prepared as a dynamic statement, or defined as a repeat query. For parameters that should be evaluated when a prepared statement is executed, use dynamic parameter markers (?). For parameters that should be evaluated when a repeat query is executed, use extended $n = ~V markers, described next.
Last modified date: 08/14/2024