Status Vector Parsing Example

From InterBase

Go Up to Parsing the Status Vector


The following C example illustrates a simple, brute force parsing of the status vector. The code forces an error condition. The error-handling block parses the status vector array cluster by cluster, printing the contents of each cluster and interpreting it for you.

#include <ibase.h>
. . .
ISC_STATUS status_vector[20];
main() {
int done, v; /* end of args?, index into vector */
int c, extra; /* cluster count, 3 long cluster flag */
static char *meaning[] = {"End of error information",
"n InterBase error code"," string address"," string length",
" numeric value"," system code"};
/* Assume database is connected and transaction started here. */
if (status_vector[0] == 1 && status_vector[1] > 0)
error_exit();
. . .
void error_exit(void)
{
done = v = 0;
c = 1;
while (!done) {
extra = 0;
printf("Cluster %d:\n", c);
printf("Status vector %d: %ld: ", v, status_vector[v]);
if (status_vector[v] != gds_arg_end)
printf("Next long is a");
switch (status_vector[v++]) {
case gds_arg_end:
printf("%s\n", meaning[0]);
done = 1;
break;
case gds_arg_gds:
printf("%s\n", meaning[1]);
break;
case gds_arg_string:
case gds_arg_interpreted:
printf("%s\n", meaning[2]);
break;
case gds_arg_number:
printf("%s\n", meaning[4]);
break;
case gds_arg_cstring:
printf("%s\n", meaning[3]);
extra = 1;
break;
default:
printf("%s\n", meaning[5]);
break;
}
if (!done) {
printf("Status vector %d: %ld", v, status_vector[v]);
v++; /* advance vector pointer */
c++; /* advance cluster count */
if (extra) {
printf(": Next long is a %s\n", meaning[2]);
printf("Status vector: %d: %ld\n\n", v,
status_vector[v]);
v++;
}
else
printf("\n\n");
}
}
isc_rollback_transaction(status_vector, &trans);
isc_detach_database(&db1);
return(1);
}

Here is a sample of the output from this program:

Cluster 1:
Status vector 0: 1: Next long is an InterBase error code
Status vector 1: 335544342
Cluster 2:
Status vector 2: 4: Next long is a numeric value
Status vector 3: 1
Cluster 3:
Status vector 4: 1: Next long is an InterBase error code
Status vector 5: 335544382
Cluster 4:
Status vector 6: 2: Next long is a string address
Status vector 7: 156740
Cluster 5:
Status vector 8: 0: End of error information

This output indicates that two InterBase errors occurred. The first error code is 335544342. The error printing routines, isc_print_status() and isc_interprete(), use the InterBase error code to retrieve a corresponding base error message. The base error message contains placeholders for replaceable parameters. For error code 335544342, the base error message string is:

"action cancelled by trigger (%ld) to preserve data integrity"

This error message uses a replaceable numeric parameter, %ld.

In this case, the numeric value to use for replacement, 1, is stored in the second long of the second cluster. When the error printing routine inserts the parameter into the message, it displays the message:

action cancelled by trigger (1) to preserve data integrity

The second error code is 335544382. The base message retrieved for this error code is:

"%s"

In this case, the entire message to be displayed consists of a replaceable string. The second long of the fourth cluster contains the address of the replacement string, 156740. This is an error message defined in the trigger that caused the error. When the error printing routine inserts the message from the trigger into the base message, it displays the resulting message:

-Department name is missing.
Note:
This sample program is only meant to illustrate the structure of the status vector and its contents. While the error-handling routine in this program might serve as a limited debugging tool for a program under development, it does not provide useful information for end users. Ordinarily, error-handling blocks in applications should interpret errors, display explanatory error messages, and take corrective action, if appropriate.

For example, if the error-handling routine in the sample program had called isc_print_status() to display the error messages associated with these codes, the following messages would have been displayed:

action cancelled by trigger (1) to preserve data integrity
-Department name is missing.

Advance To: