-
Notifications
You must be signed in to change notification settings - Fork 74
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
Miscellaneous bug and pyodbc compatibility fixes #13
Conversation
NamedTupleRow and MutableNamedTupleRow depend on _ColBufferList being populated, so without this change they do not work.
This is consistent with pyodbc.
I think out-of-the-box compatibility with pyodbc is a worthy goal. I understand not wanting a hard dependency on 'recordtype' but at least providing read-only named field access seems like an improvement.
I've run into memory corruption bugs with the following test program on 64-bit Linux, sizeof(wchar_t) == 4, sizeof(Py_UNICODE) == 4, sizeof(SQLWCHAR) == 2. from pypyodbc import connect # Replace '...' with real values conn_string = 'DRIVER={SQL Server};SERVER=...;PORT=1433;UID=...;PWD=...;TDS_Version=7.1;APP=...;DATABASE=...' while True: connect(conn_string, ansi=False) For me this typically causes libc to abort() complaining of memory corruption, double-free, etc. within a few tens of iterations with cpython (and quicker with pypy). The bug seems to be in the conversion from Python string to SQLWCHAR * when calling SQLDriverConnectW. Given the sizes above, pypyodbc sets wchar_pointer = ctypes.c_char_p, then passes a UTF-16-encoded byte buffer to it. ctypes.c_char_p null-terminates the string when converting to a C array - but it only adds a single NUL byte. unixODBC expects that argument to be a UTF-16 array, terminated by two NUL bytes. This fix is a bit of a hack, but it does work. It might be clearer to define something akin to c_char_p for these arguments, I suppose.
Ping? I've been running this branch for a while, and it still seems to work. :) |
@@ -26,7 +26,7 @@ | |||
paramstyle = 'qmark' | |||
threadsafety = 1 | |||
version = '1.3.0' | |||
lowercase=True | |||
lowercase = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably will affect projects with lowercase names everywhere.
This code makes more compatible with pyodbc, I will plan to make proper testing before. Thanks. |
You should take a look at PR #14 – it contains all of these patches plus one extra fix from @batterseapower. |
Here are some fixes and changes I needed to make to drop pypyodbc into a project which currently uses pyodbc. I think being compatible out-of-the-box is a good thing to aim for(?). I haven't run any of the test suites, I'm afraid, but it seems to work in my project!