/* Copyright © Oracle Corporation 1995. All Rights Reserved. */ #include #include /* This function is an error handler to handle run-time */ /* errors than occur during a call to RDB$INTERPRET from the */ /* program C_SAMPLE.RC. */ DATABASE PERS = [EXTERNAL] FILENAME "MF_PERSONNEL"; /* Declare variables, including symbolic error codes and */ /* rdb$signal. */ globalvalue RDB$_STREAM_EOF; globalvalue RDB$_DEADLOCK; globalvalue RDB$_BAD_SEGSTR_HANDLE; globalvalue RDB$_LOCK_CONFLICT; globalvalue RDB$_INTEG_FAIL; globalvalue RDB$_NO_DUP; globalvalue RDB$_NOT_VALID; globalvalue RDO$_INDNOTDEF; globalref int retry; extern rdb$signal(); FILE *fopen(), fp; int error; char string [132]; char msg_string[256]; callable_error (status) long *status; { $DESCRIPTOR (msgstr, msg_string); fp = fopen("error_log", "w"); /* Use LIB$MATCH_COND to determine which of a series of errors */ /* might have occurred. */ error = LIB$MATCH_COND (status, &RDB$_DEADLOCK, &RDB$_LOCK_CONFLICT, &RDB$_NO_DUP, &RDB$_NOT_VALID, &RDB$_INTEG_FAIL, &RDB$_STREAM_EOF); printf (" \n"); /* The switch statement directs program to the appropriate */ /* statements to execute depending on which error */ /* was trapped. */ switch (error) { case 0: strcpy(string, "Unexpected error - terminating program"); printf("%s\n", string); fputs (string, fp); rdb$signal(); break; case 1: case 2: if (retry <= 4) { strcpy(string, "Deadlock or Lock conflict error"); printf("%s\n", string); printf("Others are using the data that you want to access\n"); printf("Trying to restart transaction\n"); fputs (string, fp); } else { printf("Sorry, resources are not available, "); printf("please retry later\n"); rdb$signal(); } break; case 3: strcpy(string, "Duplicates are not allowed"); printf("%s\n", string); fputs (string, fp); break; case 4: strcpy(string, "Invalid Data"); printf("%s\n", string); fputs (string, fp); break; case 5: strcpy(string, "Integrity failure"); printf("%s\n", string); fputs (string, fp); break; case 6: strcpy(string, "There are no colleges with that code"); SYS$GETMSG(*status, 0, &msgstr); printf("%s\n", msg_string); printf("%s\n", string); fputs (string, fp); fputs (msg_string, fp); break; } fclose (fp); }