I. header files
When introducing the header file of the informix database, you can use the following method:
Exec SQL INCLUDE sqlca;
Exec SQL INCLUDE sqlda;
Exec SQL INCLUDE sqlhdr;
Exec SQL INCLUDE decimal;
Exec SQL INCLUDE locator;
Exec SQL INCLUDE varchar;
Exec SQL INCLUDE datetime;
Exec SQL INCLUDE sqlstype;
Exec SQL INCLUDE sqltypes;
Exec SQL INCLUDE sqlstype;
Ii. macro definition
When a macro is used as a host variable, the macro definition can be as follows:
Exec SQL define SQL _USRNAME_MAX_LEN 64;/* User name max len */
Exec SQL define SQL _PASSWD_MAX_LEN 64;/* Password max len */
Exec SQL define SQL _SVRNAME_MAX_LEN 64;/* Database name max len */
Exec SQL define SQL _CNNAME_MAX_LEN 64;/* Connect name max len */
Exec SQL define SQL _STMT_MAX_LEN 1024;/* SQL statement max len */
Iii. struct Definition
When a struct variable is used in an SQL statement, the struct type of this variable must be defined as follows:
Exec SQL BEGIN DECLARE SECTION;
Typedef struct
{
Int id;
Char name [32];
Char gender;
Int age;
Char brf [256];
} DBStudent_t;
Exec SQL END DECLARE SECTION;
For example:
Int db_ifx_update (...)
{
Exec SQL BEGIN DECLARE SECTION;
DBStudent_t dbstudent;
Exec SQL END DECLARE SECTION;
...
Exec SQL UPDATE SET * = (: dbstudent) WHERE id = '000000 ';
}
Iv. variable definition
The host variable must be defined as follows:
Exec SQL BEGIN DECLARE SECTION;
Char svrname [SQL _SVRNAME_MAX_LEN],/* Server name */
Usrname [SQL _USRNAME_MAX_LEN],/* User name */
Passwd [SQL _PASSWD_MAX_LEN],/* Passwd */
Cnname [SQL _CNNAME_MAX_LEN];/* Connect name */
Exec SQL END DECLARE SECTION;
For example:
Int db_ifx_open (...)
{
Exec SQL BEGIN DECLARE SECTION;
Char svrname [SQL _SVRNAME_MAX_LEN],/* Server name */
Usrname [SQL _USRNAME_MAX_LEN],/* User name */
Passwd [SQL _PASSWD_MAX_LEN],/* Passwd */
Cnname [SQL _CNNAME_MAX_LEN];/* Connect name */
Exec SQL END DECLARE SECTION;
...
Exec SQL CONNECT TO: svrname AS: cnname USER: usrname USING: passwd;
...
}
V. error message
After each SQL statement is executed, the error code is stored in the global variable sqlca. sqlcode. You can use rgetmsg () to obtain the error information. For example:
Int db_ifx_commit (...)
{
Exec SQL COMMIT WORK;
If (sqlca. sqlcode <0)
{
Rgetmsg (sqlca. sqlcode, errmsg, sizeof (errmsg ));
Fprintf (stdout, "% s", errmsg );
Return-1;
}
...
}
[Content navigation] |
Page 1st: ESQL syntax knowledge |
Page 2nd: interface implementation [non-query] |
Page 1: SQLDA Structure |
|