Preparing SQLDA for Data Input and Output
The SQLDA data structure contains descriptive information about each input parameter or output column. The structure contains the column name, data type, length, and a pointer to the actual data buffer for each input or output parameter.
For output data that uses the SQLDA data structure, you can use the DESCRIBE statement (or the PREPARE statement with the INTO option) to enter the column name, data type, and other data into the appropriate fields of the SQLDA data structure. DESCRIBE also sets sqld to the number of dynamic host variables used in the SQL statement being described.
Before using the SQLDA data structure in a PREPARE INTO or DESCRIBE statement, your application must set the size of the SQLDA data structure in bytes and the maximum number of entries. These numbers are reflected in the sqldabc and sqln fields, respectively.
Before performing a FETCH statement, the application must insert into the sqldata field the address of each program variable that will receive the data from the corresponding column. (The sqldata field is part of sqlvar within the SQLDA data structure.) If indicator variables are used, sqlind must also be set to the corresponding address. The data type field (sqltype) and length field (sqllen) are filled with information in the Microsoft® SQL Server™ 2000 column from a PREPARE INTO or a DESCRIBE statement. The value in the data type and length fields can be overridden by the application before a FETCH statement is executed. The sqltype code and the sqld address that are assigned must be one of the valid data types listed in Valid Values for sqltype. For more information, see Valid Values for sqltype.
Before the DESCRIBE or PREPARE statement is issued, the value of sqln must be set higher than the anticipated number of output columns. If the number of columns is unknown, you can set sqln to 0, and then issue a DESCRIBE statement. No column detail information is moved into the SQLDA data structure, but the number of columns in the result set is inserted into sqld.
To use the SQLDA data structure for input data, your application must supply data for the fields of the entire SQLDA data structure, including the sqln, sqld, sqldabc, sqltype, sqllen, and sqldata fields for each variable. If the sqltype field has an odd code number (value), the address of the indicator variable must also be supplied.