- publishing free software manuals
The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide
by The PostgreSQL Global Development Group
Paperback (6"x9"), 478 pages
ISBN 9781906966065
RRP £14.95 ($19.95)

Sales of this book support the PostgreSQL project! Get a printed copy>>>

3.9.2 SQLDA Descriptor Areas

An SQLDA Descriptor Area is a C language structure which can be also used to get the result set and the metadata of a query. One structure stores one record from the result set.

EXEC SQL include sqlda.h;
sqlda_t         *mysqlda;

EXEC SQL FETCH 3 FROM mycursor INTO DESCRIPTOR mysqlda;

Note that the SQL keyword is omitted. The paragraphs about the use cases of the INTO and USING keywords in section 3.9.1 Named SQL Descriptor Areas also apply here with an addition. In a DESCRIBE statement the DESCRIPTOR keyword can be completely omitted if the INTO keyword is used:

EXEC SQL DESCRIBE prepared_statement INTO mysqlda;

The structure of SQLDA is:

#define NAMEDATALEN 64

struct sqlname
{
        short           length;
        char            data[NAMEDATALEN];
};

struct sqlvar_struct
{
        short           sqltype;
        short           sqllen;
        char       *sqldata;
        short      *sqlind;
        struct sqlname sqlname;
};

struct sqlda_struct
{
        char            sqldaid[8];
        long            sqldabc;
        short           sqln;
        short           sqld;
        struct sqlda_struct *desc_next;
        struct sqlvar_struct    sqlvar[1];
};

typedef struct sqlvar_struct    sqlvar_t;
typedef struct sqlda_struct     sqlda_t;

The allocated data for an SQLDA structure is variable as it depends on the number of fields in a result set and also depends on the length of the string data values in a record. The individual fields of the SQLDA structure are:

sqldaid
It contains the "SQLDA " literal string.
sqldabc
It contains the size of the allocated space in bytes.
sqln
It contains the number of input parameters for a parametrized query case it's passed into OPEN, DECLARE or EXECUTE statements using the USING keyword. In case it's used as output of SELECT, EXECUTE or FETCH statements, its value is the same as sqld statement
sqld
It contains the number of fields in a result set.
desc_next
If the query returns more than one records, multiple linked SQLDA structures are returned, the first record is stored in the SQLDA returned in the
sqlvar
This is the array of the fields in the result set. The fields are:
sqltype
It contains the type identifier of the field. For values, see enum ECPGttype in ecpgtype.h.
sqllen
It contains the binary length of the field. E.g. 4 bytes for ECPGt_int.
sqldata
(char *)sqldata points to the data.
sqlind
(char *)sqlind points to the NULL indicator for data. 0 means NOT NULL, -1 means NULL.
sqlname
struct sqlname sqlname contains the name of the field in a structure:
struct sqlname
{
        short           length;
        char            data[NAMEDATALEN];
};
length
sqlname.length contains the length of the field name.
data
sqlname.data contains the actual field name.
ISBN 9781906966065The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming GuideSee the print edition