This page is part of the book SQL-99 Complete, Really, by Peter Gulutzan & Trudy Pelzer. The authors have graciously allowed us to reproduce the contents of the book here. Because the book is about the SQL-99 standard, the contents of this and other pages in the book may not directly apply to MariaDB. Use the navigation bar to navigate the book.

The nine "Header" fields in a diagnostics area occur only once. It does not matter what you pass for the RecordNumber parameter.

0001

SQLGetDiagField(...,...,NULL,SQL_DIAG_RETURNCODE,&smallint,NULL,NULL);

This field gives you the last call's return code: SQL_SUCCESS, SQL_ERROR, SQL_SUCCESS_WITH_INFO, SQL_NEED_DATA or SQL_NO_DATA. You need to call this if you failed to save the return code in an sqlreturn variable.

0002

SQLGetDiagField(...,...,NULL,SQL_DIAG_NUMBER,&integer,NULL,NULL);

This field gives you the number of Status Records (exception or completion conditions) that the DBMS generated for the last call. The value will be zero if the return code is SQL_SUCCESS, and will probably (but not certainly) be zero if the return code is SQL_NO_DATA.

0003

SQLGetDiagField(
   SQL_HANDLE_STMT,hstmt,NULL,SQL_DIAG_ROW_COUNT,&integer,NULL,NULL);

If the last call was SQLExecDirect or SQLExecute for an UPDATE, DELETE or INSERT statement, this field gives you the number of rows affected. Read about the SQLRowCount function, which returns the same information. You must call this function immediately after calling SQLExecDirect or SQLExecute.

0007

SQLGetDiagField(
   SQL_HANDLE_STMT,hstmt,NULL,SQL_DIAG_DYNAMIC_FUNCTION,charstring,
   sizeof(charstring),&charstring_size);

If the last call was SQLExecDirect or SQLExecute, this field gives you a string that describes the type of SQL statement executed. Usually this is the first two or three <keyword>s in the statement. The official list of SQL statements and their function codes is shown at the end of this section.

0012

SQLGetDiagField(
   SQL_HANDLE_STMT,hstmt,NULL,SQL_DIAG_DYNAMIC_FUNCTION_CODE,
   &integer,NULL,NULL);

If the last call was SQLExecDirect or SQLExecute, this field gives you the code value for the type of SQL statement executed; see the codes in the "SQL_DIAG_DYNAMIC_FUNCTION Codes" listings. If you allow users to type in SQL statements, it's handy to call SQLPrepare and then call this function, so you know what kind of SQL statement it is before you call SQLExecute. (This won't work with ODBC.)

0013

SQLGetDiagField(SQL_HANDLE_STMT,hstmt,NULL,SQL_DIAG_MORE,&integer,NULL,NULL);

The return value for this field is either 1 "true" or 0 "false": if there are more status records than would fit in the diagnostics area, you get a "true" code here. (Actually the Standard says that the returned value is 'Y' or 'N' but that must be an error.) You may or may not be able to change the maximum size of the diagnostics area with SET TRANSACTION ... DIAGNOSTICS SIZE statement.

0034

SQLGetDiagField(
   ...,...,NULL,SQL_DIAG_TRANSACTIONS_COMMITTED,&integer,NULL,NULL);

This field gives you the number of transactions committed.

0035

SQLGetDiagField(
   ...,...,NULL,SQL_DIAG_TRANSACTIONS_ROLLED_BACK,&integer,NULL,NULL);

This field gives you the number of transactions rolled back.

0036

SQLGetDiagField(...,...,NULL,SQL_DIAG_TRANSACTION_ACTIVE,&integer,NULL,NULL);

This field gives you a 1 "true" if a transaction is currently active. (A transaction is active if a Cursor is open or the DBMS is waiting for a deferred parameter.)

Comments

Comments loading...