Subject | Re: where the generators values located? |
---|---|
Author | jameschua1021 |
Post date | 2005-06-03T05:40:16Z |
Hi Adam,
Thanks for the SP you've provided I did get some ideas from it. What
Iam trying to do is to create a before insert trigger that will first
choose what generator to be use depending on the value supplied on one
of the table's column. But I don't want to write several if statement
on what generator to be use base on the value.
Do you have any alternative solution, because I've read from Helen's
Firebird Book, that as much as possible try to refrain from using the
EXECUTE STATEMENT.
Apinot
Thanks for the SP you've provided I did get some ideas from it. What
Iam trying to do is to create a before insert trigger that will first
choose what generator to be use depending on the value supplied on one
of the table's column. But I don't want to write several if statement
on what generator to be use base on the value.
Do you have any alternative solution, because I've read from Helen's
Firebird Book, that as much as possible try to refrain from using the
EXECUTE STATEMENT.
Apinot
--- In firebird-support@yahoogroups.com, "Adam" <s3057043@y...> wrote:
> Hello,
>
> The generator values are not stored there. In any case, why did you
> want to do this for? There are probably better ways to do what you
> are trying to do.
>
> With that disclaimer, here is a simple stored procedure can fetch
> them for you (requires FB 1.5+), but do tell why you need it.
>
>
>
> CREATE PROCEDURE SP_GET_GENERATOR_VALUES
> RETURNS
> (
> GENERATOR_NAME VARCHAR(50),
> CURRENT_VALUE BIGINT
> )
> AS
> DECLARE VARIABLE STMT VARCHAR(300);
> BEGIN
> FOR SELECT RDB$GENERATOR_NAME
> FROM RDB$GENERATORS
> WHERE RDB$SYSTEM_FLAG IS NULL
> ORDER BY RDB$GENERATOR_NAME
> INTO :GENERATOR_NAME
> DO
> BEGIN
> STMT = 'SELECT GEN_ID(' || :GENERATOR_NAME || ', 0) FROM
> RDB$DATABASE';
> EXECUTE STATEMENT STMT INTO :CURRENT_VALUE;
> SUSPEND;
> END
> END
> ^
>
> Adam
>