/************************************************************* * * WARNING: USE OF THIS PROGRAM MAY HAVE UNDESIRABLE AFFECTS * TO THE DATABASE SERVER, INCLUDING DATA CORRUPTION!! * * TITLE: xa_tool.ec * * Compile with: * on UNIX systems: * esql -o xa_tool xa_tool.ec -lifxa * on Windows systems * esql xa_tool.ec * * This program will connect to a global transaction branch * and let the user manipulate the transaction. * * Usage: * xa_tool * * The fID, gtl, bql, and hex data should be provided from the * transaction desired to be manipulated. The information is * found by execution of the onstat -G command. Example output * of the onstat -G command: * * Global Transaction Identifiers * address flags fID gtl bql data * cb2a964 0x8442a 0 2 4 4D4E4F000000 * 1 active, 128 total * * If transaction cb2a964 is the transaction that is desired * to be manipulated, then this program should be executed * with the following command: * * xa_tool 0 2 4 4D4E4F000000 * * ************************************************************* */ #include #include #include #include #include "xa.h" extern struct xa_switch_t infx_xa_switch; #define xa_open(info, rmid, flags) \ ((*infx_xa_switch.xa_open_entry)(info,rmid,flags)) #define xa_start(gtrid,rmid, flags) \ ((*infx_xa_switch.xa_start_entry)(gtrid,rmid,flags)) #define xa_rollback(gtrid,rmid, flags) \ ((*infx_xa_switch.xa_rollback_entry)(gtrid,rmid,flags)) #define xa_commit(gtrid,rmid, flags) \ ((*infx_xa_switch.xa_commit_entry)(gtrid,rmid,flags)) #define xa_rollback(gtrid,rmid, flags) \ ((*infx_xa_switch.xa_rollback_entry)(gtrid,rmid,flags)) #define xa_end(gtrid,rmid, flags) \ ((*infx_xa_switch.xa_end_entry)(gtrid,rmid,flags)) #define xa_prepare(gtrid,rmid, flags)\ ((*infx_xa_switch.xa_prepare_entry)(gtrid,rmid,flags)) #define xa_close(info,rmid, flags)\ ((*infx_xa_switch.xa_close_entry)(info,rmid,flags)) #define xa_forget(gtrid,rmid, flags)\ ((*infx_xa_switch.xa_forget_entry)(gtrid,rmid,flags)) #define xa_recover(gtrid, count, rmid, flags)\ ((*infx_xa_switch.xa_recover_entry)(gtrid,count,rmid,flags)) /* Doesn't matter what database is opened... */ #define OPEN_DATABASE "sysmaster" /* Initialize the xid */ void setup_myxid (XID *xid, int x_fID, int x_gtl, int x_bql, char* x_data) { int ii, c; xid->formatID = x_fID; xid->gtrid_length = x_gtl; xid->bqual_length = x_bql; for(ii=0; iidata[ii] = (char) c; } } void xa_tool(XID *xid) { int choice = 0; int cc; while( choice != 'Q') { printf("\tP -- XA_PREPARE\n"); printf("\tC -- XA_COMMIT\n"); printf("\tR -- XA_ROLLBACK\n"); printf("\tF -- XA_FORGET\n"); printf("\tQ -- terminate program\n"); printf("Enter Choice: "); choice = getchar(); choice = toupper(choice); printf("%c\n\n", choice); switch(choice) { case 'P': printf("Executing XA_PREAPRE\n"); if ((cc = xa_prepare(xid, 0, TMNOFLAGS)) != XA_OK) { printf("XA_PREPARE failed with %d\n", cc); } else printf("... XA_PREPARE finished\n\n"); break; case 'C': printf("Executing XA_COMMIT\n"); if ((cc = xa_commit(xid, 0, TMNOFLAGS)) != XA_OK) { printf("XA_COMMIT failed with %d\n", cc); } else printf("... XA_COMMIT finished\n\n"); break; case 'R': printf("Executing XA_ROLLBACK\n"); if ((cc = xa_rollback(xid, 0, TMNOFLAGS)) != XA_OK) { printf("XA_ROLLBACK failed with %d\n", cc); } else printf("... XA_ROLLBACK finished\n\n"); break; case 'F': printf("Executing XA_FORGET\n"); if ((cc = xa_forget(xid, 0, TMNOFLAGS)) != XA_OK) { printf("XA_FORGET failed with %d\n", cc); } else printf("... XA_FORGET finished\n\n"); break; case 'Q': break; default: printf("%c is not a valid option!\n\n", choice); choice = 0; } if (choice != 'Q') { choice = getchar(); choice = 0; } } } int main(int arc, char *argv[]) { $int cc; XID xid; int xid_fID, xid_gtl, xid_bql; char xid_data[300]; if (arc != 5) { printf("Error: Incorrect number of parameters.\n"); printf("Usage: %s \n", argv[0]); exit(2); } printf("\n\n"); xid_fID = atoi(argv[1]); xid_gtl = atoi(argv[2]); xid_bql = atoi(argv[3]); strcpy(xid_data, argv[4]); /* setup the XID which is used to identify the transaction */ setup_myxid(&xid, xid_fID, xid_gtl, xid_bql, xid_data); /* establish connection to the database */ printf("Calling xa_open ... \n"); if ((cc = xa_open(OPEN_DATABASE, 0, TMNOFLAGS)) != XA_OK) { printf("xa_open failed with %d, sqlcode = %d\n", cc, SQLCODE); exit(1); } else printf("... xa_open finished\n\n"); /** This is for xa_tool... **/ xa_tool(&xid); /* close the connection */ printf("Calling xa_close...\n"); if ((cc = xa_close("", 0, TMNOFLAGS)) != XA_OK) { printf("xa_close failed with %d\n", cc); exit(1); } else printf("... xa_close finished\n\n"); }