OCIStmtFetch error handling [message #94277] |
Mon, 28 June 2004 23:41 |
evan
Messages: 2 Registered: October 2002
|
Junior Member |
|
|
Greetings,
I am using OCI 8. Say following code model:
OCIStmtExecute("select .. from .. where ...");
while (1)
{
switch (OCIStmtFetch())
{
case OCI_SUCCESS:
handle the data;
break;
case OCI_NO_DATA:
return;
default:
// Error occur
}
}
My question is for error handling. Error might be "fetched column is NULL", etc. But anyway, it should be a record level. What I want to do is to skip the wrong record and process rest records.
And I am wondering when OCIStmtFetch returns error, can I get rowid or primary key value of the error record so that I can delete the error record?
Evan
|
|
|
Re: OCIStmtFetch error handling [message #94279 is a reply to message #94277] |
Tue, 29 June 2004 08:29 |
Nicholas Gray
Messages: 13 Registered: November 2000
|
Junior Member |
|
|
NULL_VALUE_RETURNED in fact doesn't have to be considered an error.
Usually a NULL value hold some "kinda" information anyway.
Otherwise the record wouldn't exist in the first place.
So if you just want to ignore all fetched NULL results add a:
case NULL_VALUE_RETURNED:
handle_data_or_ignore_and_do_nothing;
break;
to your example and just fetch the next record.
|
|
|
|
Re: OCIStmtFetch error handling [message #94281 is a reply to message #94280] |
Tue, 29 June 2004 08:50 |
Nicholas Gray
Messages: 13 Registered: November 2000
|
Junior Member |
|
|
And I think you might have to use a checkForError(OCIStmtFetch()) ...
int checkForError(int res)
{
sb4 rc = 0;
if (res == -1)
{
OraText errorBuffer[[SQLMERR]];
OCIErrorGet (errhp, (ub4) 1, (OraText *) NULL, &rc, errorBuffer, (ub4) sizeof(errorBuffer), OCI_HTYPE_ERROR);
}
else
{
rc = res;
}
return (rc);
}
|
|
|