![]() |
|
If you do not know the number or data types of values sent to or received from the database server, use a dynamic-management structure. A dynamic-management structure allows you to pass a variable-length list of data to the database server, or receive a variable-length list of data from it.
To execute dynamic SQL statements with unknown columns, you can use either of the following dynamic-management structures in your ESQL/C program:
For a given dynamic SQL statement, the dynamic-management structure can hold any of the following information:
The ESQL/C program can then use this information to determine a host variable of appropriate length and type to hold the value.
A system-descriptor area is an area of memory declared by ESQL/C to hold data either returned from or sent by a prepared statement. It is the dynamic-management structure that conforms to the X/Open standards.
A system-descriptor area has two parts:
Figure 15-1 shows what a system-descriptor area looks like for two values.
The fixed-size portion of the system-descriptor area consists of the single field, which Figure 15-2 shows.
Figure 15-2
Each item descriptor in the system-descriptor area holds information about a data value that can be sent to or received from the database server. Each item descriptor consists of the fields that Figure 15-3 summarizes.
Figure 15-3
For information on how to use a system-descriptor area to dynamically execute SQL statements, see Chapter 16, Using a System-Descriptor Area.
The sqlda structure is a C structure (defined in the sqlda.h header file) that holds data returned from a prepared statement. Each sqlda structure has three parts:
Figure 15-4 shows what an sqlda structure looks like for two values.
Figure 15-4 shows the column data in the sqldata fields in a single data buffer. This data can also be stored in separate buffers. For more information, see Allocating Memory for Column Data.
Figure 15-5 describes the fixed-size portion of the sqlda structure, which consists of a single field.
Figure 15-5
When all of its components are fully defined, the sqlda structure points to the initial address of a sequence of sqlvar_struct structures that contain the necessary information for each variable in the set. Each sqlvar_struct structure holds a data value that can be sent to or received from the database server. Your program accesses these sqlvar_struct structures through the sqlvar field of sqlda. Figure 15-6 and Figure 15-7 on page 15-13 summarize the variable-sized structure of sqlda.
Figure 15-6
Figure 15-7 shows the fields in the sqlvar_struct structure.
Figure 15-7
Figure 15-8 summarizes the sqlda fields that describe the sqlda structure itself.
Figure 15-8
For information on how to use an sqlda structure to dynamically execute SQL statements, see Chapter 17, Using an sqlda Structure.