Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-24-2009, 08:39 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default Mutating trigger help
I have a trigger that will delete a row from (table)myProjects and change the (column)checkout status (Table)in projectDescriptions.

I understand the trigger is being invalidated because the Trigger is referencing the myProjects table and trying to delete from it. This has to happen for the trigger to work(read: I can't think of another way to accomplish the same thing)

The code for my trigger is
Code:
CREATE OR REPLACE TRIGGER updateCheckedout
AFTER DELETE OR UPDATE OR INSERT ON myprojects FOR EACH ROW
BEGIN
  IF INSERTING THEN
    UPDATE partdescriptions
    SET checkedout = 'Y'
    WHERE pid = :new.pid ;
  END IF;
  
  IF DELETING THEN
    UPDATE partdescriptions
    SET checkedout = 'N'
    WHERE pid = :old.pid;
  END IF;    
  
  IF UPDATING THEN
    IF :new.completed = 'Y' THEN
      DELETE FROM myprojects
      WHERE :new.pid = :old.pid;
    END IF;
  END IF;

END;
How I can go about fixing the UPDATING section of code to delete from table1 and update table2 whenever table1.column gets updated?

I'll gladly post my table data/descriptions if anyone thinks it will help.
__________________
Liberty has never come from the government.
Liberty has always come from the subjects of government.
The history of liberty is the history of resistance.
The history of liberty is a history of the limitation of governmental power, not the increase of it.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 04-24-2009, 09:46 PM
Senior Member
 
Join Date: Jun 2008
Posts: 1,397
Rep Power: 3
masijade is on a distinguished road
Default
You would definately be better off asking this question on either a generic SQL forum, or a forum for the DB involved, rather than a Java DB connectivity forum.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-24-2009, 11:32 PM
markw8500's Avatar
Senior Member
 
Join Date: Jul 2008
Location: Pennsylvania, USA
Posts: 136
Rep Power: 0
markw8500 is on a distinguished road
Default
Triggers can be tricky... If you can, post the descriptions of each table and go step by on what you want to do, when table1 gets updated, inserted into, or deleted from...
__________________
Who Cares... As Long As It Works...
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-24-2009, 11:45 PM
xcallmejudasx's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Houston, TX & Flint, MI
Posts: 585
Rep Power: 2
xcallmejudasx is on a distinguished road
Send a message via AIM to xcallmejudasx
Default
I ended up trying to make the UPDATING section call a procedure that would delete the completed work from my projects but again I ran into a mutating trigger error. I just don't think it's possible to combine all this into 1 option because I HAVE to be able to reference the table to check if it's completed.

The work around I decided on was
Code:
  IF UPDATING THEN
    IF :new.completed = 'Y' THEN
      UPDATE partdescriptions
      SET checkedout = 'N'
      WHERE pid = :old.pid;
    --  removeCompletedProjects(:new.pid);  
    END IF;   
  END IF;
and then just giving the user the option to call removeCompletedProjects whenever they felt like.(This is just dummy data to help me learn PL/SQL on a personal database)

And if you're still curious mark;
Code:
DESC myProjects
pid        completed
-------- ----------
100000              N
100001              Y
100002              N

DESC partDescriptions
pid            checkedOut
----------- ------------
100000                     Y
100001                     Y
100002                     Y
100003                     N
Essentially whenever update was ran on myprojects it would check if completed = 'Y' and if so it would change checkedout = 'N'. This works as intended and if I delete a row from myprojects it checks it back into the partdescriptions so thats fine too.

Originally I didn't see the point in having myprojects hold onto completed projects so I was going to have it remove them whenever they were finished so I wanted to combine the steps by having the trigger call my deleteCompleted procedure (which is just this)
Code:
create or replace PROCEDURE removeCompletedProjects
IS
BEGIN
  DELETE FROM myprojects
  WHERE completed = 'Y';
END;
But like I said It kept giving me mutating table errors so I said f-that. It's not a big deal if completed projects are left in my table as long as they show up as not checked out. I did however leave the procedure available to just execute on its own if I felt like removing them.
__________________
Liberty has never come from the government.
Liberty has always come from the subjects of government.
The history of liberty is the history of resistance.
The history of liberty is a history of the limitation of governmental power, not the increase of it.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-24-2009, 11:49 PM
markw8500's Avatar
Senior Member
 
Join Date: Jul 2008
Location: Pennsylvania, USA
Posts: 136
Rep Power: 0
markw8500 is on a distinguished road
Default
Hey... As long as it works...
__________________
Who Cares... As Long As It Works...
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
programmaticly trigger an event maxim AWT / Swing 3 02-23-2009 04:27 PM
JSlider (to NOT cont'd trigger statechanged ) hanifa AWT / Swing 4 09-19-2008 08:58 AM
sending the message from trigger to mailid geeta_ravikanti Database 0 04-04-2008 12:09 PM
Timer which should never end and should trigger daily garinapavan New To Java 0 08-10-2007 06:23 AM


All times are GMT +2. The time now is 12:17 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org