SQL/MP Programming Manual for C

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C429847-008
10-34
Allocate and Fill In Output Variables
EMPNAME CATHERINE WILLIAMS
EMPNUM 1890
EMPNAME RICHARD SMITH
You can also display the column names as headings (similar to SQLCI) by executing
this loop for output_num iterations:
1. Get the length of the column name.
2. Advance to the name.
3. Display the name with some blank space.
4. Advance to the next length field.
If you use this second method, you must execute a second loop to interpret and
display the values, including enough blank space for each value to fall under its column
heading.
You can use data type literals to decide how to display output column values.
Example 10-6 displays output.
Example 10-6. Displaying Output (page 1 of 2)
/* Declare, open, fetch, and close the cursor. */
/* (for code, see sample program) */
int display_result ( sqldaptr output_sqlda_ptr,
char *output_namesbuf_ptr )
{
int *len_ptr; /* Pointer to get length info */
/* from the names buffer */
int name_len; /* Number of bytes in column name */
int num_entries; /* Number of columns to be output */
int i; /* loop counter */
char data_array[39]; /* Buffer to contain data to be */
/* displayed (null terminated) */
char *data_ptr; /* Pointer to retrieved data */
int data_len; /* Data buffer size */
char name_array[40]; /* Buffer for null terminated */
/* column name, in the format */
/* tablename.colname */
/* ( 8 + 1 + 30 characters ) */
char *lastchar; /* Last character read */