Specification: | DB2 CLI 2.1 |
SQLGetSQLCA() is used to return the SQLCA associated with the preparation, and execution of an SQL statement, fetching of data, or the closing of a cursor. The SQLCA may return information in addition to what is available using SQLError().
Note: | SQLGetSQLCA() must not be used as a replacement for SQLGetDiagField() and SQLGetDiagRec(). |
For a detailed description of the SQLCA structure, refer to the SQLCA appendix in theSQL Reference
An SQLCA is not available if a function is processed strictly on the application side, such as allocating a statement handle. In this case, an empty SQLCA is returned with all values set to zero.
Syntax
SQLRETURN SQLGetSQLCA (SQLHENV EnvironmentHandle, /* henv */ SQLHDBC ConnectionHandle, /* hdbc */ SQLHSTMT StatementHandle, /* hstmt */ struct sqlca FAR *SqlcaPtr); /* pSqlca */
Function Arguments
Table 117. SQLGetSQLCA Arguments
Data Type | Argument | Use | Description |
---|---|---|---|
SQLHENV | EnvironmentHandle | input | Environment Handle. To obtain the SQLCA associated with an environment, pass a valid environment handle. Set ConnectionHandle and StatementHandle to SQL_NULL_HDBC and SQL_NULL_HSTMT respectively. |
SQLHDBC | ConnectionHandle | input | Connection Handle. To obtain the SQLCA associated with a connection, pass a valid database connection handle, and set StatementHandle to SQL_NULL_HSTMT. The EnvironmentHandle argument is ignored. |
SQLHSTMT | StatementHandle | input | Statement Handle. To obtain the SQLCA associated with a statement, pass a valid statement handle. The EnvironmentHandle and ConnectionHandle arguments are ignored. |
SQLCA * | sqlCA | output | SQL Communication Area |
Usage
The handles are used in the same way as for the SQLError() function. To obtain the SQLCA associated with:
If diagnostic information generated by one DB2 CLI function is not retrieved before a function other than SQLError() is called with the same handle, the information for the previous function call is lost. This is true whether or not diagnostic information is generated for the second DB2 CLI function call.
If a DB2 CLI function is called that does not result in interaction with the DBMS, then the SQLCA will contain all zeroes. Meaningful information will usually be returned for the following functions:
If the database connection is to a DB2 Universal Database Version 2 server or later, there are two fields in the SQLCA that may be of particular interest:
This is the number that is compared to the DB2ESTIMATE configuration keyword as described in Configuration Keywords, and the SQL_ATTR_DB2ESTIMATE connection attribute as described in the function description, SQLSetConnectAttr - Set Connection Attributes.
Note: | The accuracy of the information returned in the SQLERRD(3) and SQLERRD(4)
fields is dependent on many factors such as the use of parameter markers and
expressions within the statement. The main factor which can be
controlled is the accuracy of the database statistics. That is, when
the statistics were last updated, (for example, for DB2 Universal Database,
the last time the RUNSTATS command was run.)
Starting in DB2 CLI Version 5, deferred prepare is on by default. The PREPARE request is not sent to the server until the corresponding execute request is issued. This means that the data in the SQLERRD(3) and SQLERRD(4) fields related to PREPARE will not be meaningful right after the SQLPrepare() call. See Deferred Prepare now on by Default for complete details. |
Return Codes
Diagnostics
None.
Restrictions
None.
(The complete sample apsqlca.c is also available here .)
/* From the CLI sample APSQLCA.C */ /* ... */ /* call SQLGetSQLCA */ printf(" Call SQLGetSQLCA and print some SQLCA fields.\n"); sqlrc = SQLGetSQLCA( henv, hdbc, hstmt, &sqlca ) ; HANDLE_CHECK( SQL_HANDLE_STMT, hstmt, sqlrc, &henv, &hdbc ) ;
References