Progress
Embedded SQL-92
Guide and Reference


SQLDA for Input Variables

Use an INPUT SQLDA to store the values for input host variables required in an SQL statement. Use a DESCRIBE BIND statement for an input SQLDA.

This is the syntax for a DESCRIBE BIND VARIABLES statement for an INPUT operation:

SYNTAX
EXEC SQL
     DESCRIBE BIND VARIABLES FOR statement_name INTO input_sqlda_name ; 

The DESCRIBE BIND statement must be executed after the PREPARE step and before the OPEN operation.

EXAMPLE

The following example shows how to use a DESCRIBE BIND statement to determine the number of input host variable references in an SQL statement:

struct sqlda *isqlda ;
 
EXEC SQL BEGIN DECLARE SECTION ;
     char stmt_str [100] ;
EXEC SQL END DECLARE SECTION ;
 
strcpy (stmt_str,
     "insert into dept (deptno, dname, loc) values (:p1, :p2, :p3)") ;
 
EXEC SQL
     PREPARE ins_stmt FROM :stmt_str ;
EXEC SQL
     DECLARE ins_cur CURSOR FOR ins_stmt ;
 
/* Allocate for SQLDA */
isqlda = PRO_SQLDA_Allocate(20, 0) ; 
if (!isqlda)
{
     printf ("Insufficient memory for SQLDA of size 20\n") ;
     exit (1) ;
}
 
/* Call DESCRIBE to get number of host variable references */
EXEC SQL
     DESCRIBE BIND VARIABLES FOR ins_stmt INTO isqlda ;
 
nvars = isqlda->sqld_nvars ;
if (nvars < 0) nvars = -nvars ;
 
/* Free SQLDA */
PRO_SQLDA_Deallocate(isqlda) ;
 
/* Allocate SQLDA for exact number of host variable references */
isqlda = PRO_SQLDA_Allocate(nvars, 0)
if (!isqlda)
{
     printf ("Insufficient memory for SQLDA \n") ;
     exit (1) ;
}
EXEC SQL
     OPEN ins_cur USING DESCRIPTOR isqlda ; 

In this example, an SQLDA is first allocated for 20 variables. After the DESCRIBE is performed on the prepared statement, the SQLDA is once again allocated for the exact number of host variable references. Note that the second argument for PRO_SQLDA_Allocate( ) is zero when allocating for an INPUT SQLDA.


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