-
Notifications
You must be signed in to change notification settings - Fork 161
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
bug in SQLMoreResults? #466
Comments
Hello, I know its old but have you found a workardound? I might be experiencing the same or similar although I do not have source code for the application I am trying to run to fully verify it. |
Do you have some example queries/code? |
I didn't find any workaround to handle the issue and I am fairly certain it is a bug, maybe in SQLMoreResults. I've written a quick and dirty test to show the issue: SQL code:
C code:
Output when running with Microsoft SQL Server ODBC driver:
Output when running FreeTDS driver:
You can see that Microsoft's driver correctly identify the total affected rows in both cases, where FreeTDS driver fails in the second one. |
Thanks for the test. Yes, there are some minor differences on FreeTDS and Microsoft... and also, believe it or not from Microsoft and Microsoft! A bit surprised this difference with |
I just tried using With the Microsoft driver the results are exactly the same, it is however different with the FreeTDS driver. Unfortunatelly the difference is not in a good way:
As you can see, when using Prepare/Execute instead of ExecDirect both queries fail in calculating the total affected rows. I am aware that there are differences between the drivers, and it is fine, but my issue is that I cannot figure out any way of calculating the total affected rows using FreeTDS. To add to the test, by creating a new procedure:
Again - Microsoft's driver correctly calculates 3 rows affected, FreeTDS says 1 row is affected, regardless of whether it is called via SQLExecDirect or SQLPrepare/SQLExecute. Any hint what I can try to work around that? |
Since I do not have source code for the application I have to either relicate the same behavior at the driver level or rewrite all existing stores procedures. Any possibility of FreeTDS matching the Microsoft driver regarding this? |
Try to reproduce. A workaround could be something like CREATE PROCEDURE usp_add_trash_three
AS
BEGIN
INSERT INTO trash (id) VALUES (NEWID()), (NEWID()), (NEWID());
END (if possible) |
This is a valid workaround indeed, unfortunately it is very limited - only applies to INSERTS, these INSERTS must be for the same table with the same id list and you cannot have any statements between the inserts. |
Sure, I didn't say I'm not going to fix it. |
I am trying to use freetds ODBC driver together with Microsoft ODBC driver (same application, different OS), but there seems to be inconsistency in SQLMoreResults behavior and I am not quite sure how to work around it.
I am using SQLExecDirect to execute a batch of statements, and I need to read the total rows affected. Since the batch contains multiple commands, I have to use SQLMoreResults to iterate over all results and sum those. The code is something like this:
Trying the code with multiple INSERT statements works fine in both Microsoft and FreeTDS driver - for each, minus one, INSERT the SQLMoreResults call returns SQL_SUCCESS, and the next SQLRowCount reads it.
The problem arise when instead of INSERT statements (which is just for testing purposes really, multiple inserts can be done in a single statement and SQLRowCount works fine there), I use multiple EXECUTE statements. Then Microsoft's driver works as expected - one successful SQLMoreResults for each, minus one, EXECUTE statement, and total sum matches the expected result. Unfortunately FreeTDS version of SQLMoreResults for some reason returns SQL_NO_DATA (100) immediately and SQLRowCount is read only for the first EXECUTE.
Is this a known issue? Can I work around it somehow?
The text was updated successfully, but these errors were encountered: