Program structure for results processing

Table 5-7 shows the loop structure for processing the types of results that might be seen in a DB-Library program. Table 5-8 shows the equivalent Client-Library program logic.

Table 5-7: DB-Library results loop structure

Loop control

while ((results_ret = dbresults(dbproc)) != 
NO_MORE_RESULTS)
{
    if (results_ret == SUCCEED)
    {

Retrieve regular and compute rows

       Bind regular rows.
       Bind compute rows.
       while (dbnextrow(dbproc) 
                != NO_MORE_ROWS)
       {
          Retrieve regular and compute rows.
       } /* while */

Retrieve return parameter values

       if (dbnumrets(dbproc) > 0)
       {
          Retrieve output parameter values.
       }

Retrieve return status values

       if (dbhasretstatus(dbproc))
       {
          Retrieve stored procedure return status.
       }

(optional) Get statistics

       if (DBROWS(dbproc) != -1)
       {
          Find out number of rows affected.
       }

Command error checking (server-side or client-side)

    } /* if results_ret == SUCCEED */
    
    else if (results_ret == FAIL)
    {
        printf( "Command failed");
    }
} /* while */

Table 5-8 shows the results-loop structure for a typical Client-Library program:

Table 5-8: Client-Library results loop structure

Loop control

while ((results_ret = ct_results(cmd, &result_type)) 
              == CS_SUCCEED)
{
    switch(result_type)
    {

Retrieve regular and compute rows

        case CS_ROW_RESULT:
            Bind regular rows.
            Fetch regular rows.
        break;
  
        case CS_COMPUTE_RESULT:
            Bind compute rows.
            Fetch compute rows.
        break;

Retrieve return parameter values

        case CS_PARAM_RESULT:
            Bind output parameter values.
            Fetch output parameter values.
        break;

Retrieve return status values

        case CS_STATUS_RESULT:
            Bind stored procedure return status.
            Fetch stored procedure return status.
        break;

(optional) Get statistics

        case CS_CMD_DONE:
            Find out number of rows affected.
        break;

Command error checking (server-side)

        case CS_CMD_FAIL:
            printf("Command failed on server.")
        break;

        case CS_CMD_SUCCEED:
        break;

Command error checking (client-side)

        default: /* case */
            printf("Unexpected result type");
        break;
  
    } /* end switch */
} /* end while */
if (results_ret != CS_END_RESULTS 
    && results_ret != CS_CANCELED)
    printf("ERROR: ct_results failed!");