Bug #72311 SQLCloseCursor Does Not Return Correct Error
Submitted: 10 Apr 2014 19:25 Modified: 20 Mar 16:49
Reporter: Lawrenty Novitsky Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:5.3.2 OS:Any
Assigned to: CPU Architecture:Any

[10 Apr 2014 19:25] Lawrenty Novitsky
Description:
SQLCloseCursor simply forwards request to SQLFreeStmt(SQL_CLOSE)

But "SQLCloseCursor returns SQLSTATE 24000 (Invalid cursor state) if no cursor is open. Calling SQLCloseCursor is equivalent to calling SQLFreeStmt with the SQL_CLOSE option, with the exception that SQLFreeStmt with SQL_CLOSE has no effect on the application if no cursor is open on the statement, while SQLCloseCursor returns SQLSTATE 24000 (Invalid cursor state)."

(http://msdn.microsoft.com/en-us/library/ms709301%28v=vs.85%29.aspx)

How to repeat:
SQLExecDirect(hstmt, <any ddl statement>);
SQLCloseCursor(hstmt);

Supposed to return SQL_ERROR and 24000 sql state

Suggested fix:
Add check of resultset existence to SQLClosrCursor
[25 Feb 8:26] Rafal Somla
Posted by developer:
 
We think the expected behavior of SQLCloseCursor() should be this:

1. If no cursor is open for the statement then report error 24000 (Invalid cursor state) and do nothing more.

2. Otherwise do the same thing as SQLFreeStmt(SQL_CLOSE), which should either succeed or report relevant error.
[17 Mar 3:58] Bogdan Degtyariov
Posted by developer:
 
The fix for the problem is as follows: SQLCloseCursor() function returns errors each time it is called when no result set is available for the statement.
It gives SQL State: 24000 and error message: Invalid cursor state.
The patch has been pushed into the source tree.
[20 Mar 16:49] Daniel So
Posted by developer:
 
Added the following entry to the C/ODBC 9.3.0 changelog: 

"If the SQLCloseCursor() method was called when no result set was available, no error was returned. With this patch, the method returned SQL State: 24000 and error message Invalid cursor state in the situation."