Ability to analyze results and knowledge of problem determination


SQLGetDiagField function (CLI)

SQLGetDiagField() returns the current value of a field of a diagnostic data structure, associated with a specific handle, that contains error, warning, and status information.


  SQLSMALLINT       HandleType,         /* fHandleType */
  SQLHANDLE         Handle,             /* hHandle */
  SQLSMALLINT       RecNumber,          /* iRecNumber */
  SQLSMALLINT       DiagIdentifier,     /* fDiagIdentifier */
  SQLPOINTER        DiagInfoPtr,        /* pDiagInfo */
  SQLSMALLINT       BufferLength,       /* cbDiagInfoMax */
  SQLSMALLINT       *StringLengthPtr);  /* *pcgDiagInfo */

An application typically calls SQLGetDiagField() to accomplish one of three goals:

  1. To obtain specific error or warning information when a function call has returned the SQL_ERROR or SQL_SUCCESS_WITH_INFO (or SQL_NEED_DATA for the SQLBrowseConnect() function) return codes.

  2. To find out the number of rows in the data source that were affected when insert, delete, or update operations were performed with a call to SQLExecute(), SQLExecDirect(), SQLBulkOperations(), or SQLSetPos() (from the SQL_DIAG_ROW_COUNT header field), or to find out the number of rows that exist in the current open static scrollable cursor (from the SQL_DIAG_CURSOR_ROW_COUNT header field).

  3. To determine which function was executed by a call to SQLExecDirect() or SQLExecute() (from the SQL_DIAG_DYNAMIC_FUNCTION and SQL_DIAG_DYNAMIC_FUNCTION_CODE header fields).

Any DB2 CLI function can post zero or more errors each time it is called, so an application can call SQLGetDiagField() after any function call. SQLGetDiagField() retrieves only the diagnostic information most recently associated with the diagnostic data structure specified in the Handle argument. If the application calls another function, any diagnostic information from a previous call with the same handle is lost.

Example. How to retrieve SQLCA-equivalent information:

SQLHANDLE hstmt; /* statement handle */
SQLCHAR *stmt1 = (SQLCHAR *)"SELECT * FROM org";


/* prepare the statement */
cliRC = SQLPrepare(hstmt, stmt1, SQL_NTS);

/* execute the statement */
cliRC = SQLExecute(hstmt);

/* get the SQLCA-equivalent information - sqlerrd(3)*/
printf("    Estimated number of rows that are returned: %d\n", diagPtr);
/* get the SQLCA-equivalent information - sqlerrd(4)*/
printf("    Estimated cost of prepare: %d\n", diagPtr);


SQLCA (SQL communications area)

An SQLCA is a collection of variables that is updated at the end of the execution of every SQL statement. A program that contains executable SQL statements and is precompiled with option LANGLEVEL SAA1 (the default) or MIA must provide exactly one SQLCA, though more than one SQLCA is possible by having one SQLCA per thread in a multi-threaded application.

SQLCA field descriptions:

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     SCDJWS 5.0 Quiz