Subject Re: [firebird-support] Generating unique continual integers for invoice numbering
Author Ann W. Harrison
toldy007@... wrote:
> Thanks for your reply Marcin.
>
> I think that your solution won't solve my problem. As I know, BeforeInsert will be called when the
> INSERT is called and not after the commit!
>
> Thus if there is a problem with the INSERT or there is a rollback, a concurrent transaction
> inserting a record at the same time could cause a gap in the numbering!
>
> Any more ideas?

Generators are outside transaction context to avoid waits
and potential deadlocks. The cost of that performance is
losing an occasional number. If you want an unbroken sequence,
you'll have to serialize your updates.

Create a table to hold the unique integer. In your application,
update the counter and use the new value. Until you commit,
no one else can update the counter. If the first action of the
transaction is the update of the counter, that's all you have to
rollback when you get the "update conflict" error.

Best regards,


Ann