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

Handle runtime error on Base.iterate #353

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

pankgeorg
Copy link
Contributor

@pankgeorg pankgeorg commented Sep 29, 2022

API.SQLFetchScroll(API.getptr(x.stmt), API.SQL_FETCH_NEXT, 0) may return an error after only some of the results have been loaded. In the current implementation the error is ignored and iterate just stops the iteration, returning all the rows up to this point.

With this edit, the iteration will either warn the user or throw an error, consistent with the behaviour of @checkresult.

Should fix #352

In a weird sense this is technically a breaking change - as queries that returned early with a subset of results will now raise an error. In the grand scheme of things though I think tihs is a good change.

src/dbinterface.jl Outdated Show resolved Hide resolved
if status == API.SQL_ERROR || status == API.SQL_INVALID_HANDLE
error(API.diagnostics(x.stmt))
end
status == API.SQL_STILL_EXECUTING || break
end
status == API.SQL_SUCCESS || status == API.SQL_SUCCESS_WITH_INFO || return nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
status == API.SQL_SUCCESS || status == API.SQL_SUCCESS_WITH_INFO || return nothing

Hmmm, I think we can remove this now? Since we're already erroring if it's an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can't, because it gets triggered after the last row is fetched. We need it to return nothing as requested by Base.iterate API here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that code is SQL_NO_DATA; I've updated the PR to take recognize its existence implicitly 😄

@quinnj
Copy link
Member

quinnj commented Oct 4, 2022

Hmmm, I wonder if I messed up the logic there since the tests are now failing consistently.

@pankgeorg
Copy link
Contributor Author

Hmmm, I wonder if I messed up the logic there since the tests are now failing consistently.

I had a bug with the scoping of status at the beginning; as I understand it, there is a SQL Status that is not an error and not success, triggered after the last row, so we do need this line JuliaDatabases/ODBC.jl@39a3bcd (#353)

status == API.SQL_STILL_EXECUTING && continue
status == API.SQL_SUCCESS && break
status == API.SQL_NO_DATA && return nothing
status == API.SQL_NTS && return nothing
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is based on the previous behaviour, which may be hiding a small bug. Not sure what we need to do if we get this (and I haven't stumbled upon it)

@pankgeorg pankgeorg force-pushed the pg/checkerrors-on-iterate branch 2 times, most recently from 425db32 to 56e94de Compare October 4, 2022 20:27
@codecov
Copy link

codecov bot commented Oct 4, 2022

Codecov Report

Merging #353 (d710aaf) into main (8226ef9) will increase coverage by 1.86%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #353      +/-   ##
==========================================
+ Coverage   75.00%   76.86%   +1.86%     
==========================================
  Files           6        6              
  Lines         856      860       +4     
==========================================
+ Hits          642      661      +19     
+ Misses        214      199      -15     
Impacted Files Coverage Δ
src/dbinterface.jl 92.96% <100.00%> (+0.14%) ⬆️
src/API.jl 62.58% <0.00%> (+5.10%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@pankgeorg pankgeorg force-pushed the pg/checkerrors-on-iterate branch from 56e94de to d710aaf Compare October 4, 2022 20:49
@quinnj quinnj merged commit 2d61d28 into JuliaDatabases:main Oct 4, 2022
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.

SQL Query returns wrong number of rows instead of Divide by Zero error encountered (8134) (SQLFetch)
2 participants