SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Embedded SQL Statements
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
2-3
Host Variable Declarations
•
Code INVOKE directives that generate structure descriptions of tables or views
within the Declare Section.
•
Use END DECLARE SECTION to mark the end of the Declare Section.
For a list of SQL statements allowed in the SQL Declare Section, see Table 2-2 on
page 2-6. For detailed information on each statement and the proper syntax, see the
SQL/MX Reference Manual.
C Host Variables
In a C program, you cannot include a function declaration within an SQL Declare
Section. As a result, you cannot declare the arguments of a C function as host
variables. To use argument values in an embedded SQL statement, you must copy the
argument values to host variables.
The SQL/MX C/C++ preprocessor, which is initiated by the mxsqlc command,
requires the EXEC SQL BEGIN... END DECLARE SECTION block to contain only host
variable declarations and SQL or host language comments. Any executable code in
this block is not processed and could cause the preprocessor to return error
messages.
Example
EXEC SQL BEGIN DECLARE SECTION;
...
unsigned NUMERIC (4) jobcode; /* host variables */
char jobdesc[19];
EXEC SQL INVOKE persnl.employee AS emp_tbl;
struct emp_tbl emp;
EXEC SQL END DECLARE SECTION;
C++ Host Variables Within a Class Definition
In a C++ program, you can include an SQL Declare Section within a class definition to
use a data member of a class as a host variable. References to host variables
declared within a class definition must be in member functions of the class. In a C++
program, you cannot include a class definition within an SQL Declare Section.
Example
class jobsql {
// class member host variables
EXEC SQL BEGIN DECLARE SECTION;
unsigned NUMERIC (4) memhv_jobcode;
char memhv_jobdesc[19];
EXEC SQL END DECLARE SECTION;
public:
...
void putjob(){
EXEC SQL
INSERT INTO persnl.job
VALUES (:memhv_jobcode, :memhv_jobdesc);
C
C++