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

Update SQLCancel.c #161

Merged
merged 1 commit into from
Mar 9, 2024
Merged

Update SQLCancel.c #161

merged 1 commit into from
Mar 9, 2024

Conversation

matthew-wozniczka
Copy link
Contributor

Refactored how SQLCancel checks for the driver returning 01S05 to be a bit easier to read, and a tiny bit faster (Can skip a call to SQLGetDiagField/SQLGetDiagFieldW)

Refactored how `SQLCancel` checks for the driver returning 01S05 to be a bit easier to read, and a tiny bit faster (Can skip a call to `SQLGetDiagField`/`SQLGetDiagFieldW`)
@lurcher
Copy link
Owner

lurcher commented Mar 9, 2024 via email

@lurcher lurcher merged commit 68db014 into lurcher:master Mar 9, 2024
@matthew-wozniczka
Copy link
Contributor Author

Yeah actually I did notice that and think that might be a problem, but didn't wanna get into it, then forgot about even reporting it.

@matthew-wozniczka
Copy link
Contributor Author

Actually... I was only looking at this file because I'm currently trying to debug a weird hang in our tests which seems to occur within the loop I modified in this pull request.

And it's on AIX, using PowerPC, a big-endian processor! And the tests which are hanging ARE testing the case where the connection has been configured as an ODBC 2.X connection, and SQLCancel is causing the cursor to be closed.

But I don't see how messing up the check like this can cause some sort of infinite loop, so I dismissed that as the cause.

@matthew-wozniczka
Copy link
Contributor Author

matthew-wozniczka commented Mar 11, 2024

One other thing I just noticed while staring at the loop is that it's using a SQLCHAR buffer, but passing it as SQLWCHAR* for unicode drivers.

This is actually unsafe, as there can be alignment issues, which can cause bus error signals, or at least lower performance (sometimes greatly)

It's safer to use a SQLWCHAR buffer, since that will surely be aligned for SQLCHAR (which I'm pretty sure is guaranteed to be char, and thus not need any special alignment)

@matthew-wozniczka
Copy link
Contributor Author

matthew-wozniczka commented Mar 11, 2024

Also, doesn't unixODBC support being compiled w/ SQLWCHAR == UTF-32? This code assumes UTF-16

@matthew-wozniczka
Copy link
Contributor Author

matthew-wozniczka commented Mar 11, 2024

unixODBC already has code to translate from SQLGetDiagFieldW -> SQLGetDiagField, so maybe it would be simpler to simply reuse it here and always compare against "01S05"?

@matthew-wozniczka matthew-wozniczka deleted the patch-1 branch March 11, 2024 07:15
@lurcher
Copy link
Owner

lurcher commented Mar 11, 2024 via email

@lurcher
Copy link
Owner

lurcher commented Mar 11, 2024 via email

@matthew-wozniczka
Copy link
Contributor Author

matthew-wozniczka commented Mar 11, 2024

ah, I think I may know why I have a 'hang': When the old code was fetching the number of diagnostic records, it was using SQLULEN, but that field is documented to be SQLINTEGER.

Now, on little-endian platforms, this doesn't matter, since it initializes the variable to 0.

But on big-endian platforms, in 64-bit mode, it's incorrectly interpreting the returned value as 2^32 times MORE than what the driver actually tried to report.

That, combined with the early-exit from the loop being broken on big-endian platforms would probably result in something that I (actually our test automation) could misinterpret as a hang.

@matthew-wozniczka
Copy link
Contributor Author

AFAIK, the buffer that's being compared is
already being set in a way that should work for both 2 and 4 byte
SQLWCHAR, as should the rest of the code.

I don't see how, as the memcmp hardcodes the comparison length to 10?

@lurcher
Copy link
Owner

lurcher commented Mar 11, 2024 via email

@lurcher
Copy link
Owner

lurcher commented Mar 11, 2024 via email

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

Successfully merging this pull request may close these issues.

2 participants