Home » Developer & Programmer » Forms » Pre-query vs post-quey
Pre-query vs post-quey [message #478999] Thu, 14 October 2010 02:23 Go to next message
swapnil_naik
Messages: 269
Registered: December 2009
Location: Mumbai
Senior Member

Hi friends,

Can somebody expalin me in simple words what is purpose of pre-query and post-query...i already read oracle document , but i cant get exact meaning...please expalin me in simple words.....in which certain condition i used this trigger??
Re: Pre-query vs post-quey [message #479001 is a reply to message #478999] Thu, 14 October 2010 02:33 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Here's an example (Scott's schema): you have a form with two blocks. The first block is a non-database block and contains several items, such as JOB and DEPTNO. Once again - NON database items.
The second block (something like first block's detail block) contains all columns from the EMP table. This is a database block.

The idea is: you'll enter some values into JOB and DEPTNO items in the first block. You'll press <ENTER> on the DEPTNO item and you'll fetch all employees (who work in that department and are, for example, CLERKs) in the second block.

In order to do that, you'd create two triggers:
-- KEY-NEXT-ITEM on DEPTNO item:
go_block('second_block');
execute_query;

-- PRE-QUERY trigger on the second block:
:second_block.job := :first_block.job;
:second_block.deptno := :first_block.deptno;

PRE-QUERY trigger will set those values BEFORE query is executed, so that you'd fetch only records you are interested in.

Now, in the second block, there's a DEPTNO item. But you'd like to see department NAME (instead of number). OK, so create a display (non-database) item in the second block. Create a POST-QUERY trigger which will, obviously, fire after query is executed:
-- POST-QUERY trigger on the second block
select d.dname
  into :second_block.department_name
  from deptno d
  where d.deptno = :second_block.deptno;


That's it.
Re: Pre-query vs post-quey [message #479006 is a reply to message #479001] Thu, 14 October 2010 03:42 Go to previous messageGo to next message
swapnil_naik
Messages: 269
Registered: December 2009
Location: Mumbai
Senior Member

Thast great to understand....thank you very much...
Re: Pre-query vs post-quey [message #479007 is a reply to message #479006] Thu, 14 October 2010 03:44 Go to previous messageGo to next message
swapnil_naik
Messages: 269
Registered: December 2009
Location: Mumbai
Senior Member

So my qnother question is when post-query, its automatically validate that item....no written logic for when-validate-item
Re: Pre-query vs post-quey [message #479008 is a reply to message #479007] Thu, 14 October 2010 04:02 Go to previous message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
OK, another example: if we have a form that is to be used when entering new employees, you'd have DEPTNO item (database item) and DEPARTMENT_NAME (non-database item). You'd put "10" into the DEPTNO item and expect "ACCOUNTING" to be displayed in the DEPARTMENT_NAME item. In order to do that, you'd write WHEN-VALIDATE-ITEM trigger on DEPTNO item:
begin
  select d.dname
    into :block.department_name
    from dept d
    where d.deptno = :block.deptno;
exception
  when no_data_found then
    message('Invalid department number');
    raise form_trigger_failure;
end;

For querying purposes, you'd have to create a POST-QUERY trigger. It would look like the one in my first example.

It means that - for that type of a form - you'd need both WHEN-VALIDATE-ITEM and POST-QUERY triggers.
Previous Topic: Items on tab page getting invisible
Next Topic: Create Trigger On Backend
Goto Forum:
  


Current Time: Thu Sep 19 18:48:34 CDT 2024