SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Host Variables in C/C++ Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
3-29
Host Variables as Data Members of a C++ Class
Host Variables as Data Members of a C++ Class
You can include an SQL Declare Section within a class definition to use a data
member of a class as a host variable.
Example
This example uses a class named jobsql, containing the declarations of the
memhv_jobcode and memhv_jobdesc host variables. These host variables are
referenced in the member function putjob defined in the class:
class jobsql {
// Class member host variables
EXEC SQL BEGIN DECLARE SECTION;
unsigned NUMERIC (4) memhv_jobcode;
VARCHAR memhv_jobdesc[19];
EXEC SQL END DECLARE SECTION;
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-12.
C++