HP NonStop SQL/MP Programming Manual page 211

For c
Table of Contents

Advertisement

Dynamic SQL Operations
A PREPARE statement prepares the statement in exec_statement from the host
variable update_statement:
PREPARE exec_statement FROM :update_statement;
To supply values for the UPDATE statement at run time, the program uses the two host
variables host_var1 and host_var2:
EXECUTE exec_statement USING :host_var1, :host_var2;
The value stored in host_var1 is used for both instances of the parameter named ?a.
The value stored in host_var2 is used for the parameter named ?b. If you use three
host variables, NonStop SQL/MP uses the value in the first host variable for both
occurrences of parameter ?a. The value in the second host variable is used for
parameter ?b, and the value in the third host variable remains unused.
For example, in this statement, NonStop SQL/MP uses the value in host_var1 for
both occurrences of parameter ?a and the value in host_var2 for parameter ?b. The
value in host_var3 is ignored.
EXECUTE exec_statement
USING :host_var1,:host_var2,:host_var3;
Caution. If you use the same parameter name more than once in a statement, NonStop
SQL/MP gives each duplicate occurrence of the parameter the same data type, length, and
other attributes as the first occurrence. As a result, data can be lost in some cases.
For example, during the execution of an INSERT statement, a parameter gets the same data
type and attributes as the column into which the parameter's value is first inserted. If the
parameter value is truncated to fit into the column, the values of any duplicate occurrences of
the parameter are also truncated, even if a column is large enough to hold the complete value.
Using Parameters in Loops
Parameters are often used when a dynamic SQL statement is run repeatedly with
different input values. In this example, a dynamic SQL statement uses a parameter.
Because the user of this program can enter any SQL statement, the program does not
have information about the statement during compilation. The TACL DEFINE named
=parts represents the PARTS table.
1. A user enters this SQL statement:
UPDATE =parts SET price = ?p
2. The program copies the statement into the host variable named intext.
3. The program uses the PREPARE and DESCRIBE INPUT statements to return a
description of the parameter in the input SQLDA structure (in_sqlda) and to get
the name of the parameter in the input names buffer (i_namesbuf). The prepared
statement is named exec_stmt.
EXEC SQL PREPARE exec_stmt FROM :intext;
EXEC SQL DESCRIBE INPUT exec_stmt INTO :in_sqlda
HP NonStop SQL/MP Programming Manual for C—429847-008
NAMES INTO :i_namesbuf;
10-13
Input Parameters and Output Variables
...

Advertisement

Table of Contents
loading

Table of Contents