Subject | Re: [firebird-support] Re: Auto Incrementing field |
---|---|
Author | Martijn Tonies |
Post date | 2003-12-10T08:48:08Z |
Hi,
What I do, if I want to make sure my values auto-inc, is the following:
1) create an auto-inc-like trigger, but only fire it if there's NULL or 0
in my "ID" column.
2) use a componentset that allows you to set a generator for a specific
field, so that before posting the field, it will fetch a new generator
value first.
or
3) get the generator value myself if I need it on the client side and put
it into the ID column myself.
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com
> > Thank you for your explanation. I did it.Yes, it does. But it's not multi-user safe.
> > Now how can I get this auto generated vaule when I insert records? I
> have an
> > example for mssql server which uses @@IDENTITY for returning this value.
> > Does it work for firebird?
> > Should I start a new message thread for this?
> >
>
> I think Gen_id function can do this job.
>
> Syntax is : gen_id ( generator, step)
>
> If you set argument "step" to 1, the function increment the generator
> by 1 and returns the value of the generator.
>
> If you set argument "step" to 0, the function returns the value of the
> generator without increment or decrement.
What I do, if I want to make sure my values auto-inc, is the following:
1) create an auto-inc-like trigger, but only fire it if there's NULL or 0
in my "ID" column.
2) use a componentset that allows you to set a generator for a specific
field, so that before posting the field, it will fetch a new generator
value first.
or
3) get the generator value myself if I need it on the client side and put
it into the ID column myself.
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com