Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > IBM DB2 > Re: can a trigg...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 8 Topic 8822 of 9366
Post > Topic >>

Re: can a trigger do an execute immediate?

by Oliver <JOHolloway@[EMAIL PROTECTED] > Apr 24, 2008 at 06:00 AM

On Apr 24, 7:01 am, Lennart <Erik.Lennart.Jons...@[EMAIL PROTECTED]
> wrote:
> On Apr 24, 5:41 am, "Dave Hughes" <d...@[EMAIL PROTECTED]
> wrote:
>
>
>
> > Lennart wrote:
> > > On Apr 23, 10:21 pm, Oliver <JOHollo...@[EMAIL PROTECTED]
> wrote:
> > > > On Apr 23, 4:06 pm, Lennart <Erik.Lennart.Jons...@[EMAIL PROTECTED]
>
wrote:
> > [snip]
> > > > > If the problem is that you don't want to write the triggers by
> > > > > hand, I would suggest that you write a util in your favorite
> > > > > scripting language that creates the triggers for you
>
> > > > > /Lennart
>
> > > > Exactly, we don't want to maintain the triggers by hand, that's
> > > > exactly the point.  That way, when changes occur to the table
> > > > structure, the associated trigger will still work without further
> > > > maintenance.
>
> > > I see, IMO it is better to generate static triggers during
development
> > > via some automatic script. A silly example:
>
> > [snip]
> > > I assume you have a list of tables that you want to audit. Unless
> > > there are milions of them it will only take a second or two to
> > > regenerate the trigger code.
>
> > This would certainly be my preference. Especially as "when changes
> > occur to the table structure" the associated triggers may get
> > invalidated and will need to be recreated anyway (depending on what
> > change occurred and how it was implemented).
>
> Exactly my thoughts too. As a matter of fact I do all my upgrades via
> a utility that among other things verifies this before a version is
> committed to the database. In case someone is interested I have an
> ASSERT procedure defined as:
>
> CREATE PROCEDURE TOOLBOX.ASSERT(stmt varchar(1000))
> LANGUAGE SQL
> BEGIN
>
>          DECLARE tmpstmt varchar(1100);
>          DECLARE not_found CONDITION FOR SQLSTATE '02000';
>          DECLARE CONTINUE HANDLER FOR not_found
>                  SIGNAL SQLSTATE '77000'
>                  SET MESSAGE_TEXT = 'ASSERTION FAILED!';
>
>          A: BEGIN
>                 -- Do nothing if drop session.tmp fails
>                 DECLARE CONTINUE HANDLER FOR SQLSTATE '42704'
>                 BEGIN
>                 END;
>
>                 DROP TABLE SESSION.TMP;
>          END;
>
>          DECLARE GLOBAL TEM****ARY TABLE SESSION.TMP (y int);
>
>          SET tmpstmt = 'insert into session.tmp ' || stmt;
>          execute immediate tmpstmt;
> END @[EMAIL PROTECTED]
>
> COMMENT ON PROCEDURE TOOLBOX.ASSERT IS 'Raises exception if stmt
> return 0 rows.
> Stmt must be of form select <int> from ... Note that sql string delim
> must be quoted' @[EMAIL PROTECTED]
>
> Before the version is commited to the database, the following call is
> always made:
>
> call toolbox.assert
>                 ('select 1 from lateral(values 1) x where not exists (
>                         select 1 from syscat.tables
>                         where tabschema in (
>                                 <relevant tableschemas>
>                         ) and status <> ''N''
>                         union all
>                         select 1 from syscat.triggers
>                         where trigschema in (
>                                 <relevant trigschemas>
>                         ) and valid <> ''Y''
>                 )' ) @[EMAIL PROTECTED]
>
> This way I will be notified that I messed something up, and the
> transaction is rolled back.
>
> /Lennart

I see your point about attended maintenance being the preferred
practice, as opposed to what I'm trying to do.  Thanks for the insight.
 




 8 Posts in Topic:
can a trigger do an execute immediate?
Oliver <JOHolloway@[EM  2008-04-23 12:25:10 
Re: can a trigger do an execute immediate?
Lennart <Erik.Lennart.  2008-04-23 13:06:21 
Re: can a trigger do an execute immediate?
Oliver <JOHolloway@[EM  2008-04-23 13:21:18 
Re: can a trigger do an execute immediate?
Serge Rielau <srielau@  2008-04-23 18:29:12 
Re: can a trigger do an execute immediate?
Lennart <Erik.Lennart.  2008-04-23 20:33:22 
Re: can a trigger do an execute immediate?
"Dave Hughes" &  2008-04-23 22:41:53 
Re: can a trigger do an execute immediate?
Lennart <Erik.Lennart.  2008-04-24 04:01:43 
Re: can a trigger do an execute immediate?
Oliver <JOHolloway@[EM  2008-04-24 06:00:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 21:08:11 CDT 2008.