Subject | Re: [ib-support] using Gen_id from a stored proc |
---|---|
Author | Helen Borrie |
Post date | 2001-03-24T20:42:39Z |
At 01:56 PM 24-03-01 -0300, you wrote:
I think you have missed the point, Fabrice.
This is a healthy use of a stored proc to get a unique identifier:
CREATE PROCEDURE GET_NEXT_ID
RETURNS (NEXT_ID NUMERIC(18,0))
AS
BEGIN
NEXT_ID = GEN_ID(THE_GENERATOR, 1); /* NEXT_ID is fresh and unique */
SUSPEND;
END
This is a treacherous use:
CREATE PROCEDURE GET_NEXT_ID
RETURNS (NEXT_ID NUMERIC(18,0))
AS
BEGIN
NEXT_ID = GEN_ID(THE_GENERATOR, 0); /* This number was generated for a different row */
NEXT_ID = NEXT_ID + 1; /* Recipe for key violations, Generator principle defeated */
SUSPEND;
END
Regards,
Helen
InterBase Developer Initiative · http://www.interbase2000.org
_______________________________________________________
>(snip)Ann H and I disagree? Never!
> >
> >btw, don't write a procedure that performs its own increment on Gen_ID(GeneratorName,0) as suggested by somebody. This is unsafe and totally defeats the point
> >of using a generator which is (a) to ensure that PK values are unique and (b) to keep the appointment of numbers for primary key assignments outside transaction
> >control.
>
>Curious... You and AnnH seems to disagree strongly in this question. The thing that make it funny is that you both use
>quite similar arguments to justify it.
I think you have missed the point, Fabrice.
This is a healthy use of a stored proc to get a unique identifier:
CREATE PROCEDURE GET_NEXT_ID
RETURNS (NEXT_ID NUMERIC(18,0))
AS
BEGIN
NEXT_ID = GEN_ID(THE_GENERATOR, 1); /* NEXT_ID is fresh and unique */
SUSPEND;
END
This is a treacherous use:
CREATE PROCEDURE GET_NEXT_ID
RETURNS (NEXT_ID NUMERIC(18,0))
AS
BEGIN
NEXT_ID = GEN_ID(THE_GENERATOR, 0); /* This number was generated for a different row */
NEXT_ID = NEXT_ID + 1; /* Recipe for key violations, Generator principle defeated */
SUSPEND;
END
>That's why I love mailing lists. :-)One of the deficiencies of mailing lists is that confusion reigns supreme when one person misreads something. :))
Regards,
Helen
> >All for Open and Open for All
> >Cheers,
> >Helen
> >
> >All for Open and Open for All
> >InterBase Developer Initiative · http://www.interbase2000.org
> >_______________________________________________________
> >
> >
> >To unsubscribe from this group, send an email to:
> >ib-support-unsubscribe@egroups.com
> >
> >
> >
> >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
> >
> >
>
>
>[]s Fabricio
>Systems Developer
>
>
>
>
>To unsubscribe from this group, send an email to:
>ib-support-unsubscribe@egroups.com
>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
InterBase Developer Initiative · http://www.interbase2000.org
_______________________________________________________