SQL/MP Programming Manual for C

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C429847-008
10-35
Allocate and Fill In Output Variables
num_entries = output_sqlda_ptr->num_entries;
for (i=0; i < num_entries; i++)
{
/* Position output_namesbuf_ptr to the length prefix in */
/* the names buffer, store the length in name_len, move */
/* the pointer past the prefix and onto a name, and store*/
/* the column name in name_array. Code is the same as */
/* that used for input parameter names (See "Getting */
/* Parameter Values"), except that when no name is */
/* supplied, name_array should be assigned the string */
/* "(EXPR)". */
/* If you want to display the column names once (as SQLCI*/
/* does), rather than repetitively with each FETCH, */
/* display all the names at this point. The remaining */
/* code here assumes a repetitive display of column names*/
/* and their associated values. */
switch (output_sqlda_ptr->sqlvar[i].data_type)
{
case _SQLDT_ASCII_F : /* char data type */
data_ptr = (char *)output_sqlda_ptr->sqlvar[i].var_ptr;
data_len = output_sqlda_ptr->sqlvar[i].data_len;
...
strncpy (data_array, data_ptr, data_len);
data_array[data_len] = '\0';
printf( "%-40s %s\n", name_array, data_array);
...
break;
...
/* Continue to handle all the possible data types for */
/* output values and write the data pointed to by */
/* the var_ptr field in the output SQLDA in a format */
/* depending on the data type. */
/* (For complete code, see sample program.) */
} /* End of SWITCH statement to display values */
/* according to data type */
} /* End of loop to process each column */
}
Example 10-6. Displaying Output (page 2 of 2)