Home » Developer & Programmer » Forms » prevent delete when details exist (merged)
prevent delete when details exist (merged) [message #174587] Mon, 29 May 2006 23:10 Go to next message
mfa786
Messages: 210
Registered: February 2006
Location: karachi
Senior Member
hi master
sir
how i get my block_name because i check black name
it manse where the curser system give that block name
such as
i have two block dept and emp
on delete event i put this code

if block_name='emp' then
delete emp where deptno=:dept.deptno;
elsif block_name='dept' then
select count(*) into variablecount from emp where deptno=:dept.deptno;
if variablecount=0 then
delete dept where deptno=:dept.deptno;
else
meassage (system found matching record then no delete master record)
endif;
endif;
end;

please give me idea how i get block name

thanking you

aamir



[Updated on: Tue, 30 May 2006 01:49] by Moderator

Report message to a moderator

Re: how get block name ( if block_name='emp' then ) [message #174602 is a reply to message #174587] Tue, 30 May 2006 01:12 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
:SYSTEM.CURSOR_BLOCK is what you are after. But why don't you put the code in the on-delete trigger of the appropriate block? And counting records to verify if just ONE exist? If I see that on a production form I refuse to put it in production. Have you tried this: if a foreign key relationship exists you can just delete from DEPT and if the delete fails with an ORA-02292 (integrity constraint ... violated - child record found) display your message. No need for a count...

MHE
urgent where i put this code for delete [message #174607 is a reply to message #174587] Tue, 30 May 2006 01:20 Go to previous messageGo to next message
mfa786
Messages: 210
Registered: February 2006
Location: karachi
Senior Member

hi master

sir this code is right for my requirment but when i put on_delete event system not respons or not delete record

where i put this code for conditional deletion

this is my code

declare
recno number;
begin
if :system.cursor_block='accbal' then
delete accbal where accid=:chartofacc.accid;
go_block('chartofacc');
next_record;
elsif :system.cursor_block='chartofacc' then

select count(*) into recno from accbal where accid=:chartofacc.accid;
if recno=0 then
delete_record;
go_block('chartofacc');
previous_record;
else
message ('system found matching record then no delete master record');
message ('system found matching record then no delete master record');
end if;



end if;
end;



please gide me which event i use

thanking you

aamir
Re: urgent where i put this code for delete [message #174612 is a reply to message #174607] Tue, 30 May 2006 01:38 Go to previous messageGo to next message
Littlefoot
Messages: 21818
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Did you try to put this code into the KEY-DELREC trigger?

[EDIT]
Besides, why are opening new topics about the same question?

[Updated on: Tue, 30 May 2006 01:40]

Report message to a moderator

Re: urgent where i put this code for delete [message #174615 is a reply to message #174612] Tue, 30 May 2006 01:47 Go to previous message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
A nice feature of a RELATIONAL database like Oracle is that you actually can define relations in it. A side effect of this can be that you prevent the deletion of masters if detail records exist. In Forms you can also define relations have you tried that? And again you count all the details to find out if one exist. Bad practice, but it is your program not mine.

To answer your question (after all it is urgent Wink): a ON-DELETE replaces the default Forms delete. You have to create your own. Like Littlefoot suggested, move it to another trigger like PRE-DELETE. But it would be better if you used the standard forms relations.

MHE

EDIT: Topics merged.

[Updated on: Tue, 30 May 2006 01:50]

Report message to a moderator

Previous Topic: I'm new and need help !!!!
Next Topic: problem in set_item_property
Goto Forum:
  


Current Time: Fri Sep 20 10:27:32 CDT 2024