Subject | Re: [firebird-support] Re: Legitimate generator reset |
---|---|
Author | Ann W. Harrison |
Post date | 2005-10-24T15:52:06Z |
> Alan wrote:The problem, essentially, is that generators are a general purpose
>
> Any ideas for this system oriented VIEW from any system table gurus?
> thanks
mechanism for creating unique values - not the exact equivalent of
autonumber fields. There's talk of creating some language for
specialized generators in a future version, but for now, the best
hope is to track generators through the RDB$DEPENDENCIES table,
though I don't think you can coerce the generator value from this
technique.
Here's a very simple example:
SQL> create database 'foo.fdb';
SQL> create table t1 (f1 integer not null primary key);
SQL> set term ^;
SQL> create generator f1_t1^
SQL> create trigger t1_bi_0 for t1 before insert position 0
CON> as begin
CON> if (new.f1 is null) then
CON> new.f1 = gen_id (f1_t1, 1);
CON> end^
SQL> commit^
SQL> set term ;^
SQL> set list;
SQL> select * from rdb$dependencies;
RDB$DEPENDENT_NAME T1_BI_0
RDB$DEPENDED_ON_NAME T1
RDB$FIELD_NAME F1
RDB$DEPENDENT_TYPE 2
RDB$DEPENDED_ON_TYPE 0
RDB$DEPENDENT_NAME T1_BI_0
RDB$DEPENDED_ON_NAME F1_T1
RDB$FIELD_NAME <null>
RDB$DEPENDENT_TYPE 2
RDB$DEPENDED_ON_TYPE 14
A view that joins RDB$DEPENDENCIES on itself
will get the relationship between tables and generators -
select distinct d1.rdb$depended_on_name,
d1.rdb$field_name,
d2.rdb$depended_on_name
from rdb$dependencies d1
join rdb$dependencies d2
on d1.rdb$dependent_name = d2.rdb$dependent_name
where d1.rdb$dependent_type = 2
and d2.rdb$dependent_type = 2
and d1.rdb$depended_on_type = 0
and d2.rdb$depended_on_type = 14
Regards
Ann