Ex: Re: SP ODBC RetryOnError
Paul Henson
henson at signet.id
Mon Dec 12 22:47:40 UTC 2022
Okay, let's step back for a second and make sure we are operating under
the same understanding.
There is an outer loop, which iterates over each error code returned
from SQLGetDiagRec.
There is an inner loop, which iterates over each re-tryable error code
as stored in m_retries.
The outer loop can execute more than one time, or else why would it be a
loop and not a single path of execution?
Consider the case where there is an SQL ODBC failure resulting in two
error codes returned, 10 and 15. Error code 10 is re-tryable, 15 is not.
On the first execution of the outer loop native = 10. The inner loop
iterates over the single value 10 and executes:
res.first = (*n == native);
As *n is indeed equal to native (both being 10) res.first becomes true.
The first iteration of the outer loop completes, with a result of
res.first being true. Now, the second iteration of the outer loop
occurs, this time with native = 15. The inner loop again iterates over
the single value 10 and executes:
res.first = (*n == native);
As *n is not equal to native (the first being 10, the second being 15)
res.first is assigned the value false.
The second iteration of the outer loop completes, there are no more
error codes returned, and the function exits, with a final result of
res.first being false.
If the inner loop did something like:
if (*n == native)
res.first = true
Then yes, if any error code returned was re-tryable then the final value
of res.first would be true as indeed it is never explicitly set back to
false. However, the test in the inner loop implicitly sets it back to
false as the second time through the outer loop the comparison fails.
On 12/12/2022 5:24 AM, Cantor, Scott via users wrote:
>> I recognize that it is doing two separate checks, and returning two
>> boolean values. But unless I am really off of my rocker there are two
>> loops in the code:
>
> Yes, but the inner loop doing the retry check is bypassed as soon as a retryable code is found, so the first retryable error sets the return flag, and it doesn't matter which code happened to have been the one to trigger it.
>
>> However, if the outer loop executes multiple times, and the last error
>> code returned by it is not in the retry list, the final value of
>> res.first returned is false, even if it was set to true by the check in
>> one of the earlier iterations of the loop.
>
> Nothing in the outer loop resets the flag to false.
--
Signet - The Art of Access
https://www.signet.id/
More information about the users
mailing list