|
From: Eric B. <eb...@ya...> - 2003-08-25 18:39:53
|
Christian,
I should've included some example code to help explain
what I was talking about. However, I'm glad you where
able to understand what I was saying.
Error handling is great because it helps find sloppy
mistakes that the compiler will not find. For
example, I was able to find mistakes where someone
did a query like "SELECT x FROM y", then did a
dbi_result_get_long("x_nm").
My error handler does an assert() so that it forces
the developers to fix the problem rather than ignoring
it or not realizing that it occurred.
The problem with ignoring BAD_IDX is that it's the
same error code that occurs in a while loop and the
same error code that occurs in the example I just
gave.
Usually, we used a for loop, like this:
rows = dbi_result_get_numrows(result);
for (row = 0; row < rows; row++) {
dbi_result_next_row(result);
column = dbi_result_get_string(result, "A");
printf("%s\n", column);
}
However, we switched to using a while loop to use
fewer lines of code, like this:
while (dbi_result_next_row(result)) {
column = dbi_result_get_string(result, "A");
printf("%s\n", column);
}
The quick fix I came up with, to avoid rewriting the
while loops back to for loops, was to create a wrapper
function:
int DbiResultNextRow(dbi_result Result)
{
dbi_result_t *result = Result;
if ((result != NULL) && (result->currowidx <
dbi_result_get_numrows(Result)))
{
return dbi_result_next_row(result);
}
else
{
return 0;
}
}
Thanks for your help.
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
|