What difference CLOSE cursor between FREE CURSOR?
Posted in 1999
Topics: General Discussion
What difference CLOSE cursor between FREE CURSOR? EXEC SQL close cursor; EXEC SQL free cursor; -- ------------------------------ e-mail to soph@doit.ajou.ac.kr
soph@engineer.ajou.ac.kr wrote: > > What difference CLOSE cursor between FREE CURSOR? > > EXEC SQL close cursor; This empties and releases the buffer associated with the cursor, meaning you discard all the rows, but you can still OPEN the cursor again, retrieving all matching rows (which can be different than the previous set, giving some time has ellapsed and the table may have been modified) > EXEC SQL free cursor; This one discards any reference to the cursor on both the client and the server i.e. you release ALL memory associated with this cursor, loosing the ability to reopen it. You should use CLOSE+OPEN to 'refresh' your set of rows, and FREE when you are done. > > -- > ------------------------------ > e-mail to soph@doit.ajou.ac.kr -- _________________________________________________ Paulo Silva mailto:psilva@informix.com Consultant/Trainer phone : +351 1 412 89 40 Informix Software Portugal fax : +351 1 410 84 37
Since CLOSE CURSOR and FREE CURSOR are both explained (technically) in the "Informix Guide to SQL - Syntax", I presume you are looking for some additionally information. Use close cursor if you plan to re-open (that is, re-use) the cursor. You would want to do this for a number of reasons, including (a) you want to get an a more current picture of the data, (b) your program does something over and over and you are using a dynamic statement for the cursor where the selection criteria changes. Use free cursor if you will not be using the cursor further in your program, and particularly if your program has a long way to go - freeing the cursor frees resources associated with the cursor. If you used a prepared statement to create the cursor, then you will need to free the prepared statement (via its id) separately. soph@engineer.ajou.ac.kr wrote: > What difference CLOSE cursor between FREE CURSOR? > > EXEC SQL close cursor; > EXEC SQL free cursor; > > -- > ------------------------------ > e-mail to soph@doit.ajou.ac.kr
HI Buddy, close cursor statement only closes the cursor but does not free the memory allcocated by informix for the cursor. If your program is going to exit immediately after clost cursor statement then you don't need to worry about free cursor. But if your program is complicated and has lots of other processing to do and will run for another couple of minutes or more than it is a good idea to do free cursor after the close cursor to free the memory. But make sure you don't need the cursor after that. You won't be able to open cursor once you have done free. thanks, khem chander kchande@yahoo.com soph@engineer.ajou.ac.kr wrote in article <slrn7k45uj.fm2.soph@engineer.ajou.ac.kr>... > > What difference CLOSE cursor between FREE CURSOR? > > EXEC SQL close cursor; > EXEC SQL free cursor; > > -- > ------------------------------ > e-mail to soph@doit.ajou.ac.kr >