Subject | RE: [firebird-support] Re: Generators for auto-increment - with override |
---|---|
Author | Alan McDonald |
Post date | 2005-01-08T00:16:23Z |
> Daniel L. Miller wrote:before insert - why would you want to change the PK during update?
>
> >My question now is how to handle "tinkering". Particularly when
> >developing a new database/application, it's typical to add or change
> >records without going through the "proper" procedures (for example, I
> >use ibwebadmin, which forces an entry in primary key fields without
> >checking the result of the before insert trigger). So the generator
> >can get "behind" in its numbering.
> >
> >If I want to implement "generator protection" - where should I place
> >it? In the before-inserts, the after-updates, both, or elsewhere? Is
> >this something I should keep in my production environment as a form of
> >defensive programming? I'm envisioning something like (and I haven't
> >tried this yet):
> >
> >DECLARE VARIABLE t_id INTEGER;
> >DECLARE VARIABLE t_gen INTEGER;
> >BEGIN
> > SELECT MAX(id) FROM jobs INTO :t_id;
> > t_gen = GEN_ID( g_job_id, 0 );
> > IF ( t_id > t_gen ) THEN
> > t_id = GEN_ID( g_job_id, ( t_id - t_gen ) );
> >END
> >
> >
> Thanks very much for the responses - but they don't quite answer my
> questions. To re-state:
>
> Question #1: Where should I implement "generator protection" -
> before or after inserts/updates?
> Question #2: Should I keep this "protection" in a productionI wouldn't use it at all, anywhere - but its up to you
> environment?
>
Alan
> --
> Daniel