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.) |
Return Codes
Diagnostics
None.
Restrictions
None.
/* From CLI sample getsqlca.c */ /* ... */ /* execute the SQL statement in "sqlstr" */ rc = SQLPrepare(hstmt, sqlstr, SQL_NTS); CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; rc = SQLGetSQLCA(henv, hdbc, hstmt, &sqlca); CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; printf(" Relative Cost=[%ld] Estimated # rows=[%ld]\n" " Continue with execution(Y or N)?\n", sqlca.sqlerrd[3], sqlca.sqlerrd[2]); gets((char *)prompt); if (prompt[0] == 'n' || prompt[0] =='N') return(0); if ( rc != SQL_SUCCESS ) CHECK_HANDLE( SQL_HANDLE_STMT, hstmt, rc ) ; rc = SQLExecute(hstmt);
References