The examples show: o How to use COMMIT when modifying data in the database o How to use COMMIT when creating data definitions
1 – Modifying
This example makes a change to a relation and writes that change to the database: DISPLAY "Enter employee's ID number: " <-- 1 WITH NO ADVANCING. ACCEPT ID. DISPLAY "Percentage increase: " <-------- 2 WITH NO ADVANCING. ACCEPT PERC. CALL "SYS$GETTIM" USING TODAY GIVING RETURN_VALUE. &RDB& START_TRANSACTION READ_WRITE <---------- 3 &RDB& RESERVING SALARY_HISTORY FOR &RDB& PROTECTED WRITE &RDB& FOR S IN SALARY_HISTORY &RDB& WITH S.EMPLOYEE_ID = ID AND <---------- 4 &RDB& S.SALARY_END MISSING &RDB& MODIFY S USING <---------- 5 &RDB& ON ERROR GO TO ERROR-PAR &RDB& END_ERROR &RDB& S.SALARY_END = TODAY &RDB& END_MODIFY &RDB& STORE NEW IN SALARY_HISTORY USING <----- 6 &RDB& ON ERROR GO TO ERROR-PAR &RDB& END_ERROR &RDB& NEW.EMPLOYEE_ID = S.EMPLOYEE_ID; &RDB& NEW.SALARY_AMOUNT = &RDB& ( S.SALARY_AMOUNT * &RDB& ( 1 + ( PERC / 100 ) ) ); &RDB& NEW.SALARY_START = TODAY &RDB& END_STORE &RDB& END_FOR &RDB& COMMIT <------------------------ 7 This program fragment gives a raise to an employee. To maintain a consistent database, it performs the following operations: 1. Prompts for an employee identification number (ID). 2. Prompts for a percentage increase, which is used to calculate INCREASE. 3. Starts a read/write transaction. This statement uses the RESERVING clause to protect the SALARY_HISTORY record against conflicting updates, while allowing users access to all the other relations in the database. 4. Establishes a record stream consisting of the current SALARY_ HISTORY record for the specified employee. 5. Uses MODIFY to change the current salary record, by changing its date from missing to the current date (TODAY). 6. Uses STORE to create a new SALARY_HISTORY record. Although this statement executes within the record stream defined by the FOR loop, it must declare a new context variable to identify the new record. All the fields of the new record can be derived from fields of the old one, except the start date, which must be calculated from the current date. Oracle Rdb calculates NEW.SALARY_AMOUNT from the S.SALARY_AMOUNT, using the specified percentage increase (PERC). 7. Uses COMMIT to make the changes permanent to the database. Note that each data manipulation statement provides an ON ERROR clause. If an error occurs at any point in the transaction, control transfers to another paragraph, which contains a ROLLBACK statement. Therefore, this set of operations is never partially completed.
2 – Defining
This example shows how to use COMMIT to make a data definition permanent: RDO> DEFINE DATABASE 'INVENTORY'. RDO> SHOW DATABASES Database with db_handle INVENTORY in file INVENTORY RDO> DEFINE FIELD PART DATATYPE TEXT SIZE 10. RDO> DEFINE RELATION TEST. cont> PART. cont> END TEST RELATION. RDO> RDO> COMMIT RDO> SHOW RELATIONS User Relations in Database with db_handle INVENTORY TEST RDO> SHOW FIELDS User Fields in Database with db_handle INVENTORY PART text size is 10 RDO> EXIT This example shows how to define a database, a field, and a relation. These statements would normally be in an indirect command file. After you define the database and its components, the COMMIT statement makes the database permanent. If you do not issue the COMMIT statement, RDO returns this message: There are uncommitted changes to a database or the data dictionary Would you like a chance to COMMIT these changes [NO]?