Deallocates a cursor for a static SQL statement or for a dynamic SQL statement.
exec sql [at connection_name] deallocate cursor cursor_name;
The name of the cursor to be deallocated. The cursor_name must be a character string enclosed in double quotation marks or in no quotation marks—for example “my_cursor" or my_cursor. It cannot be a host variable.
exec sql include sqlca;
main()
{
exec sql begin declare section;
CS_CHAR title[80];
CS_SMALLINT i_title;
exec sql end declare section;
exec sql whenever sqlerror call error_handler();
exec sql whenever sqlwarning call error_handler();
exec sql whenever not found continue;
exec sql connect “sa”;
exec sql use pubs2;
exec sql declare title_list cursor for select title from titles;
exec sql open title_list;
for (;;)
{
exec sql fetch title_list into :title :i_title;
if (sqlca.sqlcode == 100) break;
if (i_title == -1) printf(“Title is NULL.\n”);
printf(“Title: %s\n”, title);
}
exec sql close title_list;
exec sql deallocate cursor title_list;
exec sql disconnect all;
exit(0);
}
error_handler()
{
printf(“%d\n%s\n”,sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
exec sql deallocate cursor title_list;
exec sql disconnect all;
exit(-1);
}
Deallocating a cursor releases all resources allocated to the cursor. In particular, deallocate cursor drops the Client-Library command handle and CS_COMMAND structure associated with the cursor.
A static cursor can be deallocated at any time after it is opened. A dynamic cursor can be deallocated at any time after it is declared.
If cursor_name is open, deallocate cursor closes it and then deallocates it.
You cannot reference a deallocated cursor, nor can you reopen it. If you try, an error occurs.
You can declare a new cursor having the same name as that of a deallocated cursor. Opening a cursor with the same name as a deallocated cursor is not the same as reopening the deallocated cursor. Other than the name, the new cursor shares nothing with the deallocated cursor.
Declaring a new cursor with the same name as that of a deallocated cursor can cause the precompiler to generate a warning message.
The deallocate cursor statement is a Sybase extension; it is not defined in the SQL standard.
If you are using persistent binding in your Embedded
SQL program, use the deallocate cursor statement
carefully. Needlessly deallocating cursors can negate the advantage
of persistent binding.
close cursor, declare cursor, open (static cursor)