SQL | NOSQL
Category
Language element control
Pragma equivalent
None.
Purpose
Enables the compiler to process embedded SQL statements.
Syntax
.-NOSQL-. >>-+-SQL---+--+----------------------------------+------------->< | .-,----------------------. | | V | | '-(----DB2 precompiler option-+--)-'
Defaults
NOSQL
Parameters
- DB2 precompiler option
- The SQL coprocessor options are only passed to the SQL statement coprocessor; the z/OS® XL C/C++ compiler does not act on any of the options. Refer to DB2® for z/OS Application Programming and SQL Guide at http://www.ibm.com/software/data/db2/zos/library.html for details.
Usage
You may use this option to compile C and C++ programs containing embedded SQL statements, that have not been pre-compiled by the DB2 Precompiler. When you specify this option, the compiler writes the database request module (DBRM Bind file) to the ddname DBRMLIB. This option is not supported under AMODE 64 (LP64 compiler option).
To use this option with the supplied proc, specify the required items in your JCL, as in the following example:
//SQLCOMP EXEC EDCC,
// CPARM='SQL',
// INFILE=PAYROLL.SOURCE(MASTER)'
//STEPLIB DD DSN=CEE.SCEERUN,DISP=SHR
// DD DSN=CEE.SCEERUN2,DISP=SHR
// DD DSN=CBC.SCCNCMP,DISP=SHR
// DD DSN=hlq.SDSNLOAD,DISP=SHR
//DBRMLIB DD DSN=PAYROLL.DBRMLIB.DATA(MASTER),DISP=SHR
where hlq.SDSNLOAD is a generic data set name.
An SQL INCLUDE statement is treated the same as an #include directive. The following two lines are processed the same way by the compiler:
EXEC SQL INCLUDE name;
#include "name"
The library search order for SQL INCLUDE statements is the same as specified in the LSEARCH option or the USERLIB ddname. Nested SQL INCLUDE statements, that are not supported with the DB2 Precompiler, are supported by the SQL compiler option.
For C++, host variable names do not need to be unique, as they are previously required to be by the DB2 Precompiler. You may declare host variables, using the SQL BEGIN DECLARE SECTION and SQL END DECLARE SECTION statements, of the same name but in different lexical scopes.
EXEC SQL BEGIN DECLARE SECTION;
int salary;
EXEC SQL END DECLARE SECTION;
main() {
EXEC SQL BEGIN DECLARE SECTION; /* (1) */
int salary;
EXEC SQL END DECLARE SECTION; /* (2) */
/* The local variable salary will be used here */
EXEC SQL SELECT SALARY INTO :salary FROM ctab WHERE EMPNO = 12345;
}
If the local variable has not been declared as host variable, that is, the SQL BEGIN DECLARE SECTION statement (1) and SQL END DECLARE SECTION statement (2) are missing, you will get a compiler error.
When you specify the DFP and SQL compiler options with the XL C/C++ compiler, decimal floating-point typed identifiers can be designated as host variables and used in embedded SQL statements. This will allow you to write applications with embedded SQL statements for DB2 databases containing decimal floating-point data. SQL for DB2 V9 provides support for decimal floating-point types through the DECFLOAT data type. For further information on the DFP type host variable, see the description for the DECFLOAT scalar function in the DB2 Version 9.1 for z/OS SQL Reference at http://www.ibm.com/software/data/db2/zos/library.html. For more information on the DFP compiler option, see DFP | NODFP.
Predefined macros
__SQL__ is predefined to 1 when the SQL compiler option is in effect; otherwise it is undefined.
- SQL_VARBINARY_INIT
- SQL_BLOB_INIT
- SQL_CLOB_INIT
- SQL_DBCLOB_INIT
#define SQL_VARBINARY_INIT(s) {sizeof(s)-1, s}
#define SQL_BLOB_INIT(s) {sizeof(s)-1, s}
#define SQL_CLOB_INIT(s) {sizeof(s)-1, s}
#define SQL_DBCLOB_INIT(s) {(sizeof(s)/2)-1, s} (31-bit mode)
#define SQL_DBCLOB_INIT(s) {(sizeof(s)/4)-1, s} (64-bit mode)
Refer to DB2 Version 9.1 for z/OS SQL Reference at http://www.ibm.com/software/data/db2/zos/library.html for further information on the VARBINARY, BLOB, CLOB, and DBCLOB functions that are related to these macros.