Subject | Re: [Firebird-Architect] Database triggers |
---|---|
Author | Adriano dos Santos Fernandes |
Post date | 2006-09-19T15:41Z |
Vlad Horsun wrote:
invalidating the attachment handle?
Seems difficult to make TPB customizations.
They could be added later.
Adriano
> "Adriano dos Santos Fernandes" ...Yes. Forget to mention because I don't see anything useful for it. :-)
>
>> Triggers fired in database events are useful for many things:
>> On connect/disconnect for logging or logon control.
>> On begin transaction for implementation of a "writable transaction
>> id" (incrementing a generator and storing in a context variable).
>> On commit triggers for business rules validations.
>>
>
> And on rollback of course
>
>Yes.
>
>> Proposed syntax:
>> CREATE TRIGGER <name> <type> AS ...
>>
>> Types:
>> AFTER CONNECT (or LOGON as in Oracle?)
>>
>
> ON CONNECT
> fired after user validation and attachment creation but before
> return from jrd8_attach_database. Worked in own auto-started
> and auto-stoped transaction. Any unhandled exception prevent
> CONNECT to be succsesfull and error code returns to client as
> result
>
>What about pass the exception to client (instead of log) but
>> BEFORE DISCONNECT (or LOGOFF)
>>
>
> ON DISCONNECT
> fired before erase of any attachment resources. Worked in own
> auto-started and auto-stoped transaction. Any unhandled exception
> don't prevent DISCONNECT but logged in firebird.log
>
invalidating the attachment handle?
>Yes.
>> AFTER BEGIN TRANSACTION
>>
>
> ON BEGIN TRANSACTION
> fired just after transaction starts in context of that transaction.
> Any unhandled exception breaks this transaction. Error code returns
> to client
>
>They are executed too.
>> BEFORE COMMIT
>>
>
> ON END TRANSACTION
> fired before transaction end (and therefore before any DFW works).
> Unhandled exception leave transaction open. Error code returns to client
> What to do with commit\rollback_retaining ?
> Needs read-only context variableSeems nice. And maybe ON TRANSACTION START (instead of BEGIN TRANSACTION).
> with kind of transaction end (commit\rollback).
>
> Or use common syntax
>
> ON <TRANSACTION | COMMIT | ROLLBACK>
> where ON TRANSACTION fired after transaction start, ON COMMIT - before
> commit, ON ROLLBACK - before rollback
>
>Seems not logical to auto-run things when doing backup or fixing a database.
>
>> They will be stored in RDB$TRIGGERS with RDB$RELATION_NAME = NULL.
>>
>> RDB$TRIGGER_TYPE will store incompatible values with the current ones,
>> but RDB$RELATION_NAME = NULL make they work in different ways.
>>
>
> Agree
>
>
>> Or another field (RDB$TRIGGER_KIND?) could be created to store in what
>> event the trigger are fired (DML, DATABASE, DDL in the future), so the
>> real trigger type become (RDB$TRIGGER_KIND, RDB$TRIGGER_TYPE).
>>
>
> For now i don't see needs in such field
>
>
>> These triggers may make the database unusable (for example, an exception
>> in a CONNECT trigger), so it could be disabled (only for the attachment)
>> through a DPB, but only by sysdba/db-owner.
>>
>
> Maybe yes
>
>
>> Attachments from GBAK/GFIX/GSEC automatically make this flag ON.
>>
>
> Why ?
>
>I think we should define a constant TPB.
>> To run CONNECT/DISCONNECT, the engine will start and finish a snapshot
>> transaction.
>>
>
> Agree. What about other parameters ? concurrency, write, wait ?
>
Seems difficult to make TPB customizations.
>While they are SQL standard, they're not so useful as db triggers.
>
>> Exceptions in CONNECT, BEGIN TRANSACTION and COMMIT cancels the
>> operation. But not cancels (the detach) in DISCONNECT.
>>
>
> Agree
>
>
> Regards,
> Vlad
>
> PS What about triggers on DDL : CREATE\ALTER\DROP TABLE\PROCEDURE\etc ?
>
They could be added later.
Adriano