Google
 

Rabu, 19 September 2007

Firebird System Table (Part II)

Another FB system table is system table for trigger. The reason I create this view is to scan for some code inside the source of the trigger. For example, I want to change the field type of table A, then I want to know, this field is being used by which trigger, so I can search thorough this view:

CREATE VIEW "vSYS_FindTriggerSource"(
"triggerName",
"tableName",
"triggerInactive",
"triggerSource")
AS
select r.rdb$trigger_name, r.rdb$relation_name, r.rdb$trigger_inactive, r.rdb$trigger_source
from rdb$triggers r
where r.rdb$system_flag = 0


If you want to seach some text in the trigger source then you can use this simple query:

select *
from "vSYS_FindTriggerSource"
where "triggerSource" containing 'some_field'


The keyword "containing" here (if I'm not forget) is exists from FB 2. The difference between "containing" and "like" is the "like" is case sensitive where "containing" is case insensitive, and also you not need the "%" sign like in "like" keyword.

That view also display the status of the trigger, if the "triggerInactive" field value is zero, then it means that trigger is active and vice versa.

2 komentar:

Anonim mengatakan...

The first query for system tables which I learn was
select RDB$DEPENDENT_NAME, RDB$DEPENDENT_TYPE
from RDB$DEPENDENCIES
where RDB$DEPENDED_ON_NAME = 'MY_TABLE' and RDB$FIELD_NAME = 'MY_FIELD';
This query show all dependencies on field and dependent type is:
0 - table
1 - view
2 - trigger
3 - computed_field
4 - validation
5 - procedure
6 - expression_index
7 - exception
8 - user
9 - field
10 - index

It was IB4 and WISQL shown very clear message like '... there are X dependencies' on trying to delete some fields...

Randy White mengatakan...

CONTAINING is in Firebird since the first versions (1.0, 1.5, 2.0).

Milan Babuskov
http://www.firebirdfaq.org