SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
C Sample Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
A-19
Using a Dynamic SQL Cursor With Descriptor Area
void run_dynTest(char *chstr)
{
char SQLSTATE_OK[6]="00000";
char SQLSTATE_NODATA[6]="02000";
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR in_curspec[256];
long desc_max;
EXEC SQL END DECLARE SECTION;
exec sql declare schema 'SQL12.mysch';
exec sql set schema 'SQL12.mysch';
printf("\n\nThis example uses a dynamic cursor with desc area.
\n\n");
EXEC SQL WHENEVER SQLERROR CALL sql_error;
/* Allocate the descriptor area for output parameters. */
desc_max=100;
EXEC SQL ALLOCATE DESCRIPTOR 'out_sqlda' WITH MAX :desc_max;
/* Input cursor specification. */
/*
printf("\nEnter cursor specification (use fully-qualified table
name):\n");
gets(in_curspec);
*/
strcpy(in_curspec,chstr);
printf("%s\n", in_curspec);
/* Prepare the cursor specification. */
EXEC SQL PREPARE cursor_spec FROM :in_curspec;
EXEC SQL DESCRIBE OUTPUT cursor_spec USING SQL DESCRIPTOR
'out_sqlda';
/* Declare the dynamic cursor from the prepared statement. */
EXEC SQL DECLARE get_row CURSOR FOR cursor_spec;
/* Open the cursor using the value of the dynamic parameter. */
EXEC SQL OPEN get_row;
/* Fetch the first row of the result table. */
EXEC SQL FETCH get_row
INTO SQL DESCRIPTOR 'out_sqlda';
Example A-7. Using a Dynamic SQL Cursor With Descriptor Areas (page 2 of 8)