Databases Reference
In-Depth Information
Example 4-26 Printing SQLDA Fields
strncpy (test,"SELECT PID FROM inventory", sizeof(test));
/***********************************************
Call PREPARE INTO to prepare and describe the SQL statement. The
statement is equivalent to :
EXEC SQL PREPARE stmt INTO :*mysqlda FROM :test;
EXEC SQL EXECUTE stmt USING DESCRIPTOR :*mysqlda;
*************************************************/
EXEC SQL PREPARE stmt INTO :*mysqlda FROM :test;
printf("Number of columns(sqld)= %d\n", mysqlda->sqld);
printf("Number of SQLVARs(sqln)= %d\n", mysqlda->sqln);
printf("Column name (sqlname.data)= %s\n",
mysqlda->sqlvar[0].sqlname.data);
printf("Column name length (sqlname.length)= %d\n",
mysqlda->sqlvar[0].sqlname.length);
printf("Column datatype (sqltype)= %d\n", mysqlda->sqlvar[0].sqltype);
printf("Column length (sqllen)= %d\n", mysqlda->sqlvar[0].sqllen);
Running this produces the following output.
Example 4-27 Sample output of values stored in the SQLDA
Number of columns(sqld)= 1
Number of SQLVARs(sqln)= 2
Column name (sqlname.data)= PID
Column name length (sqlname.length)= 3
Column datatype (sqltype)= 448
Column length (sqllen)= 10
The result in Example 4-27 informs us that there are two SQLVAR elements
defined (sqln), and one column in the resultset returned (sqld). The name of the
column (sqlname.data) is PID which is of length (sqlname.length) 10 and of type
(sqltype) SQL_VARCHAR (448).
Although we defined two SQLVAR elements, we only really needed one
SQLVAR element because there is only one column returned by the SQL
statement. In the PREPARE of a SELECT statement, ideally the number of
SQLVAR elements defined should be equal to the number of columns expected
from the result set. If more SQLVARs are defined than is needed, more memory
Search WWH ::




Custom Search