Informix Error -11031: Invalid cursor state.
Cause and resolution
Invalid cursor state.
This Informix CLI error code is the same as SQLSTATE value 24000. The following functions can return this error code: SQLColAttributes(), SQLColumnPrivileges(), SQLColumns(), SQLDescribeCol(), SQLExecDirect(), SQLExecute(), SQLExtendedFetch(), SQLFetch(), SQLForeignKeys(), SQLGetData(), SQLGetStmtOption(), SQLGetTypeInfo(), SQLPrepare(), SQLPrimaryKeys(), SQLProcedureColumns(), SQLProcedures(), SQLSetCursorName(), SQLSetStmtOption(), SQLSpecialColumns(), SQLStatistics(), SQLTablePrivileges(), and SQLTables().
A cursor is open on hstmt, and SQLFetch or SQLExtendedFetch was not called. Check the sequence of operations. For example, confirm that you are not trying to execute an EXECUTE statement before the PREPARE statement finishes.
One of the following problems occurred:
(1) The statement that is associated with the statement handle does not return a result set because there are no columns to describe. Change the statement so that it returns a result set. This problem can occur for SQLColAttributes() and SQLDescribeCol().
(2) You already opened a cursor for the statement handle. Use the cursor that you already opened. This problem can occur for SQLColumnPrivileges(), SQLColumns(), SQLExecDirect(), SQLExecute(), SQLForeignKeys(), SQLGetTypeInfo(), SQLPrepare(), SQLPrimaryKeys(), SQLProcedureColumns(), SQLProcedures(), SQLSpecialColumns(), SQLStatistics(), SQLTablePrivileges(), and SQLTables().
(3) The cursor was positioned before the start of the result set or after the end of the result set. Make sure that the cursor is positioned within the result set. This problem can occur for SQLExecDirect(), SQLExecute(), SQLGetData(), and SQLGetStmtOption().
(4) The statement handle was in an executed state, but no result set was associated with the statement handle. Make sure that a result set is associated with the statement handle. This problem can occur for SQLExtendedFetch(), SQLFetch(), and SQLGetData().
(5) You opened a cursor for the statement handle, but you did not call SQLFetch() or SQLExtendedFetch(). Call SQLFetch() or SQLExtendedFetch() after you open a cursor for a statement handle. This problem can occur for SQLGetData().
(6) The fOption value was SQL_ROW_NUMBER, but the cursor was not open. Open a cursor before you use an fOption value of SQL_ROW_NUMBER. This problem can occur for SQLGetStmtOption().
(7) The statement handle was already in an executed state or a cursor-positioned state. Do not call this function for a statement handle that has already been executed or is already in a cursor-positioned state. This problem can occur for SQLSetCursorName().
(8) The fOption value was SQL_CONCURRENCY, SQL_SIMULATE_CURSOR, or SQL_CURSOR_TYPE, and the cursor was open. Do not use an open cursor for one of these fOption values. This problem can occur for SQLSetStmtOption().
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-11031 fires when a function is called with a statement handle whose cursor isn't in the
required state — per the official guidance, this is the same as SQLSTATE value 24000,
returnable by a wide range of CLI functions (SQLColAttributes(), SQLColumnPrivileges(),
SQLColumns(), SQLDescribeCol(), SQLExecDirect(), SQLExecute(), SQLExtendedFetch(),
SQLFetch(), SQLForeignKeys(), SQLGetData(), SQLGetStmtOption(), SQLGetTypeInfo(),
SQLPrepare(), SQLPrimaryKeys(), SQLProcedureColumns(), SQLProcedures(),
SQLSetCursorName(), SQLSetStmtOption(), SQLSpecialColumns(), SQLStatistics(),
SQLTablePrivileges(), and SQLTables()).
- The statement's cursor not being in the state the called function requires, per the official guidance — the direct, only cause.
Solutions / Resolution
- Check the cursor's current state before calling the function, per the official guidance's implication, and bring it into the required state first (e.g. execute or re-prepare as needed).
Examples
N/A
No specific triggering statement is documented beyond calling a function while the cursor is in the wrong state.
Diagnostic Checks
- Check the sequence of CLI calls on this statement handle, and confirm the cursor was brought into the required state (open, executed, etc.) before the failing call.
Related Errors / Related Topics
- -11034 — "Invalid cursor name." A related cursor error, about the name referenced by a positioned statement not matching an open cursor, rather than a state mismatch.
A function was called while the statement's cursor was in the wrong state — check the call sequence.