| 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.10.3 Informix-compatible SQLDA Descriptor Areas
Informix-compatible mode supports a different structure than the one described in section 3.9.2 SQLDA Descriptor Areas. See below:
struct sqlvar_compat
{
short sqltype;
int sqllen;
char *sqldata;
short *sqlind;
char *sqlname;
char *sqlformat;
short sqlitype;
short sqlilen;
char *sqlidata;
int sqlxid;
char *sqltypename;
short sqltypelen;
short sqlownerlen;
short sqlsourcetype;
char *sqlownername;
int sqlsourceid;
char *sqlilongdata;
int sqlflags;
void *sqlreserved;
};
struct sqlda_compat
{
short sqld;
struct sqlvar_compat *sqlvar;
char desc_name[19];
short desc_occ;
struct sqlda_compat *desc_next;
void *reserved;
};
typedef struct sqlvar_compat sqlvar_t;
typedef struct sqlda_compat sqlda_t;
The global properties are:
sqld-
The number of fields in the
SQLDAdescriptor. sqlvar- Pointer to the per-field properties.
desc_name- Unused, filled with zero-bytes.
desc_occ- Size of the allocated structure.
desc_next- Pointer to the next SQLDA structure if the result set contains more than one records.
reserved- Unused pointer, contains NULL. Kept for Informix-compatibility.
The per-field properties are below, they are stored in the sqlvar array:
sqltype-
Type of the field. Constants are in
sqltypes.h sqllen- Length of the field data.
sqldata-
Pointer to the field data. The pointer is of
char *type, the data pointed by it is in a binary format. Example:int intval; switch (sqldata->sqlvar[i].sqltype) { case SQLINTEGER: intval = *(int *)sqldata->sqlvar[i].sqldata; break; ... } sqlind-
Pointer to the NULL indicator. If returned by DESCRIBE or FETCH then it's always a valid pointer.
If used as input for
EXECUTE ... USING sqlda;then NULL-pointer value means that the value for this field is non-NULL. Otherwise a valid pointer andsqlitypehas to be properly set. Example:if (*(int2 *)sqldata->sqlvar[i].sqlind != 0) printf("value is NULL\n"); sqlname- Name of the field. 0-terminated string.
sqlformat-
Reserved in Informix, value of
PQfformat()for the field. sqlitype-
Type of the NULL indicator data. It's always SQLSMINT when returning data from the server.
When the
SQLDAis used for a parametrized query, the data is treated according to the set type. sqlilen- Length of the NULL indicator data.
sqlxid-
Extended type of the field, result of
PQftype(). sqltypenamesqltypelensqlownerlensqlsourcetypesqlownernamesqlsourceidsqlflagssqlreserved- Unused.
sqlilongdata-
It equals to
sqldataifsqllenis larger than 32KB.
Example:
EXEC SQL INCLUDE sqlda.h;
sqlda_t *sqlda; /* This doesn't need to be under
embedded DECLARE SECTION */
EXEC SQL BEGIN DECLARE SECTION;
char *prep_stmt = "select * from table1";
int i;
EXEC SQL END DECLARE SECTION;
...
EXEC SQL PREPARE mystmt FROM :prep_stmt;
EXEC SQL DESCRIBE mystmt INTO sqlda;
printf("# of fields: %d\n", sqlda->sqld);
for (i = 0; i < sqlda->sqld; i++)
printf("field %d: \"%s\"\n", sqlda->sqlvar[i]->sqlname);
EXEC SQL DECLARE mycursor CURSOR FOR mystmt;
EXEC SQL OPEN mycursor;
EXEC SQL WHENEVER NOT FOUND GOTO out;
while (1)
{
EXEC SQL FETCH mycursor USING sqlda;
}
EXEC SQL CLOSE mycursor;
free(sqlda); /* The main structure is all to be free(),
* sqlda and sqlda->sqlvar is in one allocated area */
For more information, see the sqlda.h header and the
src/interfaces/ecpg/test/compat_informix/sqlda.pgc regression test.
| ISBN 9781906966065 | The PostgreSQL 9.0 Reference Manual - Volume 2 - Programming Guide | See the print edition |