On Tue, Dec 22, 2015 at 9:40 AM, Luigi Siciliano luigi...@tiscalinet.it
[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't
work because they're deliberately non-transactional.  Once you take one its
gone and if
your 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 contains
the 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 record
concurrently, your transaction will wait then get an error and you'll need
to re-run the
whole thing.

 Check the FAQ's at FirebirdSQL.org for other ways of handling this problem.


Good luck,

Ann


>
>
  • ... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]
    • ... Ann Harrison aharri...@ibphoenix.com [firebird-support]
      • ... Svein Erling Tysvær setys...@gmail.com [firebird-support]
        • ... 'Walter R. Ojeda Valiente' sistemas2000profesio...@gmail.com [firebird-support]
          • ... slucas slu...@iquanta.com [firebird-support]
            • ... 'Walter R. Ojeda Valiente' sistemas2000profesio...@gmail.com [firebird-support]
              • ... slucas slu...@iquanta.com [firebird-support]

Reply via email to