int ociw_error_info(db_wrap * self, char const ** dest, size_t * len, int * errCode) { if (! self) return DB_WRAP_E_BAD_ARG; #if 1 /* workaround for per-connection error info not being available to us for reasons which haven't been fully determined. This does NOT provide the exact same semantics as the underlying driver, which appears to re-set the error information on each call into the API. Our problem appears to be that we sometimes have several OCI calls before we check the error state, and the error state is gone by the time we can get around to fetching it. */ if (dest) *dest = ociw_error_info_kludge.errorString; if (len) *len = ociw_error_info_kludge.errorString ? strlen(ociw_error_info_kludge.errorString) : 0; if (errCode) *errCode = ociw_error_info_kludge.ociCode; #else OCI_Error * err = OCI_GetLastError(); if (! err) { if (dest) *dest = NULL; if (len) *len = 0; if (errCode) *errCode = 0; return 0; } char const * msg = OCI_ErrorGetString(err); if (dest) *dest = msg; if (len) *len = msg ? strlen(msg) : 0; if (errCode) *errCode = OCI_ErrorGetOCICode(err); #endif return 0; }
static char * ocilibGetError( HB_ERRCODE * pErrCode ) { OCI_Error * err = OCI_GetLastError(); char * szRet; int iNativeErr; if( err ) { PHB_ITEM pRet = M_HB_ITEMPUTSTR( NULL, OCI_ErrorGetString( err ) ); szRet = hb_strdup( hb_itemGetCPtr( pRet ) ); hb_itemRelease( pRet ); iNativeErr = OCI_ErrorGetOCICode( err ); } else { szRet = hb_strdup( "Unable to get error message" ); iNativeErr = 9999; } if( pErrCode ) *pErrCode = ( HB_ERRCODE ) iNativeErr; return szRet; }
void err_handler(OCI_Error *err) { int err_type = OCI_ErrorGetType(err); char *err_msg = OCI_ErrorGetString(err); printf("%s - %s\n", err_type == OCI_ERR_WARNING ? "warning" : "error", err_msg); }
void raise_ocierror() { OCI_Error *err = OCI_GetLastError(); if (err) { perror(OCI_ErrorGetString(err)); exit(1); } }
int main(void) { OCI_Connection *cn; OCI_Statement *st; OCI_Error *err; int tab_int[1000]; char tab_str[1000][21]; int i; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT)) return EXIT_FAILURE; /* ... create connection and statement ... */ cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); /* binding */ OCI_Prepare(st, "insert into products values(:i, :s)"); OCI_BindArraySetSize(st, 1000); OCI_BindArrayOfInts(st, ":i", (int*) tab_int, 0); OCI_BindArrayOfStrings(st, ":s", (char*) tab_str, 20, 0); /* filling arrays */ for(i=0;i<1000;i++) { tab_int[i] = i+1; sprintf(tab_str[i],"Name %d",i+1); } /* execute */ if (!OCI_Execute(st)) { printf("Number of DML array errors : %d\n", OCI_GetBatchErrorCount(st)); err = OCI_GetBatchError(st); while (err) { printf("Error at row %d : %s\n", OCI_ErrorGetRow(err), OCI_ErrorGetString(err)); err = OCI_GetBatchError(st); } } printf("row processed : %d\n", OCI_GetAffectedRows(st)); OCI_Commit(cn); OCI_Cleanup(); return EXIT_SUCCESS; }
static void oci_err_handler(OCI_Error *err) { ociw_error_info_kludge.sql = OCI_GetSql(OCI_ErrorGetStatement(err)); ociw_error_info_kludge.errorString = OCI_ErrorGetString(err); ociw_error_info_kludge.ociCode = OCI_ErrorGetOCICode(err); }
void err_handler(OCI_Error *err) { printf( "code : ORA-%05i\n" "msg : %s\n" "sql : %s\n", OCI_ErrorGetOCICode(err), OCI_ErrorGetString(err), OCI_GetSql(OCI_ErrorGetStatement(err)) ); }
void error(OCI_Error *err) { printf("msg : %s\n", OCI_ErrorGetString(err)); exit(EXIT_FAILURE); }
void err_handler(OCI_Error *err) { printf("%s\n", OCI_ErrorGetString(err)); }