The following programs demonstrate the use of the commit statement to make permanent changes to a field value in a database. These programs: o Use a record selection expression to find an employee in the EMPLOYEES relation with the ID number "00193" o Use a MODIFY statement to change the field value of E.LAST_NAME for this employee Although this change is written to the database at the time of the MODIFY, the change is not permanent until the programs issue a COMMIT statement. After the programs issue the COMMIT statement the old value for E.LAST_NAME is not available. The C example uses the function pad_string to pad the name "Smith-Fields" with blanks. Blanks are appended to the name so that the length of the name matches the spaces reserved for it in the database definition for LAST_NAME.
1 – C Example
#include <stdio.h> DATABASE PERS = FILENAME "PERSONNEL"; extern void pad_string(); main() { READY PERS; START_TRANSACTION READ_WRITE; FOR E IN EMPLOYEES WITH E.EMPLOYEE_ID = '00193' MODIFY E USING pad_string ("Smith-Fields", E.LAST_NAME, sizeof(E.LAST_NAME)); END_MODIFY; END_FOR; COMMIT; FINISH; }
2 – Pascal Example
program commit_changes (input,output); DATABASE PERS = FILENAME 'PERSONNEL'; begin READY PERS; START_TRANSACTION READ_WRITE; FOR E IN EMPLOYEES WITH E.EMPLOYEE_ID = '00193' MODIFY E USING E.LAST_NAME := 'Smith-Fields'; END_MODIFY; END_FOR; COMMIT; FINISH; end.