Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 4th, 2011, 05:44 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Does Firebird allow SELECT in Trigger?

Does anyone know if Firebird allows a SELECT query on a table during
the execution of an insert trigger on that same table?

I am looking for the least intrusive way to retrofit a rule to prevent insertions succeeding
based on certain existing conditions.

Oracle would give a mutating table error.

I want to avoid changing the code in all the client applications.

Reply With Quote
  #2  
Old July 5th, 2011, 12:42 AM
costin_mentor costin_mentor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 31 costin_mentor User rank is Lance Corporal (50 - 100 Reputation Level)costin_mentor User rank is Lance Corporal (50 - 100 Reputation Level)costin_mentor User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 13 h 12 m 34 sec
Reputation Power: 7
YES, Firebird allows a SELECT query on a table during
the execution of an insert trigger on that same table.
I have a trigger like that in one of my tables.

Reply With Quote
  #3  
Old July 5th, 2011, 12:44 AM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Thanks.
I will give it a try.

Reply With Quote
  #4  
Old July 8th, 2011, 08:13 AM
nagysz nagysz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 200 nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 19 m 28 sec
Reputation Power: 13
Of course it does!

I use it for example automatically updating sums in bill header tables, automatically updating ticket status after events, automatically register into accounting after a bill/payment is made, etc.

Reply With Quote
  #5  
Old July 8th, 2011, 01:17 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Quote:
Originally Posted by nagysz
Of course it does!

I use it for example automatically updating sums in bill header tables, automatically updating ticket status after events, automatically register into accounting after a bill/payment is made, etc.

Surely not in the same table as the trigger!

Running a SELECT query is one thing, doing a modification is possibly going to lead you down some nasty recursive paths.

I would definitely advise against modifying a table from within one of its triggers.

Obviously I am talking about modifying via SQL NOT modifying the fields of the record being modified.

Clive

Reply With Quote
  #6  
Old July 8th, 2011, 11:26 PM
nagysz nagysz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 200 nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 19 m 28 sec
Reputation Power: 13
Quote:
Originally Posted by clivew
Surely not in the same table as the trigger!

Running a SELECT query is one thing, doing a modification is possibly going to lead you down some nasty recursive paths.

I would definitely advise against modifying a table from within one of its triggers.

Obviously I am talking about modifying via SQL NOT modifying the fields of the record being modified.

Clive




Sorry, i missed the "same table" part. I totally agree with the rest.

And yes, i have that scenario too. For example i store the menu of the client software in tree structure in a table, that has a PARENT field referencing the ID in the same table. And before any INSERT/UPDATE i have to check if i have a circular reference.



I paste here a quote from Helen Borrie's "The Firebird eBook":
Quote:
Self-Referencing Tables and Trees
Self-referencing tables that implement tree structures4 are a special case. Each row
in such a table is a node in a tree and inter-row dependencies are inherent. Any node
potentially has two “lives”: one as a parent to nodes beneath it, the other as a child to
a higher node. Triggers are likely to be required for all DML events, both to modify the
behavior of referential integrity constraints and to maintain the metatables (graphs)
used by some tree algorithms to make the state of the tree’s geometry available to
queries. Triggers for trees should always be designed with conditions and branches
that protect the structure from infinite loops.
Updating the Same Row
Never try to use an SQL statement to update or delete the same row that the trigger is
operating on. The following, for example, is not advisable:
CREATE TRIGGER O_SO_SILLY FOR ATABLE
BEFORE UPDATE
AS
BEGIN
UPDATE ATABLE SET ACOLUMN = NEW.ACOLUMN
WHERE ID = NEW.ID;
END ^
Always use the NEW variables for same-row modifications and never resolve an
exception by attempting to delete the row from within the trigger.

Chapter 31, Page 660

Last edited by nagysz : July 8th, 2011 at 11:38 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Does Firebird allow SELECT in Trigger?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap