Field descriptions of an occurrence of a base SQLVAR

The fields of a base SQLVAR have different uses depending on the SQL statement.

The following table describes the contents of the fields of a base SQLVAR.

Table 1. Fields in an occurrence of a base SQLVAR
C name
assembler
COBOL, or
PL/I name
 Data
type
Usage in DESCRIBE1
and PREPARE INTO
Usage in FETCH, OPEN,
EXECUTE, and CALL
sqltype
SQLTYPE
SMALLINT Indicates the data type of the column or parameter and whether it can contain null values. For a description of the type codes, see Table 1.

For a distinct type, the data type on which the distinct type was based is placed in this field. The base SQLVAR provides no indication that this is part of the description of a distinct type.

Indicates the data type of the host variable and whether an indicator variable is provided. Host variables for datetime values must be character string variables. For FETCH, a datetime type code means a fixed-length character string. For a description of the type codes, see SQLTYPE and SQLLEN.
sqllen
SQLLEN
SMALLINT The length attribute of the column or parameter. For datetime data, the length of the string representation of the value. See SQLTYPE and SQLLEN for a description of allowable values.

For LOBs, the value is 0 regardless of the length attribute of the LOB. For XML, the value is 0. Field SQLLONGLEN in the extended SQLVAR contains the length attribute.

The length attribute of the host variable. See SQLTYPE and SQLLEN for a description of allowable values.

For LOBs, the value is 0 regardless of the length attribute of the LOB. Field SQLLONGLEN in the extended SQLVAR contains the length attribute.

For XML AS BLOB, CLOB, or DBCLOB, sqllen is 0 as for LOB types.

sqldata
SQLDATA
pointer For string columns or parameters, SQLDATA contains X'0000zzzz', where zzzz is the associated CCSID. For character strings, SQLDATA can alternatively contain X'FFFF', which indicates bit data. Not used for other types of data.

For datetime columns, SQLDATA can contain the CCSID of the string representation of the datetime value.

For DESCRIBE PROCEDURE, the result set locator value associated with the result set.

Contains the address of the host variable.
sqlind
SQLIND
pointer Reserved

For DESCRIBE PROCEDURE, it is set to -1.

Contains the address of an associated indicator variable, if SQLTYPE is odd. Otherwise, the field is not used.
sqlname
SQLNAME
VARCHAR(30) Contains the unqualified name or label of the column, or a string of length zero if the name or label does not exist. If the name is longer than 30 bytes, it is truncated at a byte boundary. For more information about column names, see Names of result columns.

For DESCRIBE PROCEDURE, SQLNAME contains the cursor name used by the stored procedure to return the result set. The values for SQLNAME appear in the order the cursors were opened by the stored procedure.

For DESCRIBE INPUT, SQLNAME is not used.

Can contain CCSID and/or host-variable-array dimension information. DB2® interprets the third and fourth byte of the data portion of SQLNAME as the CCSID of the host variable if all of the following are true and the third and fourth byte are not X'0000':
  • The 6th byte of SQLDAID is '+' (x'4E')
  • SQLTYPE indicates the host variable is a string variable
  • The length of SQLNAME is 8
  • The first two bytes of the data portion of SQLNAME are X'0000'.
If the third and fourth byte of the data portion of SQLNAME are X'0000', DB2 uses the appropriate default CCSID.

For FETCH, OPEN, INSERT, and EXECUTE, if the length of SQLNAME is 8, and the first two bytes of the data portion of SQLNAME are X'0000', DB2 interprets the fifth through eighth bytes of the data portion of the SQLNAME field as follows:

(cont.)
sqlname
SQLNAME
   
  • fifth and sixth bytes: a flag field that indicates the type of host variable that is being described by the current SQLDA entry. The values of this field are as follows:
    • X'0000' - host variable
    • X'0100' - XML host variable ( XML AS BLOB, XML AS CLOB, XML AS DBCLOB)
    • X'0001' - host variable array
    • X'0101' - XML host variable array
    • X'0002' - special host variable that represents the value for 'n' in a multiple-row INSERT statement.
  • seventh and eighth bytes: if the sixth byte is X'01', a binary small integer (halfword) that represents the dimension of the host-variable-array, and the corresponding indicator-array if one is specified.
Notes:
  1. The third column of this table represents several forms of the DESCRIBE statement.
    • For DESCRIBE output and PREPARE INTO, the column pertains to columns of the result table.
    • For DESCRIBE CURSOR, the column pertains to a result set associated with a cursor.
    • For DESCRIBE INPUT, the column pertains to parameter markers.
    • For DESCRIBE PROCEDURE, the column pertains to the result sets returned by the stored procedure.