SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Embedded SQL Statements
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
2-5
Executable SQL Statements
Diagnostics statement
Data Definition Language (DDL) statements
Data Manipulation Language (DML) statements
Transaction control statements
Object naming statements
Data Control Language (DCL) statements
Utilities (UPDATE STATISTICS)
For a list of executable SQL statements, see Table 2-4 on page 2-8.
Executable SQL Statements in C++ Programs
In a C++ program, you can include embedded SQL statements that refer to host
variables declared within a class definition only in member functions of the class within
the scope of the class definition. However, you can include both of these types of
embedded SQL statements within the same C++ program:
Statements that refer to host variables declared within a class definition
Statements that refer to host variables not declared within a class definition
Example
// Non-class member host variables
EXEC SQL BEGIN DECLARE SECTION;
unsigned NUMERIC (4) nonmemhv_jobcode;
EXEC SQL END DECLARE SECTION;
...
class jobsql {
// Class member host variables
EXEC SQL BEGIN DECLARE SECTION;
unsigned NUMERIC (4) memhv_jobcode;
EXEC SQL END DECLARE SECTION;
public:
void deljob(){
memhv_jobcode = 1234;
EXEC SQL DELETE FROM persnl.job
WHERE jobcode = :memhv_jobcode;
}
}; // End of jobsql class definition
...
main(){
jobsql mysql; // Instantiate a member of the class jobsql
...
// Delete job code 1234
mysql.deljob();
...
// Delete another job code 5678
nonmemhv_jobcode = 5678;
EXEC SQL DELETE FROM persnl.job
WHERE jobcode = :nonmemhv_jobcode;
} // End of main
In this example, a DELETE statement is executed twice within main(): the first time
as a member function that consists of an embedded SQL statement, and the second
C++