Errors with optimized message transfers
When you enable the OPTMSG feature, HCL OneDB™ ODBC does not perform error handling on any chained statement.
If you are not sure whether a particular statement might generate an error, include error-handling statements in your code and do not enable message chaining for that statement.
The database server stops execution of subsequent statements
when an error occurs in a chained statement. For example, in the following
code fragment, the intent is to chain five INSERT statements:
SQLExecDirect(hstmt, "create table tab1 (col1 INTEGER)", SQL_NTS);
/* enable message chaining */
SQLSetStmtOption(hstmt, SQL_INFX_ATTR_OPTMSG, 1);
/* these two INSERT statements execute successfully */
SQLExecDirect(hstmt, "insert into tab1 values (1)", SQL_NTS);
SQLExecDirect(hstmt, "insert into tab1 values (2)", SQL_NTS);
/* this INSERT statement generates an error because the data
* in the VALUES clause is not compatible with the column type */
SQLExecDirect(hstmt, "insert into tab1 values ('a')", SQL_NTS);
/* these two INSERT statements never execute */
SQLExecDirect(hstmt, "insert into tab1 values (3)", SQL_NTS);
SQLExecDirect(hstmt, "insert into tab1 values (4)", SQL_NTS);
/* disable message chaining */
SQLSetStmtOption(hstmt, SQL_INFX_ATTR_OPTMSG, 0);
/* commit work */
rc = SQLEndTran (SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
if (rc != SQL_SUCCESS)
In this example, the following actions occur:
- The driver sends the five INSERT statements and the COMMIT WORK statements to the database server for execution.
- The database inserts col1 values of 1 and 2 into the tab1 table.
- The third INSERT statement generates an error, so the database server does not execute the subsequent INSERT statements or the COMMIT WORK statement.
- The driver flushes the message queue when the queue reaches the SQLEndTran function.
- The SQLEndTran function, which is the last statement in the chained statements, returns the error from the failed INSERT statement.
If you want to keep the values that the database server inserted into col1, you must commit them yourself.