Figure 16-1 SQL Statements That Can Be Used to Manipulate a System-Descriptor Area (1 of 2) SQL Statement Purpose See Page... ALLOCATE DESCRIPTOR Allocates memory for a system-descriptor area 16-5 DESCRIBE...USING SQL DESCRIPTOR Initializes the system-descriptor area with information about column-list columns 16-6 GET DESCRIPTOR Obtains information from the fields of the system-descriptor area 16-8 SET DESCRIPTOR Places information into a system- descriptor area for the database server to access 16-8 For SELECT and EXECUTE FUNCTION statements that use cursors: OPEN...USING SQL DESCRIPTOR FETCH...USING SQL DESCRIPTOR Takes any input parameters from the specified system-descriptor area Puts the contents of the row into the system-descriptor area 16-10 16-11 For SELECT and EXECUTE FUNCTION statements that return only one row: EXECUTE...INTO SQL DESCRIPTOR Puts the contents of the singleton row into the system-descriptor area 16-11 For non-SELECT statements: EXECUTE...USING SQL DESCRIPTOR Takes any input parameters from the specified system-descriptor area 16-10 For an INSERT statement that uses an insert cursor: PUT...USING SQL DESCRIPTOR Puts a row into the insert buffer, obtaining the column values from the specified system-descriptor area 16-29 DEALLOCATE DESCRIPTOR Frees memory allocated for the system-descriptor area when your program is finished with it 16-12 Allocating Memory for a System-Descriptor Area To allocate memory for a system-descriptor area, use the ALLOCATE DESCRIPTOR statement. This statement performs the following tasks:
(1 of 2)
ALLOCATE DESCRIPTOR
Allocates memory for a system-descriptor area
16-5
DESCRIBE...USING SQL DESCRIPTOR
Initializes the system-descriptor area with information about column-list columns
16-6
GET DESCRIPTOR
Obtains information from the fields of the system-descriptor area
16-8
SET DESCRIPTOR
Places information into a system- descriptor area for the database server to access
For SELECT and EXECUTE FUNCTION statements that use cursors:
OPEN...USING SQL DESCRIPTOR
FETCH...USING SQL DESCRIPTOR
Takes any input parameters from the specified system-descriptor area
Puts the contents of the row into the system-descriptor area
16-10
16-11
For SELECT and EXECUTE FUNCTION statements that return only one row:
EXECUTE...INTO SQL DESCRIPTOR
Puts the contents of the singleton row into the system-descriptor area
For non-SELECT statements:
EXECUTE...USING SQL DESCRIPTOR
For an INSERT statement that uses an insert cursor:
PUT...USING SQL DESCRIPTOR
Puts a row into the insert buffer, obtaining the column values from the specified system-descriptor area
16-29
DEALLOCATE DESCRIPTOR
Frees memory allocated for the system-descriptor area when your program is finished with it
16-12
The DESCRIBE Statement and Memory Allocation When you use a system-descriptor area to hold columns of prepared SQL statements, the ALLOCATE DESCRIPTOR statement allocates memory for the item descriptors of each column and the DESCRIBE...USING SQL DESCRIPTOR statement allocates memory for the DATA field of each item descriptor. However, the DESCRIBE...USING SQL DESCRIPTOR statement does not allocate memory for the DATA field of a system-descriptor area when you describe a prepared SELECT statement that fetches data from a column into a host variable of type lvarchar. Before you fetch lvarchar data into the system-descriptor area, you must explicitly assign memory to the DATA field to hold the column value, as follows:
1. Declare an lvarchar host variable of the appropriate size.
2. Assign this host variable to the DATA field with the SET DESCRIPTOR statement.
3. Execute the FETCH...USING SQL DESCRIPTOR statement to retrieve the column data into the DATA field of the system-descriptor area.
Using the GET DESCRIPTOR Statement The GET DESCRIPTOR statement obtains values from the system-descriptor-area fields. You can use the GET DESCRIPTOR statement to:
For more information about how to get individual system-descriptor fields, see the entry for the GET DESCRIPTOR statement in the Informix Guide to SQL: Syntax.
Specifying Input Parameter Values Because the DESCRIBE...USING SQL DESCRIPTOR statement does not analyze a WHERE clause, your program must store the number, data types, and values of the input parameters in the fields of the system-descriptor area to explicitly describe these parameters. For general information on how to define input parameters dynamically, see page 15-26.
When you execute a parameterized statement, you must specify the system-descriptor area as the location of input parameter values with the USING SQL DESCRIPTOR clause, as follows: