-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Wrong value returned from Statement::getUpdateCount, after Statement::getMoreResults call #703
Comments
Firebird does not have update counts as a separate result, so Jaybird must explicitly request an update count from the server at the appropriate time using a "statement information request". It is not something that the server automatically pushes to the client, and there is no way to detect that a statement does not produce an update count (i.e. did not execute any modifying DML). In Firebird, even selects can produce an update count (e.g. if it directly or indirectly references a selectable stored procedure with modifying DML). So, to be able to return update counts at all, Jaybird uses a simple state-machine for the current statement execution, In other words, this is a trade off between providing too little information (no update counts when there are), or too much information (providing a 0 update count, when the statement wouldn't do any modification). |
I do see that for DDL, the first result should probably be NO_MORE_RESULTS, and not UPDATE_COUNT like it does right now. |
Interesting. I did think there must be a reason that isn't strictly a bug. Would you be interested in documenting this also on stack overflow? I could repeat my question on there, to make your useful answer more widely available. |
I was verifying my assumptions, and I found out that my belief that selectable stored procedures with modifying DML have a non-zero update count when requested is actually incorrect. In other words, it is actually a bug. There is one complication, Firebird 5 will identify DML with a RETURNING clause as a select-statement (for backwards compatibility) to allow it returning multiple rows (as opposed to the single row it can produce in Firebird 4 and older), which means that to fix this, Jaybird itself will need to perform identification of the actual statement type by parsing the statement. |
Other wrinkle, an |
Excellent, thanks a lot for the analysis! |
I'm not going to fix this in Jaybird 4, as that version doesn't yet use the new parser introduced with #680, and backporting it, or using the old parser is too much work. I will do this for Jaybird 5. |
I'm also going to exclude other statements that don't produce an update count. I'm wondering what to do with |
Forgot one option for |
I forgot about server-side batch behaviour, there using |
Can you show an example? |
I have basically already decided to continue reporting A very simple example (one for jaybird/src/test/org/firebirdsql/jdbc/BatchUpdatesTest.java Lines 278 to 324 in 6c71bac
Given this executes a stored procedure, the client-side emulated batch would - without intervention - produce update counts |
Try this code:
It produces this output:
The last value should be
-1
, not0
From the
getMoreResults()
Javadoc:From the
getUpdateCount()
Javadoc:Debugging this a bit further, there seems to be an intermediary update count of 0 that is being returned:
This now produces:
Given the query, I don't see a good reason for this update count to be returned.
The text was updated successfully, but these errors were encountered: