Handling an unknown select list

For a SELECT statement, the columns in the select list identify the column values that are received from the database server. In the SELECT statement described and illustrated in the demo1.ec example program (see A sample HCL OneDB ESQL/C program), the values returned from the query are placed into the host variables that are listed in an INTO host_var clause of the SELECT statement.

However, when your program creates a SELECT statement at run time, you cannot use an INTO clause because you do not know at compile time what host variables are needed. If the type and number of the values that your program receives are not known at compile time, your program must perform the following tasks:
  1. Declare a dynamic-management structure to serve as storage for the select-list column definitions. This structure can be either a system-descriptor area or an sqlda structure.

    Use of the system-descriptor area conforms to X/Open standards.

  2. Use the DESCRIBE statement to examine the select list of the prepared SELECT statement and describes the columns.
  3. Specify the dynamic-management structure as the location of the data fetched from the database. From the dynamic-management structure, the program can move the column values into host variables.
Important: Use a dynamic-management structure only if you do not know the number and data types of the select-list columns at compile time.

For information about how to execute a SELECT if you do know the number and data types of select-list columns, see Execute SELECT statements. For information about how to identify columns in the select list of a SELECT statement with a system-descriptor area, see Handling an unknown select list. For more information about how to use an sqlda structure, see Handling an unknown select list.