Subject | Re: [IBO] Re: Autoinc field value unknown after insert+post+commit |
---|---|
Author | Paul Vinkenoog |
Post date | 2005-08-27T12:10:25Z |
Hi JRP,
guarantee that every number is unique.
if there are multiple connections the generator may already have been
incremented several times between the moment you get the value and the
moment you decide to turn it back.
[ But if you still want to do it, the SQL is simple:
MyDummyVar = gen_id( MyGenerator, -1 ); ]
visible to your transaction. To get the current value, call
gen_id( MyGenerator, 0 )
...but that's still not safe, because by the time you set the
generator back it may have been called again by other clients.
may only execute DML (Manipulation).
there's no simple way. But it can be done; there's an article on
this subject here:
http://www.ibobjects.com/docs/ti_AuditableSeries.ZIP
Greetings,
Paul Vinkenoog
> If I cancel the insert, the increment of generator value does notThat's right, and it's meant to be that way. It's the only way to
> cancelled, so I end up with a skipped number each time I cancel.
> It looks like the increment of the generator value happens outside
> my transaction, since I also can't undo the increment with a
> rollback.
guarantee that every number is unique.
> I have a need for an uninterrupted autonumbering sequence. ThisThat's dangerous (like you indicate yourself in your message), because
> means I have to negate the increment of the generator each time I
> perform a cancel.
if there are multiple connections the generator may already have been
incremented several times between the moment you get the value and the
moment you decide to turn it back.
[ But if you still want to do it, the SQL is simple:
MyDummyVar = gen_id( MyGenerator, -1 ); ]
> SELECT MAX(ID) FROM DUMMY INTO :GEN_VAL;This is unsafe because IDs may have been assigned that are not (yet)
visible to your transaction. To get the current value, call
gen_id( MyGenerator, 0 )
...but that's still not safe, because by the time you set the
generator back it may have been called again by other clients.
> I wonder why SET GENERATOR name TO int;Because it's a DDL (Data Definition Language) statement. In SPs you
> do not work inside a stored procedure.
may only execute DML (Manipulation).
> Could someone please show me how to do this safely, simpler and moreIf you *really* must have an uninterrupted sequence, I'm afraid
> efficient? Any tips & tricks would be really appreciated.
there's no simple way. But it can be done; there's an article on
this subject here:
http://www.ibobjects.com/docs/ti_AuditableSeries.ZIP
Greetings,
Paul Vinkenoog