open (dynamic cursor)

Description

Opens a previously declared dynamic cursor.

Syntax

exec sql [at connection_name] open cursor_name
[row_count = size] [using {host_var_list |
 descriptor descriptor_name | 
 sql descriptor descriptor_name}];

Parameters

cursor_name

Names a cursor that has been declared using the declare cursor statement.

size

The number of rows moved in a network roundtrip, not the number fetched into the host variable. The size argument can be either a literal or a declared host variable.

host_var_list

Names the host variables that contain the values for dynamic parameter markers.

descriptor

Identifies descriptor_name as a SQLDA structure.

sql descriptor

Identifies descriptor_name as a SQL descriptor.

descriptor_name

Names the dynamic descriptor that contains information about the dynamic parameter markers in a prepared statement.

Examples

Example 1

exec sql begin declare section; 
     CS_CHAR        dyna_buf[128]; 
     CS_CHAR        title_id[6]; 
     CS_CHAR        lastname[40]; 
     CS_CHAR        firstname[20]; 
     CS_CHAR        phone[12]; 
 exec sql end declare section;  
 
 dyna_buf = "SELECT a.au_lname, a.au_fname, a.phone"
         + "FROM authors a, titleauthor t " 
         + "WHERE a.au_id = t.au_id "
         + "AND t.title_id = ?”;
 
 exec sql prepare dyna_comm from :dyna_buf;  
 
 exec sql declare who_wrote cursor for dyna_comm;  
 
 printf("List authors for what title? ");
 gets(title_id);
exec sql open who_wrote using :title_id; 
while (TRUE){         exec sql fetch who_wrote into 
             :lastname, :firstname, :phone; 
         if (sqlcode == 100) break;
         printf(“Last name is %s\n”,lastname,           “First name is %s\n”, firstname, 
           “Phone number is %s\n”, phone); 
 }
 
 exec sql close who_wrote;

Usage

See also

close, declare, fetch, prepare