Cancel results for user automatically #563
Open
+167
−96
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to #539
FreeTDS enforces a strict sequence of how queries are sent and results are retrieved. To summarize it very briefly:
dbopen
.dbcmd
.dbsqlsend
.dbsqlok
.dbdbresults
.dbnextrow
or cancel the running results (dbcancel
)dbclose
if not cancelled.You do not have to serialize / bind each retrieved result, but you still need to fetch them. This is mentioned in the sample code as well:
The current implementation of
do
andinsert
perform the entire sequence. However,each
works different: Sinceeach
lazy-loads each result from the server, it cannot perform the entire sequence as we do not want to fetch all results at once and the user is free to cancel the iterator early.As mentioned on #539, the error
Assertion conn->in_net_tds == NULL'
likely occured when people did not callcancel
on the result object, as the query is technically still pending from FreeTDS point-of-view.FreeTDS also mentions:
With this PR, in
#execute
, I check if we have to still acknowledge and fetch results prior to running another query, essentially doing the job ofcancel
automatically for the user.This is not my initially proposed solution on #539. I have coded out that proposed solution as well in a different branch, but during that development, I imagined that people could run into issues when a query will produce a large result set. But it helped me to understand the request lifecycle of FreeTDS better in order to develop this solution.