Progress
Embedded SQL-92
Guide and Reference


SQLDA for Output Variables

For a dynamic SQL query, a DESCRIBE statement is required to associate items in the SELECT list with an output SQLDA. You use the DESCRIBE SELECT statement for the OUTPUT SQLDA. This is the syntax for a DESCRIBE SELECT LIST FOR statement:

SYNTAX
EXEC SQL
  DESCRIBE SELECT LIST FOR statement_name INTO output_sqlda_name ; 

The DESCRIBE SELECT statement must occur after the PREPARE, DESCRIBE BIND, and OPEN statements, and before the FETCH statement.

EXAMPLE

The following example shows how to use the DESCRIBE SELECT statement:

struct sqlda *osqlda = (struct sqlda *)0 ;
strcpy (stmt, "select qty, product from orders where order_no < :p1") ;
EXEC SQL PREPARE stmtid FROM :stmt ;
EXEC SQL DECLARE dyncur CURSOR FOR stmtid ;
for (order_no_v = 1002 ; order_no_v <= 1004 ; order_no_v++)
{
     EXEC SQL OPEN dyncur USING :order_no_v ;
     /* maxvars = 2, varnmsz = 20 */
     if (!(osqlda = PRO_SQLDA_Allocate(2, 20)))
     {
           printf ("PRO_SQLDA_Allocate returned err\n") ;
          goto err ;
     }
     for (;;)
     {
          short  nvars ;
          EXEC SQL DESCRIBE SELECT LIST FOR stmtid INTO osqlda ;
          if ((nvars = osqlda->sqld_nvars) < 0)
          {
               PRO_SQLDA_Deallocate(osqlda) ;
               if (!(osqlda = PRO_SQLDA_Allocate(-(nvars), 20)))
               {
                    printf ("PRO_SQLDA_Allocate returned err\n") ;
                    goto err ;
               }
               continue ;
          }
          break ;
     }
} 

In this example, the SQLDA is allocated again when the size (first argument) provided in the PRO_SQLDA_Allocate function is insufficient. In this case the SQLDA component SQLD_NVARS contains a negative number equal to the negative of the actual number of outputs.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095