Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calls to SQLBindParameter causes libiodbc to return SQL_INVALID_HANDLE on Big Sur #85

Open
alinaliBQ opened this issue Apr 6, 2023 · 8 comments

Comments

@alinaliBQ
Copy link

alinaliBQ commented Apr 6, 2023

Our driver does not support SQLBindParameter, so we define SQLBindParameter to return SQL_ERROR save a statement diagnostic message saying that "SQLBindParameter is not supported", but calls to SQLBindParameter causes libiodbc to return SQL_INVALID_HANDLE on Big Sur GitHub instance.

Steps to reproduce

  1. Install libiodbc on Big Sur GitHub instance.
        brew tap homebrew/services
        brew unlink unixodbc
        brew install libiodbc
        brew link --overwrite --force libiodbc
  1. Call SQLBindParameter.
// connect to driver and allocate SQLHSTMT stmt.
  SQLINTEGER sqlint;
  SQLLEN len = SQL_DATA_AT_EXEC;

  SQLRETURN ret = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_LONG,
                                   SQL_INTEGER, 0, 0, &sqlint, 0, &len);
  1. SQL_INVALID_HANDLE is returned from SQLBindParameter.
    Looking at the logs, libiodbc never calls SQLBindParameter using our driver, and returns SQL_INVALID_HANDLE directly.

Expected outcome: SQL_ERROR is returned as our driver has defined SQL_ERROR to be returned from SQLBindParameter. And application is able to get statement diagnostic message saying that "SQLBindParameter is not supported". On Linux and Windows (not using iODBC), the correct behavior is observed. On macOS Ventura with iODBC application (OpenLink ODBC Administrator.app) installed, this correct behavior is observed. I'm unsure what had caused libiodbc to have undefined behavior on macOS Big Sur.

More context: The driver built on Big Sur is tested on Big Sur GitHub instance only. The driver built on Ventura is tested on Ventura only.

@smalinin
Copy link
Collaborator

smalinin commented Apr 6, 2023

Function SQLBindParameter (from libiodbc ) could not return SQL_INVALID_HANDLE because such case isn't existed in the source code.

SQLBindParameter_Internal (

Attach here your log file for issue.

@alinaliBQ
Copy link
Author

alinaliBQ commented Apr 6, 2023

Let me clarify, I believe when calling SQLBindParameter with libiodbc installed, libiodbc does not sent the call of SQLBindParameter to my driver. And the case of SQL_INVALID_HANDLE being returned should exist in libiodbc, and the logic should be in CALL_DRIVER, where retcode is changed.

CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc3,

I don't have logs directly from libiodbc, only logs from my driver which does not show SQLBindParameter being called. If you could kindly point me to a place where I can find a way to get logs from libiodbc (similar to ODBC tracing on iODBC Application), it would be greatly appreciated.

Here is a simplified log (with added message) from my driver:

SQLGetInfoW: SQLGetInfo called: 23 (SQL_CURSOR_COMMIT_BEHAVIOR), return int result 1
SQLGetInfoW: SQLGetInfo called: 24 (SQL_CURSOR_ROLLBACK_BEHAVIOR), return int result 2
SQLAllocHandle: SQLAllocHandle called with type 3
SQLAllocStmt: SQLAllocStmt called
SQLGetStmtAttrW: SQLGetStmtAttr called with attr 10010
SQLGetStmtAttrW: SQLGetStmtAttr called with attr 10011
SQLGetStmtAttrW: SQLGetStmtAttr called with attr 10012
SQLGetStmtAttrW: SQLGetStmtAttr called with attr 10013
// This is supposed to be where SQLBindParameter is called. 
// On Windows, the logs show that SQLBindParameter is being called, but not on libiodbc on macOS.
SQLFreeHandle: SQLFreeHandle called with type 3
SQLFreeStmt: SQLFreeStmt called [option=1]
SQLDisconnect: SQLDisconnect called
SQLFreeHandle: SQLFreeHandle called with type 2
SQLFreeConnect: SQLFreeConnect called
SQLFreeHandle: SQLFreeHandle called with type 1
SQLFreeEnv: SQLFreeEnv called

@TallTed
Copy link
Contributor

TallTed commented Apr 9, 2023

@alinaliBQ — The "ODBC Tracing on Mac OS X" section of this article should provide the detailed instructions you want...

@alinaliBQ
Copy link
Author

alinaliBQ commented Apr 10, 2023

@TallTed Thanks for the link! I have shared it with my colleagues working with macOS who might find it useful. However, the instructions are for OpenLink ODBC Administrator.app and doesn't explicitly say that it can also work in an environment where only libiodbc is installed (using brew install libiodbc) and without the OpenLink ODBC Administrator app. So I'm not sure if that will work. During my tests, the issue with SQLBindParameter does not occur with OpenLink ODBC Administrator.app, only with libiodbc (installed using brew install libiodbc).

Currently my hands are tied with other items to work on, but when I do get a chance to try it out, I will post updates here.

@TallTed
Copy link
Contributor

TallTed commented Apr 10, 2023

@alinaliBQ — The trace functionality described is in the iODBC libraries, not in the Administrator app. You should find that editing or adding the described stanzas to the active odbc.ini and/or adding the described keywords and values to a fileDSN or to a DSN-less connect string, results in production of the requested logs.

Given the extra details you've just provided — that "During [your] tests, the issue with SQLBindParameter does not occur with OpenLink ODBC Administrator.app, only with libiodbc (installed using brew install libiodbc)." — I'm thinking that the Homebrew package may be outdated or have some other error (though it looks OK at first glance).

Please do be aware that Homebrew and other command-line tools can use the libraries installed with the iODBC Administrator.app (equivalent to the OpenLink ODBC Administrator.app), so this may be your fastest path to success, given your latest.

I'm sure our developers will also make more rapid progress analyzing the issue, given your latest.

@alinaliBQ
Copy link
Author

@TallTed Thank you for the update and the information. I have now updated the GitHub issue to clarify that the issue does not occur with OpenLink ODBC Administrator.app.

@smalinin
Copy link
Collaborator

smalinin commented Apr 11, 2023

You could do next:

  1. Add the next to your odbc.ini , for enable trace iODBC
[ODBC]
Trace         = 1
TraceFile     = /Users/myuid/odbc.log

but it may not help much you for detailed analyze issue
2. build IODBC binaries with debug info and without optimization for use with debugger

  • checkout iODBC sources from github, than run next commands in console for build
$ autogen.sh
$ export CFLAGS='-O0 -g -mmacosx-version-min=10.9 -arch arm64'
$ export LDFLAGS='-g'
$ ./configure --disable-gui --disable-shared --with-pic --prefix=/usr/local/debugODBC
$ make
$ make install
  1. Link your test App with new debugODBC library, than run your test app under lldb , set breakpoint on iODBC function SQLBindParameter_Internal and trace.

@alinaliBQ
Copy link
Author

@smalinin Thanks so much for the detailed steps. Recently I have been assigned to also work on another project, and the rest of the team likely won't be able to have time to investigate for this ticket in the near future given the timelines we have. This issue is not a blocking issue with our driver. I think the issue likely has to do with discrepancies between Homebrew package for Big Sur and the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants