In a C program, execute a DESCRIBE statement with an SQLDA that has no occurrences of SQLVAR entries. If SQLD is greater than zero, use the value to allocate an SQLDA with the necessary number of occurrences of SQLVAR entrires and then execute a DESCRIBE statement using that SQLDA.
EXEC SQL BEGIN DECLARE SECTION; char stmt1_str [200]; EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE SQLDA; struct sqlda mja; struct sqlda *mjap; EXEC SQL DECLARE DYN_CURSOR CURSOR FOR STMT1_NAME; ... /* code to prompt user for a query, then to generate */ /* a select-statement in the stmt1_str */ EXEC SQL PREPARE STMT1_NAME FROM :stmt1_str; ... /* code to set SQLN to zero and to allocate the SQLDA */ EXEC SQL DESCRIBE STMT1_NAME INTO :mja; if (mja.sqld == 0); else { ... /* Code to re-allocate the SQLDA and set mjap */ . . . if (strcmp(SQLSTATE,"01005") == 0) { mjap->sqln = 2*mja.sqld; SETSQLDOUBLED(mjap, SQLDOUBLED); } else { mjap->sqln = mja.sqld; SETSQLDOUBLED(mjap, SQLSINGLED); } EXEC SQL DESCRIBE STMT1_NAME INTO :newda; } ... /* code to prepare for the use of the SQLDA */ EXEC SQL OPEN DYN_CURSOR; ... /* loop to fetch rows from result table */ EXEC SQL FETCH DYN_CURSOR USING DESCRIPTOR :mja; . . .
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.