Bug #21588 Incomplete ODBC API implementaion
Submitted: 11 Aug 2006 15:27 Modified: 26 Mar 2007 6:40
Reporter: Shawn Green Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:3.51.12 OS:Microsoft Windows (Win32)
Assigned to: Jim Winstead CPU Architecture:Any
Tags: SQLEndTran, SQLTransact

[11 Aug 2006 15:27] Shawn Green
Description:
The ODBC API specifies that transactions can be closed two ways, depending on your version: SQLTransact() (a deprecated function) or SQLEndTran()

We have a customer using a data library from Computer Associates (CA) that calls the SQLTransact() function without specifying a connection handle. This is _permitted_ by the API as long as the environment handle is populated. 

The expected behavior is that all of the connections bound to that environment handle would either be committed or rolled back based on the value of the third parameter to the call. Here is an excerpt from an ODBC log demonstrating the call:

app025x         d6c-ab0	ENTER SQLTransact 
		HENV                003C1788
		HDBC                00000000
		UWORD                        0 <SQL_COMMIT>

One portion of this bug is in our implementation of SQLTransact(). Whenever the HDBC parameter is null, the boundary checking IF() block fails directly to a SQL_SUCCESS code.  No handling of the documented, permitted case is implemented.

The other portion of this bug is in how the SQLEndTran() function handles the same situation. Please refer to the following comment in the code:

case SQL_HANDLE_ENV:
    /*
      TODO : The simple logic could be to call my_transact
      with all connection handles in the current environment,
      but as majority of the applications doesn't use this
      option, lets wait for the request or any bug-report
    */
    break;

Even if CA modifies their library to use the non-deprecated function SQLEndTran() but still makes the call to process all connections in this environment, our implementation will still fail.

How to repeat:
See description for how to cause the failure

Suggested fix:
Correct the source code so that it meets the ODBC API specification for handling COMMIT and ROLLBACK statements that are applied to an entire group of connections at once.
[8 Mar 2007 2:02] Jim Winstead
The SQLEndTran() case has been fixed, but not SQLTransact().
[9 Mar 2007 0:25] Jim Winstead
Patch to fix SQLTables called with only an environment handle

Attachment: bug21588.patch (application/octet-stream, text), 21.63 KiB.

[20 Mar 2007 18:19] Jim Winstead
Fix pushed into the tree, will be in the 3.51.15 release.
[26 Mar 2007 6:40] MC Brown
A note has been added to the 3.51.15 changelog.