Securing a Transaction

Asked

Viewed 113 times

0

I have a table of Tags with sequential ID incremented in hand, because it Zera every day.

I have a Tag registration screen where I pass the amount of tags to be generated:

Vrg := Select MAX onde eu pego o maior RG.
qtETQ := quantidade de etiquetas, por exemplo 500 etiquetas digitada pelo usuario 
i := 0
while i <= qtEtq do  //loop de 500 vezes
begin
  Vrg := Vrg+1 
  etiqueta.rg := Vrg
  etiqueta.post
end

My question is this::

If I have two screens open, they can happen to have duplicate labels. There’s a way around that?

  • an alternative is before you enter in the database check if there is already a label registered with that rg, if there is a new code or keep adding.

  • I don’t know if you give the commit only at the end of the loop or the sticker. already commit the information in the bank. However commit be given only at the end (recommended), I suggest you work with a quence (as Oracle does). If it is not Oracle, you can simulate a quence, ensuring the exclusivity of the label.

  • @Andrey how do I simulate this Quence in Delphi? I’m using Firebird

  • You can ride a Generator on Firebird and each day when it is the first access to reset the Generator (In this case the SGDB itself will guarantee the unique RG). If you try to control the application level, either leave the table in Lock or commit to each new record.

  • The application even shows some error?

1 answer

0

A solution that can impact performance but that will solve the problem is every loop iteration you give the "select max + 1" in the field of rg.

I don’t know exactly what the size of your application and its infrastructure, depending can be a bad idea or something tolerable.

One option you could try would be to leave this field as auto increment, but there’s the question of Zera your count every day.

  • Thanks for the tip, but I decided to create a separate table in the databank, which controls whether or not to generate tags.

  • It would be a good thing if you put an answer to your own question showing how you did it to solve, this can be useful for more people.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.