Query Triggers
Objectives • How Query Processing occurs in Forms? • Writing Pre-Query Trigger • Writing Post-Query Trigger • Scope of the triggers and Built-ins
Query Processing Perform queryPerform query Fetch a row into a new recordFetch a row into a new record Mark record as validMark record as valid Fire Post-Query triggerFire Post-Query trigger Validate any record changesValidate any record changes Abort query on failure Flush record on failure Construct SELECT...Construct SELECT... Fire Pre-Query triggerFire Pre-Query trigger
Where & Order By Clauses • Three sources for Where Clause – Query/Where Dialog Box – Example Record – Where Clause Block Property Where Clauses are combined by the AND Operator. • Two sources for Order By Clause – Order by Clause Block Property – Query/Where Dialog Box Second source for Order by clause Overrides the first one.
SELECT statement Issued SELECT base_column, ..., ROWID INTO :base_item, ..., :ROWID FROM base_table WHERE default_where_clause AND (example_record_conditions) AND (query_where_conditions) ORDER BY default_order_by_clause | query_where_order_by
Pre-Query Trigger • Defined at the Block-level • Fires once before the query is issued. IF :emp.enmpno||:emp.ename|| :emp.hiredate IS NULL THEN MESSAGE(‘You must query on emp id or name or joindate’); RAISE form_trigger_failure; --Built-in Exception END IF;
Post-Query Trigger • Written at Block level • Use to populate nondatabase items and calculate statistics • Fires once for each fetched record. • SELECT dname INTO :control.dept_name FROM dept WHERE deptno=:emp.deptno;
Query Array Processing • Reduces network traffic • Enables Query Array processing: – Enable Array Processing option – Set Query Array Size property • Query Array Size property • Query All Records property
Enter-Query Mode • Some triggers may fire in Enter-Query mode. • Set to fire in Enter-Query Mode property. • Test mode during execution with :SYSTEM.MODE – NORMAL – ENTER-QUERY – QUERY IF :SYSTEM.MODE = ’NORMAL’ THEN ENTER_QUERY; ELSE EXECUTE_QUERY; END IF;
Query Info at Runtime • SYSTEM.MODE • SYSTEM.LAST_QUERY –Contains bind variables (EMPNO = :1) before SELECT_RECORDS –Contains actual values (EMPNO = 7566) after SELECT_RECORDS
Query Info at Runtime • GET_BLOCK_PROPERTY SET_BLOCK_PROPERTY – Get and set: DEFAULT_WHERE ORDER_BY QUERY_ALLOWED QUERY_HITS – Get only: QUERY_OPTIONS RECORDS_TO_FETCH
Query Info at Runtime • GET_ITEM_PROPERTY SET_ITEM_PROPERTY – Get and set: CASE_INSENSITIVE_QUERY QUERYABLE QUERY_ONLY – Get only: QUERY_LENGTH
Summary • Where clauses are combined with AND Operator • Second Order by Overrides the first one. • A Pre-Query trigger fires before a query executes. Use it to check or modify query conditions. • A Post-Query trigger fires as each record is fetched. Use it to perform calculations and populate additional items.

Oracle Forms : Query Triggers

  • 1.
  • 2.
    Objectives • How QueryProcessing occurs in Forms? • Writing Pre-Query Trigger • Writing Post-Query Trigger • Scope of the triggers and Built-ins
  • 3.
    Query Processing Perform queryPerformquery Fetch a row into a new recordFetch a row into a new record Mark record as validMark record as valid Fire Post-Query triggerFire Post-Query trigger Validate any record changesValidate any record changes Abort query on failure Flush record on failure Construct SELECT...Construct SELECT... Fire Pre-Query triggerFire Pre-Query trigger
  • 4.
    Where & OrderBy Clauses • Three sources for Where Clause – Query/Where Dialog Box – Example Record – Where Clause Block Property Where Clauses are combined by the AND Operator. • Two sources for Order By Clause – Order by Clause Block Property – Query/Where Dialog Box Second source for Order by clause Overrides the first one.
  • 5.
    SELECT statement Issued SELECTbase_column, ..., ROWID INTO :base_item, ..., :ROWID FROM base_table WHERE default_where_clause AND (example_record_conditions) AND (query_where_conditions) ORDER BY default_order_by_clause | query_where_order_by
  • 6.
    Pre-Query Trigger • Definedat the Block-level • Fires once before the query is issued. IF :emp.enmpno||:emp.ename|| :emp.hiredate IS NULL THEN MESSAGE(‘You must query on emp id or name or joindate’); RAISE form_trigger_failure; --Built-in Exception END IF;
  • 7.
    Post-Query Trigger • Writtenat Block level • Use to populate nondatabase items and calculate statistics • Fires once for each fetched record. • SELECT dname INTO :control.dept_name FROM dept WHERE deptno=:emp.deptno;
  • 8.
    Query Array Processing •Reduces network traffic • Enables Query Array processing: – Enable Array Processing option – Set Query Array Size property • Query Array Size property • Query All Records property
  • 9.
    Enter-Query Mode • Sometriggers may fire in Enter-Query mode. • Set to fire in Enter-Query Mode property. • Test mode during execution with :SYSTEM.MODE – NORMAL – ENTER-QUERY – QUERY IF :SYSTEM.MODE = ’NORMAL’ THEN ENTER_QUERY; ELSE EXECUTE_QUERY; END IF;
  • 10.
    Query Info atRuntime • SYSTEM.MODE • SYSTEM.LAST_QUERY –Contains bind variables (EMPNO = :1) before SELECT_RECORDS –Contains actual values (EMPNO = 7566) after SELECT_RECORDS
  • 11.
    Query Info atRuntime • GET_BLOCK_PROPERTY SET_BLOCK_PROPERTY – Get and set: DEFAULT_WHERE ORDER_BY QUERY_ALLOWED QUERY_HITS – Get only: QUERY_OPTIONS RECORDS_TO_FETCH
  • 12.
    Query Info atRuntime • GET_ITEM_PROPERTY SET_ITEM_PROPERTY – Get and set: CASE_INSENSITIVE_QUERY QUERYABLE QUERY_ONLY – Get only: QUERY_LENGTH
  • 13.
    Summary • Where clausesare combined with AND Operator • Second Order by Overrides the first one. • A Pre-Query trigger fires before a query executes. Use it to check or modify query conditions. • A Post-Query trigger fires as each record is fetched. Use it to perform calculations and populate additional items.

Editor's Notes

  • #5 Note: You can change the WHERE clause and ORDER BY clause block properties at Run time by using the SET_BLOCK_PROPERTY