The following programs demonstrate the use of the ROLLBACK statement with a transaction handle to undo changes to the database made with the STORE statement. These programs: o Start a READ_WRITE transaction, SAL_INCREASE o Store a new JOBS record using the SAL_INCREASE transaction o Use the ROLLBACK statement to undo the changes made to the database during the SAL_INCREASE increase transaction, that is, the new record is not stored in the database Note that the C program uses the pad_string function to read in the values for the STORE statement. This function pads the values stored in each field with the correct number of trailing blanks to ensure that the length of the values stored match the text size of the field. For more information on pad_string, see Appendix B of the "RDML Reference Manual".
1 – C Example
#include <stdio.h> DATABASE PERS = FILENAME "PERSONNEL"; extern void pad_string(); main() { int SAL_INCREASE = 0; READY PERS; START_TRANSACTION (TRANSACTION_HANDLE SAL_INCREASE) READ_WRITE; STORE (TRANSACTION_HANDLE SAL_INCREASE) J IN JOBS USING pad_string ("TYPS", J.JOB_CODE, sizeof(J.JOB_CODE)); pad_string ("1", J.WAGE_CLASS, sizeof(J.WAGE_CLASS)); pad_string ("TYPIST", J.JOB_TITLE, sizeof(J.JOB_TITLE)); J.MINIMUM_SALARY = 10000; J.MAXIMUM_SALARY = 17000; END_STORE; ROLLBACK (TRANSACTION_HANDLE SAL_INCREASE); FINISH; }
2 – Pascal Example
program rollback_trans (input,output); DATABASE PERS = FILENAME 'PERSONNEL'; var sal_increase : [volatile] integer := 0; begin READY PERS; START_TRANSACTION (TRANSACTION_HANDLE SAL_INCREASE) READ_WRITE; STORE (TRANSACTION_HANDLE SAL_INCREASE) J IN JOBS USING J.JOB_CODE := 'TYPS'; J.WAGE_CLASS := '1'; J.JOB_TITLE := 'Typist'; J.MINIMUM_SALARY := 10000; J.MAXIMUM_SALARY := 17000; END_STORE; ROLLBACK (TRANSACTION_HANDLE SAL_INCREASE); FINISH; end.