Collection Contents Index Working with cursors Controlling transactions in applications pdf/chap9.pdf

User's Guide
   PART 1. Working with Databases
     CHAPTER 9. Using SQL in Applications       

Describing result sets


Some applications build SQL statements, perhaps in response to the user's actions, which cannot be completely specified in the application. For example, a reporting application may allow a user to select which columns they wish to display.

In such a case, the application needs a method for retrieving information about the nature of the result set itself (the number and type of columns), as well as the contents of the result set. This resultset metadata information is manipulated using descriptors. Obtaining and managing the result set metadata is called describing.

As result sets are generally obtained from cursors, descriptors and cursors are closely linked.

In some interfaces, use of descriptors is hidden from the user.

A sequence for using a descriptor with a cursor-based operation is as follows:

  1. Allocate the descriptor. This may be done implicitly, although explicit allocation is allowed in some interfaces.

  2. Prepare the statement.

  3. Declare and open a cursor for the statement (Embedded SQL) or execute the statement.

  4. Get the descriptor and modify the allocated area if necessary. This is often done implicitly.

  5. Fetch and process the statement results.

  6. Deallocate the descriptor.

  7. Close the cursor.

  8. Drop the statement. This is done automatically by some interfaces.

Typically, statements that need descriptors are either SELECT statements or stored procedures that return result sets.

The data structure that holds the information concerning the expected number and type of columns that are being returned is called a descriptor. In different interfaces, the descriptor may be implemented in different ways.

Implementation notes 


Collection Contents Index Working with cursors Controlling transactions in applications pdf/chap9.pdf