Host variable names in C and C++ embedded SQL applications
The SQL precompiler
identifies host variables by their declared name.
The following rules apply when declaring host variable names:
- Host variable names must be no longer than 255 characters in length.
- Host variable names must not use the prefix
SQL
,sql
,DB2
, anddb2
, which are reserved for system use. For example:EXEC SQL BEGIN DECLARE SECTION; char varsql; /* allowed */ char sqlvar; /* not allowed */ char SQL_VAR; /* not allowed */ EXEC SQL END DECLARE SECTION;
- The precompiler supports the same scope rules as the C and
C++ programming languages. Therefore, you can use the same name for
two different variables each existing within their own scope. In the
following example, both declarations of the variable called empno
are allowed; the second declaration does not cause an error:
file: main.sqc ... void scope1() { EXEC SQL BEGIN DECLARE SECTION ; short empno; EXEC SQL END DECLARE SECTION ; ... } void scope2() { EXEC SQL BEGIN DECLARE SECTION ; char[15 + 1] empno; /* this declaration is allowed */ EXEC SQL END DECLARE SECTION ; ... }