Home » Developer & Programmer » Precompilers, OCI & OCCI » OCIStmtFetch error handling
OCIStmtFetch error handling [message #94277] Mon, 28 June 2004 23:41 Go to next message
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 Go to previous messageGo to next message
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 #94280 is a reply to message #94279] Tue, 29 June 2004 08:45 Go to previous messageGo to next message
Nicholas Gray
Messages: 13
Registered: November 2000
Junior Member
PS: #define NULL_VALUE_RETURNED 1405
Re: OCIStmtFetch error handling [message #94281 is a reply to message #94280] Tue, 29 June 2004 08:50 Go to previous message
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);
}
Previous Topic: Pro*c Include File
Next Topic: weird No data found error in Pro*C code. Pls help
Goto Forum:
  


Current Time: Tue Apr 16 04:16:37 CDT 2024