Ex: Re: SP ODBC RetryOnError
Paul Henson
henson at signet.id
Fri Dec 9 05:09:52 UTC 2022
On 12/8/2022 1:11 PM, Cantor, Scott via users wrote:
> I hope I didn't actually write all that, despite having committed it,
> it's hideous
Heh, I have no idea if you wrote that or not, but I have definitely
looked at things I did in my younger years (not just coding) and
wondered WTF I was thinking when I did it ;).
> but what it's doing is simultaneously doing two separate checks.
[...]
> The loop is against the retry list, there's only one error code coming back.
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:
// start of first loop, running as long as SQLGetDiagRec succeeds
do {
ret = SQLGetDiagRec(htype, handle, ++i, state, &native, text,
sizeof(text), &len);
if (SQL_SUCCEEDED(ret)) {
m_log.error("ODBC Error: %s:%ld:%ld:%s", state, i, native,
text);
// second loop, iterating over retry error codes
for (vector<SQLINTEGER>::const_iterator n =
m_retries.begin(); !res.first && n != m_retries.end(); ++n)
res.first = (*n == native);
if (checkfor && !strcmp(checkfor, (const char*)state))
res.second = true;
}
// end of first loop
} while(SQL_SUCCEEDED(ret));
The outer loop repeatedly calls SQLGetDiagRec and continues until a call
to it fails. Within the outer loop, the inner loop checks to see whether
or not the error code returned is in the list of codes to retry, and if
so, sets res.first to true.
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.
https://i.imgflip.com/2bekbc.jpg?a463992
:)
--
Signet - The Art of Access
https://www.signet.id/
More information about the users
mailing list