After completing this lesson, you should be able to do the following:
Explain the process used by Forms to apply changes to the database
Describe the commit sequence of events
Supplement transaction processing
Allocate sequence numbers to records as they are applied to tables
Implement array DML
Transaction Processing Overview Transaction (Begin) FORM A A ction E dit Block#1 Block#2 New Record Updated Record Deleted Record Updated Record Commit work; INSERT INTO Table1 UPDATE Table1 DELETE FROM Table2 UPDATE Table2 Transaction (End) S ave
Transaction Processing Overview
Transaction processing includes two phases:
Writes record changes to base tables
Fires transactional triggers
Commit: Performs database commit
Errors result in:
Rollback of the database changes
The Commit Sequence of Events Validate the block Pre-Commit Pre-Delete Delete row Post-Delete More records? 1 On-Delete Validate the form 2
The Commit Sequence of Events Check uniqueness On-Insert Insert row Post-Insert Post-Update More blocks? Post-Forms-Commit INSERT UPDATE Stop 2 More records? Pre-Insert Copy value from item Pre-Update Check uniqueness On-Update Update row 1 Post-Database-Commit Commit changes
Characteristics of Commit Triggers
Pre-Commit: Fires once if form changes are made or uncommitted changes are posted
Pre- and Post-DML
On-DML: Fires per record, replacing default DML on row Use DELETE_RECORD , INSERT_RECORD , UPDATE_RECORD built-ins
Characteristics of Commit Triggers
Post-Forms-Commit: Fires once even if no changes are made
Post-Database-Commit: Fires once even if no changes are made
Note: A commit-trigger failure causes a rollback to the savepoint.
Common Uses for Commit Triggers Pre-Commit Pre-Delete Pre-Insert Pre-Update Check user authorization; set up special locking Journaling; implement foreign-key delete rule Generate sequence numbers; journaling; automatically generated columns; check constraints Journaling; implement foreign-key update rule; auto-generated columns; check constraints
Common Uses for Commit Triggers On-Insert/Update/Delete Post-Forms-Commit Post-Database-Commit Replace default block DML statements Check complex multirow constraints Test commit success; test uncommitted posts
Life of an Update Column Item Query Rollback Data 20 20 Locked Query 30 20 Update record in form [Save] 30 20 [Save] Pre-Update 30 20 Row Updated 30 30 20 Row updated Post-Update 30 30 20 30 30 Post-Update Pre-Update Commit
Final checks before row deletion
DECLARE CURSOR C1 IS SELECT ’anything’ FROM ORDERS WHERE customer_id = :CUSTOMERS.customer_id; BEGIN OPEN C1; FETCH C1 INTO :GLOBAL.dummy; IF C1%FOUND THEN CLOSE C1; MESSAGE(’There are orders for this customer!’); RAISE form_trigger_failure; ELSE CLOSE C1; END IF; END;
Assigning Sequence Numbers Pre-Insert Insert Database 601 Value Value ID Sequence SELECT ORDERS_SEQ.nextval INTO :ORDERS.order_id FROM SYS.dual; 601 602
UPDATE ORDERS SET order_date = SYSDATE WHERE order_id = :ORDERS.order_id; IF SQL%NOTFOUND THEN MESSAGE(’Record not found in database’); RAISE form_trigger_failure; END IF;
Testing the Results of Trigger DML
UPDATE S_ORD SET date_shipped = SYSDATE WHERE id = :S_ORD.id; IF SQL%NOTFOUND THEN MESSAGE(’Record not found in database’); RAISE form_trigger_failure; END IF;
DML Statements Issued During Commit Processing INSERT INTO base_table ( base_column, base_column ,...) VALUES ( :base_item, :base_item , ...) UPDATE base_table SET base_column = :base_item, base_column = :base_item, ... WHERE ROWID = :ROWID DELETE FROM base_table WHERE ROWID = :ROWID
DML Statements Issued During Commit Processing
DML statements may fire database triggers.
Forms uses and retrieves ROWID .
The Update Changed Columns Only and Enforce Column Security properties affect UPDATE statements.
Locking statements are not issued.
Overriding Default Transaction Processing
Additional transactional triggers:
On-Check-Unique On-Column-Security On-Commit On-Rollback On-Savepoint On-Sequence-Number CHECK_RECORD_UNIQUENESS ENFORCE_COLUMN_SECURITY COMMIT_FORM ISSUE_ROLLBACK ISSUE_SAVEPOINT GENERATE_SEQUENCE_NUMBER Trigger Do-the-Right-Thing Built-in Note: These triggers are meant to be used when connecting to data sources other than Oracle.