informix
INFORMIX-ESQL/C Programmer's Manual
Determining SQL Statements

Using the DESCRIBE Statement

This section provides a brief introduction to the DESCRIBE statement. For more information about the DESCRIBE statement, refer to its entry in the Informix Guide to SQL: Syntax.

The DESCRIBE statement obtains information about database columns or expressions in a prepared statement. It can put this information in one of the following dynamic-management structures:

For more information, see Deferring Execution of the PREPARE Statement.

If the DESCRIBE is successful, it obtains the following information about a prepared statement:

Determining the Statement Type

The sqlstype.h file contains the defined integer constants for the SQL statements that can be prepared. The DESCRIBE statement returns one of these values in the SQLCODE (sqlca.sqlcode) variable to identify a prepared statement. That is, SQLCODE indicates whether the statement was an INSERT, SELECT, CREATE TABLE, or any other SQL statement.

Within an ESQL/C program that uses dynamic SQL statements, you can use the constants that Figure 15-9 shows to determine which SQL statement was prepared.

Figure 15-9

SQL Statement Defined sqlstype.h Constant Value
SELECT (no INTO TEMP clause) None 0
DATABASE SQ_DATABASE 1
Internal use only 2
SELECT INTO TEMP SQ_SELINTO 3
UPDATE...WHERE SQ_UPDATE 4
DELETE...WHERE SQ_DELETE 5
INSERT SQ_INSERT 6
UPDATE WHERE CURRENT OF SQ_UPDCURR 7
DELETE WHERE CURRENT OF SQ_DELCURR 8
Internal use only 9
LOCK TABLE SQ_LOCK 10
UNLOCK TABLE SQ_UNLOCK 11
CREATE DATABASE SQ_CREADB 12
DROP DATABASE SQ_DROPDB 13
CREATE TABLE SQ_CRETAB 14
DROP TABLE SQ_DRPTAB 15
CREATE INDEX SQ_CREIDX 16
DROP INDEX SQ_DRPIDX 17
GRANT SQ_GRANT 18
REVOKE SQ_REVOKE 19
RENAME TABLE SQ_RENTAB 20
RENAME COLUMN SQ_RENCOL 21
CREATE AUDIT SQ_CREAUD 22
Internal use only 23-28
ALTER TABLE SQ_ALTER 29
UPDATE STATISTICS SQ_STATS 30
CLOSE DATABASE SQ_CLSDB 31
DELETE (no WHERE clause) SQ_DELALL 32
UPDATE (no WHERE clause) SQ_UPDALL 33
BEGIN WORK SQ_BEGWORK 34
COMMIT WORK SQ_COMMIT 35
ROLLBACK WORK SQ_ROLLBACK 36
Internal use only 37-39
CREATE VIEW SQ_CREVIEW 40
DROP VIEW SQ_DROPVIEW 41
Internal use only 42
CREATE SYNONYM SQ_CREASYN 43
DROP SYNONYM SQ_DROPSYN 44
CREATE TEMP TABLE SQ_CTEMP 45
SET LOCK MODE SQ_WAITFOR 46
ALTER INDEX SQ_ALTIDX 47
SET ISOLATION, SET TRANSACTION SQ_ISOLATE 48
SET LOG SQ_SETLOG 49
SET EXPLAIN SQ_EXPLAIN 50
CREATE SCHEMA SQ_SCHEMA 51
SET OPTIMIZATION SQ_OPTIM 52
CREATE PROCEDURE SQ_CREPROC 53
DROP PROCEDURE SQ_DRPPROC 54
SET CONSTRAINTS SQ_CONSTRMODE 55
EXECUTE PROCEDURE, EXECUTE FUNCTION SQ_EXECPROC 56
SET DEBUG FILE TO SQ_DBGFILE 57
CREATE OPTICAL CLUSTER SQ_CREOPCL 58
ALTER OPTICAL CLUSTER SQ_ALTOPCL 59
DROP OPTICAL CLUSTER SQ_DRPOPCL 60
RESERVE (Optical) SQ_OPRESERVE 61
RELEASE (Optical) SQ_OPRELEASE 62
SET MOUNTING TIMEOUT SQ_OPTIMEOUT 63
UPDATE STATS...for procedure SQ_PROCSTATS 64
Defined for Kanji version only 65 and 66
Reserved 67-69
CREATE TRIGGER SQ_CRETRIG 70
DROP TRIGGER SQ_DRPTRIG 71
SQ_UNKNOWN 72
SET DATASKIP SQ_SETDATASKIP 73
SET PDQPRIORITY SQ_PDQPRIORITY 74
ALTER FRAGMENT SQ_ALTFRAG 75
SET SQ_SETOBJMODE 76
START VIOLATIONS TABLE SQ_START 77
STOP VIOLATIONS TABLE SQ_STOP 78
Internal use only 79
SET SESSION AUTHORIZATION SQ_SETDAC 80
Internal use only 81-82
CREATE ROLE SQ_CREATEROLE 83
DROP ROLE SQ_DROPROLE 84
SET ROLE SQ_SETROLE 85
Internal use only 86-89
CREATE ROW TYPE SQ_CREANRT 90
DROP ROW TYPE SQ_DROPNRT 91
CREATE DISTINCT TYPE SQ_CREADT 92
CREATE CAST SQ_CREACT 93
DROP CAST SQ_DROPCT 94
CREATE OPAQUE TYPE SQ_CREABT 95
DROP TYPE SQ_DROPTYPE 96
Reserved 97
CREATE ACCESS_METHOD SQ_CREATEAM 98
DROP ACCESS_METHOD SQ_DROPAM 99
Reserved 100
CREATE OPCLASS SQ_CREATEOPC 101
DROP OPCLASS SQ_DROPOPC 102
The Constants for SQL Statement Types That the sqlstype.h File Defines

Tip: Check the sqlstype.h header file on your system for the most updated list of SQL statement-type values.

To determine the type of SQL statement that was prepared dynamically, your ESQL/C program must take the following actions:

The sample program that starts on page 16-25 uses the SQ_EXECPROC constant to verify that an EXECUTE FUNCTION statement has been prepared.

Determining the Data Type of a Column

The DESCRIBE statement identifies the data type of a column with an integer value. After DESCRIBE analyzes a prepared statement, it stores this value in a dynamic-management structure, as follows:

ESQL/C provides defined constants for these data types in the following two header files:

Use the SQL data-type constants from sqltypes.h or sqlxtype.h to analyze the information returned by a DESCRIBE statement or to set the data type of a column before execution.

Tip: When you set the data type of a column in a system-descriptor area, you assign a data-type constant to the TYPE field (and optionally the ITYPE field) of an item descriptor with the SET DESCRIPTOR statement. For more information, see Assigning and Obtaining Values from a System-Descriptor Area. When you set the data type of a column in an sqlda structure, you assign a data-type constant to the sqltype field (and optionally the sqlitype field) of an sqlvar structure. For more information, see Assigning and Obtaining Values from an sqlda Structure.

Informix-Specific SQL Data Types

The Informix-specific SQL data types are available to a column in an Informix database. The Informix Guide to SQL: Reference describes these data types. If you do not include the -xopen option when you compile your ESQL/C program, the DESCRIBE statement uses these data types to specify the data type of a column or the return value of a user-defined function. Constants for these Informix SQL data types are defined in the ESQL/C sqltypes.h header file.

Figure 15-10 shows some of the SQL data-type entries in sqltypes.h.


Figure 15-10
Some Informix SQL Data-Type Constants

For a complete list of constants for SQL data types, see Figure 3-4 on page 3-8. The integer values in Figure 15-10 are language-independent constants; they are the same in all Informix embedded products.

X/Open SQL Data Types

The X/Open standards support only a subset of the Informix-specific SQL data types. To conform to the X/Open standards, you must use the X/Open SQL data-type constants. The DESCRIBE statement uses these constants to specify the data type of a column (or a return value) when you compile your ESQL/C program with the -xopen option.

The X/Open data type constants are defined in the sqlxtype.h header file. For more information, see X/Open Data Type Constants.

Constants for ESQL/C Data Types

The sqltypes.h header file also contains defined constants for the ESQL/C data types. The ESQL/C data types are assigned to host variables in an ESQL/C program. If your program initializes a column description, it usually obtains the column value from an ESQL/C host variable. To set the column data type for this value, the program must use the ESQL/C data types.

Figure 15-11 shows only some of the ESQL/C data type entries in the sqltypes.h header file. For a complete list of constants for ESQL/C data types, see Figure 3-4 on page 3-8.


Figure 15-11
Some ESQL/C Data-Type Constants from the sqltypes.h Header File

Within an ESQL/C program that uses dynamic SQL statements, you can use the constants that are shown in Figure 15-11 to set the data types of the associated host variables. Use the ESQL/C data-type constants to set the data types of host variables used as input parameters to a dynamically defined SQL statement or as storage for column values that are returned by the database server. The sample program on page 16-34 stores a TEXT value into a database table.

Checking for a WHERE Clause

When DESCRIBE analyzes a prepared DELETE or UPDATE statement, it indicates if the statement includes a WHERE clause, as follows:

Your program can check for either of these conditions to determine the type of DELETE or UPDATE statement that was executed. If the DELETE or UPDATE does not contain a WHERE clause, the database server deletes or updates all rows in the table. For more information about how to execute DELETE and UPDATE statements dynamically with a system-descriptor area, see page 16-52; for information on how to use an sqlda structure, see page 17-46.


INFORMIX-ESQL/C Programmer's Manual, Version 9.21
Copyright © 1999, Informix Software, Inc. All rights reserved