4 GET DESCRIPTOR — get information from an SQL descriptor area
8 GET DESCRIPTOR descriptor_name :cvariable = descriptor_header_item [, ... ]
9 GET DESCRIPTOR descriptor_name VALUE column_number :cvariable = descriptor_item
14 GET DESCRIPTOR retrieves information about a query result set from an
15 SQL descriptor area and stores it into host variables. A descriptor
16 area is typically populated using FETCH or SELECT before using this
17 command to transfer the information into host language variables.
19 This command has two forms: The first form retrieves descriptor
20 “header” items, which apply to the result set in its entirety. One
21 example is the row count. The second form, which requires the column
22 number as additional parameter, retrieves information about a
23 particular column. Examples are the column name and the actual column
31 descriptor_header_item #
32 A token identifying which header information item to retrieve.
33 Only COUNT, to get the number of columns in the result set, is
37 The number of the column about which information is to be
38 retrieved. The count starts at 1.
41 A token identifying which item of information about a column to
42 retrieve. See Section 34.7.1 for a list of supported items.
45 A host variable that will receive the data retrieved from the
50 An example to retrieve the number of columns in a result set:
51 EXEC SQL GET DESCRIPTOR d :d_count = COUNT;
53 An example to retrieve a data length in the first column:
54 EXEC SQL GET DESCRIPTOR d VALUE 1 :d_returned_octet_length = RETURNED_OCTET_LENG
57 An example to retrieve the data body of the second column as a string:
58 EXEC SQL GET DESCRIPTOR d VALUE 2 :d_data = DATA;
60 Here is an example for a whole procedure of executing SELECT
61 current_database(); and showing the number of columns, the column data
62 length, and the column data:
66 EXEC SQL BEGIN DECLARE SECTION;
69 int d_returned_octet_length;
70 EXEC SQL END DECLARE SECTION;
72 EXEC SQL CONNECT TO testdb AS con1 USER testuser;
73 EXEC SQL SELECT pg_catalog.set_config('search_path', '', false); EXEC SQL CO
75 EXEC SQL ALLOCATE DESCRIPTOR d;
77 /* Declare, open a cursor, and assign a descriptor to the cursor */
78 EXEC SQL DECLARE cur CURSOR FOR SELECT current_database();
80 EXEC SQL FETCH NEXT FROM cur INTO SQL DESCRIPTOR d;
82 /* Get a number of total columns */
83 EXEC SQL GET DESCRIPTOR d :d_count = COUNT;
84 printf("d_count = %d\n", d_count);
86 /* Get length of a returned column */
87 EXEC SQL GET DESCRIPTOR d VALUE 1 :d_returned_octet_length = RETURNED_OCTET_
89 printf("d_returned_octet_length = %d\n", d_returned_octet_length);
91 /* Fetch the returned column as a string */
92 EXEC SQL GET DESCRIPTOR d VALUE 1 :d_data = DATA;
93 printf("d_data = %s\n", d_data);
99 EXEC SQL DEALLOCATE DESCRIPTOR d;
100 EXEC SQL DISCONNECT ALL;
105 When the example is executed, the result will look like this:
107 d_returned_octet_length = 6
112 GET DESCRIPTOR is specified in the SQL standard.
116 ALLOCATE DESCRIPTOR, SET DESCRIPTOR