Subject | Re: [IBO] accessing a generator |
---|---|
Author | Lucas Franzen |
Post date | 2003-09-23T18:02:25Z |
Peter,
peter@... schrieb:
- You can do a statement like:
SELECT GEN_ID ( <GENERATORNAME>, <increment> ) from RDB$DATABASE
- You can use IBO's built-in-function GEN_ID (which works with every
TIB_Component, be it a TIB_Connection, TIB_Query, TIB_Cursor or...) for
example:
NewValue := IB_Query.Gen_id ( <GENERATORNAME>, <increment> )
- You can, of course, use a stored procedure like:
create procedure get_id
returns ( new_id integer )
as
begin
new_id = gen_id ( <GENERATORNAME>, <increment> );
end
- You can assign the value within a before insert trigger
create trigger bi_mytable
for mytable before insert position 0
as
begin
if ( new.pkfield IS NULL ) then
begin
new.pkfield = gen_id ( <GENERATORNAME>, <increment> );
end
end
and maybe there are some more options.
If you have mass inserts and you can be sure you have a single user
connection to the database (so noone else can use this generator in the
meantime) it's easier to get the first value, increment it on your own
while inserting and set the generator to the last (client side) applied
value afterwards.
(I do use this when building a database from some ascii data where
millions of records are inserted)
Luc.
peter@... schrieb:
> HiYou have a lot of choices for getting / setting a generator value.
>
> I have a generator which I wish to use to indicate sets of batch
> downloads , a sort of batch counter.
>
> Which is the best way to access the generator via a stored procedure
> ? or is there an easier way ? I don't believe I can use a trigger as
> I wish to access and increment it manually in response to a user
> request then associate it with a group of pins. The reason being to
> be able to generate a short report on what pins were downloaded in
> that batch.
- You can do a statement like:
SELECT GEN_ID ( <GENERATORNAME>, <increment> ) from RDB$DATABASE
- You can use IBO's built-in-function GEN_ID (which works with every
TIB_Component, be it a TIB_Connection, TIB_Query, TIB_Cursor or...) for
example:
NewValue := IB_Query.Gen_id ( <GENERATORNAME>, <increment> )
- You can, of course, use a stored procedure like:
create procedure get_id
returns ( new_id integer )
as
begin
new_id = gen_id ( <GENERATORNAME>, <increment> );
end
- You can assign the value within a before insert trigger
create trigger bi_mytable
for mytable before insert position 0
as
begin
if ( new.pkfield IS NULL ) then
begin
new.pkfield = gen_id ( <GENERATORNAME>, <increment> );
end
end
and maybe there are some more options.
If you have mass inserts and you can be sure you have a single user
connection to the database (so noone else can use this generator in the
meantime) it's easier to get the first value, increment it on your own
while inserting and set the generator to the last (client side) applied
value afterwards.
(I do use this when building a database from some ascii data where
millions of records are inserted)
Luc.