Assign and obtain values from an sqlda structure
When you use the sqlda structure with dynamic SQL, you must transfer information in and out of it with C-language statements.
Assign values
da_ptr->sqld = 1;
da_ptr->sqlvar[0].sqldata = compny_data;
da_ptr->sqlvar[0].sqltype = SQLCHAR; /* CHAR data type */
da_ptr->sqlvar[0].sqllen = 21; /* column is CHAR(20) */
Set sqlda fields to provide values for input parameters in a WHERE clause (Specify input parameter values) or to modify the contents of a field after you use the DESCRIBE...INTO statement to fill the sqlda structure (Allocate memory for column data).
Obtain values
To obtain values from the sqlda fields, you must also use regular C-language assignment from fields of the structure. For example:
count = da_ptr->sqld;
/* Allow for the trailing null character in C character arrays */
if (da_ptr->sqlvar[0].sqltype == SQLCHAR)
a_ptr->sqlvar[0].sqllen += 1;
/* Allocate a separate buffer per column */
da_ptr->sqlvar[0].sqldata = malloc(col_ptr->sqllen);
Typically, you obtain sqlda field values to examine descriptions of columns in a SELECT, INSERT, or EXECUTE FUNCTION statement. You might also need to access these fields to copy a column value that is returned by the database server from the sqlda structure into a host variable (Put column values into an sqlda structure). In the latter case, you might need to change sqllen to account for the correct buffer length. For example, you must increment sqllen for a CHAR data type. If you do not increment sqllen, the last character of the fetched data will be truncated because the FETCH statement will assume that the sqllen value is the size of the buffer, and will use the last position in the buffer for the zero termination of the string.
The data type of the host variable must be compatible with the type of the associated field in the sqlda structure. When you interpret the sqltype field, make sure that you use the data type values that match your environment. For some data types, X/Open values differ from HCL OneDB™ values. For more information, see Determine the data type of a column.