Opens a previously declared dynamic cursor.
exec sql [at connection_name] open cursor_name [row_count = size] [using {host_var_list | descriptor descriptor_name | sql descriptor descriptor_name}];
Names a cursor that has been declared using the declare cursor statement.
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.
Names the host variables that contain the values for dynamic parameter markers.
Identifies descriptor_name as a SQLDA structure.
Identifies descriptor_name as a SQL descriptor.
Names the dynamic descriptor that contains information about the dynamic parameter markers in a prepared statement.
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;
open executes the statement specified in the corresponding declare cursor statement. You can then use the fetch statement to retrieve the results of the prepared statement.
You can have any number of open cursors.
The using clause substitutes host-variable or dynamic-descriptor contents for the dynamic parameter markers (“?”) in the select statement.
close, declare, fetch, prepare