Bug #68185 MYSQL ODBC 64bit connector, does not handle null appropriatly
Submitted: 26 Jan 2013 1:40 Modified: 31 May 2013 7:39
Reporter: sushil sharma Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:mysql-connector-odbc-5.2.2-1.rhel5.x86_6 OS:Linux (Red Had Linux 5.7)
Assigned to: Bogdan Degtyariov CPU Architecture:Any

[26 Jan 2013 1:40] sushil sharma
Description:
I am using mysql odbc connector version 5.2.2 on a Red Hat linux machine. I am trying to use it with IBM Datastage 8.7 product. We encountered an issue with the driver when it tries to select the data and encounter a null record in the data base it is not buffering the pcbValue correctly.

I wrote a simple C program to test this and following condition is not resulting true while it should be true:

After the fetch, the following check for null should have been true.

if (dlp->pcbValue == SQL_NULL_DATA)
{
printf("<sqlnull>\n");
}

I checked the ODBC Specs on the  http://download.oracle.com/otn_hosted_doc/timesten/703/TimesTen-Documentation/ms.odbc.pdf

On page 77 they specify this:

If an application specifies a return value parameter for a procedure that does not return
a value, the driver sets the pcbValue buffer specified in SQLBindParameter for the
parameter to SQL_NULL_DATA.

Exactly this is the condition that is failing.
The issue is related to the last argument of the SQLBindCol call.

rc = SQLBindCol(hstmt, (UWORD)i, (SWORD)SQL_C_CHAR, dlp->strvaltext, (signed long) (dlp->strvallen+1), &(dlp->pcbValue));

MySQL driver being used has treated pcbValue as a 32 bit quantity and when assigned to the 64 bit variable, it evaluates to 4294967295, which is what being printed as pcbValue by their testprog2.  Therefore, it doesn't think the column is NULL. What needs to be determined is whether libmysql5w.so (and underlying libodbc.so?) define the SQLLEN type to be 8 bytes.

How to repeat:
I will attach the C program testprog2 which demonstrates this behaviour.

Suggested fix:
Make the 64bit mysql odbc connector compliant to odbc specs.
[29 Jan 2013 7:58] Bogdan Degtyariov
Thanks for the detailed report and for the test case.
However, I do not see how the documentation page you are referring is related to the current case. There is no stored procedure, just a normal SQL query.

One question: which ODBC driver manager you are using? Is that UnixODBC? Which version?

I am asking because UnixODBC versions older than 2.2.14 had different mapping for 64-bit types, which could lead to a mismatch.
[1 Mar 2013 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[31 May 2013 7:39] Bogdan Degtyariov
I'm closing this bug because I can not continue without feedback from the reporter. If you have new info, please reopen the report.