Bug #33910 SQLGetDiagRec Returns 0 with no error message
Submitted: 17 Jan 2008 21:49 Modified: 13 May 2008 13:53
Reporter: John Water Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:5.1 beta OS:Linux (Linux XXX 2.6.11.7 #1 SMP Mon Jan 29 15:19:26 EST 2007 x86_64 x86_64 x86_64 GNU/Linux)
Assigned to: Jim Winstead
Tags: ODBC, SQLGetDiagRec
Triage: D4 (Minor)

[17 Jan 2008 21:49] John Water
Description:
With the MyODBC driver 5.1 beta on LINUX, the SQLGetDiagRec function could return 0 -- SQL_SUCCESS with empty ODBC state and error message and zero native error.  If there is no error on the connection and environment levels, this function should return 100 -- SQL_NO_DATA.
By the way, the driver behaves well on Windows.

How to repeat:
Here are the steps to repro:

1) Build the application with the attached source code;

2) Run the app against MySQL on LINUX, the command line can be
       odbcbug "dsn=your_dsn;uid=your_uid;pwd=your_pwd"
then you'll get the following output:
Call SQLGetDiagRec with SQL_HANDLE_STMT:
SQLGetDiagRec returns 0
SQLSTATE     = 23000
NATIVE ERROR = 1062
ERRMSG LEN   = 89
ERROR MSG    = [MySQL][ODBC 5.1 Driver][mysqld-5.1.22-rc-community]Duplicate entry '1' for key PRIMARY'
SQLGetDiagRec returns 100
Call SQLGetDiagRec with SQL_HANDLE_DBC:
SQLGetDiagRec returns 0
SQLSTATE     = 
NATIVE ERROR = 0
ERRMSG LEN   = 0
ERROR MSG    = 
SQLGetDiagRec returns 100
Call SQLGetDiagRec with SQL_HANDLE_ENV:
SQLGetDiagRec returns 0
SQLSTATE     = 
NATIVE ERROR = 0
ERRMSG LEN   = 0
ERROR MSG    = 
SQLGetDiagRec returns 100

3) If you run this app against Oracle, you'll get 
Call SQLGetDiagRec with SQL_HANDLE_STMT:
SQLGetDiagRec returns 0
SQLSTATE     = 23000
NATIVE ERROR = 1
ERRMSG LEN   = 106
ERROR MSG    = [Oracle][Oracle][Oracle]ORA-00001: unique constraint (TEST.SYS_C006163274) violated
SQLGetDiagRec returns 100
Call SQLGetDiagRec with SQL_HANDLE_DBC:
SQLGetDiagRec returns 100
Call SQLGetDiagRec with SQL_HANDLE_ENV:
SQLGetDiagRec returns 100
[9 Apr 2008 2:24] Jim Winstead
Fix detection of when there are no errors. Could not construct a test for the test suite for this, but verified with supplied code.

Attachment: bug33910.diff (text/plain), 362 bytes.

[9 Apr 2008 13:13] Lawrenty Novitsky
approved
[9 Apr 2008 16:59] Jim Winstead
The fix for this bug has been committed, and will be part of the 5.1.4 release.
[13 May 2008 13:53] Paul Dubois
Noted in 5.1.4 changelog.

On Linux, SQLGetDiagRec() returned SQL_SUCCESS in cases when it
should have returned SQL_NO_DATA.