Declaration of fixed-length, null-terminated and variable-length character host variables in C and C++ embedded SQL applications

There are two forms of C and C++ variables that you can declare in an embedded SQL application. Form 1 variables are fixed length and null-terminated character host variables and form 2 are variable-length character host variables.

Form 1: Syntax for fixed and null-terminated character host variables in C or C++ embedded SQL applications

Read syntax diagramSkip visual syntax diagramautoexternstaticregisterconstvolatileunsignedchar ,CHARC String=value
CHAR
Read syntax diagramSkip visual syntax diagram*&constvolatilevarname1
C String
Read syntax diagramSkip visual syntax diagramvarname(*&constvolatilevarname)[length]2
Read syntax diagramSkip visual syntax diagram;
Notes:
  • 1 CHAR (SQLTYPE 452), length 1
  • 2 Null-terminated C string (SQLTYPE 460); length can be any valid constant expression

Form 2: Syntax for variable-length character host variables in C and C++ embedded SQL applications

Read syntax diagramSkip visual syntax diagramautoexternstaticregisterconstvolatilestructtag {shortint var1;unsigned charvar2 [length]1 ;},*&constvolatilevarnameValues
Values
Read syntax diagramSkip visual syntax diagram={value-1,value-2}
Read syntax diagramSkip visual syntax diagram;
Notes:
  • 1 In form 2, length can be any valid constant expression. Its value after evaluation determines if the host variable is VARCHAR (SQLTYPE 448) or LONG VARCHAR (SQLTYPE 456).
Variable-Length Character Host Variable Considerations:
  1. Although the database manager converts character data to either form 1 or form 2 whenever possible, form 1 corresponds to column types CHAR or VARCHAR, whereas form 2 corresponds to column types VARCHAR and LONG VARCHAR.
  2. If form 1 is used with a length specifier [n], the value for the length specifier after evaluation must be no greater than 32 672, and the string contained by the variable should be null-terminated.
  3. If form 2 is used, the value for the length specifier after evaluation must be no greater than 32 700.
  4. In form 2, var1 and var2 must be simple variable references (no operators), and cannot be used as host variables (varname is the host variable).
  5. varname can be a simple variable name, or it can include operators such as *varname. See the description of pointer data types in C and C++ for more information.
  6. The precompiler determines the SQLTYPE and SQLLEN of all host variables. If a host variable appears in an SQL statement with an indicator variable, the SQLTYPE is assigned to be the base SQLTYPE plus one for the duration of that statement.
  7. The precompiler permits some declarations which are not syntactically valid in C or C++. Refer to your compiler documentation if in doubt about a particular declaration syntax.