SQL/MX 3.2.1 Programming Manual for C and COBOL (H06.26+, J06.15+)

Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.2.1 Programming Manual for C and COBOL663854-005
3-41
Using Indicator Variables in a C/C++ Program
public:
void putjob(){
EXEC SQL
INSERT INTO persnl.job
VALUES (:memhv_jobcode, :memhv_jobdesc);
}
}; // End of jobsql class definition
main(){
...
jobsql mysql; // Instantiate a member of the class jobsql
// Insert job code in table
mysql.putjob();
} // End of main
Using Indicator Variables in a C/C++ Program
Null in an SQL column indicates that a value is either unknown or is not applicable. A
host language program uses an indicator variable to insert null. It also uses an
indicator variable to test for null or a truncated output value.
An indicator variable is an exact numeric variable associated with the host variable that
sets or receives the actual column value. The INVOKE directive automatically declares
indicator variables for columns that allow null.
A host language program can use an indicator variable to:
Insert values into a database with an INSERT or UPDATE statement.
Test for null or a truncated value (in the case of character data) after retrieving a
value from a database with a SELECT INTO or FETCH statement.
For more information on indicator variables, see Specifying Host Variables in SQL
Statements on page 3-15.
Inserting Null
To insert values into columns that allow null with an INSERT or UPDATE statement,
you must set the indicator variable to a value less than zero for null or zero for a
nonnull value before executing the statement.
Example
This example uses a statement that inserts values into the ODETAIL table. The
columns UNIT_PRICE and QTY_ORDERED allow null. To insert null, declare and use
an indicator variable:
EXEC SQL BEGIN DECLARE SECTION;
...
short ind_1 = -1;
EXEC SQL END DECLARE SECTION;
...
EXEC SQL INSERT INTO sales.odetail
(ordernum, partnum, unit_price, qty_ordered)
C