Subject | Re: [firebird-support] Numeration without hole, Is right Before Insert Trigger? |
---|---|
Author | Svein Erling Tysvær |
Post date | 2015-12-24T11:05:26Z |
Also, take a look at this ancient document that used to be the standard answer to people asking the same question as yours: http://ibobjects.com/docs/ti_AuditableSeries.ZIP
HTH,
Set
2015-12-22 20:26 GMT+01:00 Ann Harrison aharrison@... [firebird-support] <firebird-support@yahoogroups.com>:
On Tue, Dec 22, 2015 at 9:40 AM, Luigi Siciliano luigisic@... [firebird-support] <firebird-support@yahoogroups.com> wrote:
I must assign a serial number, without hole, in a column of a fiscal
document. I must assign the number only when I know if the document is complete
and I think the right moment is on a Before Insert Trigger for the table.Yes that's a good place, but you've got to be very careful. Generators/Sequences won'twork because they're deliberately non-transactional. Once you take one its gone and ifyour operation fails, you'll have a hole.
Is right or the insertion can fail? If not right, when I must assign the
number to be sure of not have a hole in numeration?One way to get numbers without holes is to create a table with one field that containsthe seed for your numbers. In your before insert trigger update that field adding one to it,then read to get the new value. Unfortunately, if someone else has inserted a recordconcurrently, your transaction will wait then get an error and you'll need to re-run thewhole thing.Check the FAQ's at FirebirdSQL.org for other ways of handling this problem.Good luck,Ann