Tutorial Chapter 4: Query by Example / Modifying the Program to Handle Errors |
Closing and freeing the cursor when you no longer need it is good practice, especially if the modules are part of a larger program.
This function must be placed in the same module as the DECLARE/OPEN/FETCH statements and in sequence, so this is the last function in the query_cust module. However, the function can be called from cust_main, as a final "cleanup" routine.
01 FUNCTION cleanup() 02 WHENEVER ERROR CONTINUE 03 CLOSE cust_curs 04 FREE cust_curs 05 WHENEVER ERROR STOP 06 END FUNCTION
Line 03 Closes the cursor used to retrieve the database rows.
Line 04 Frees the memory associated with the cursor.
Lines 02 and 05 The WHENEVER ERROR statements prevent a program error if the user exited the program without querying, and the cursor was never created.