Sign up on the Revelation Software website to have access to the most current content, and to be able to ask questions and get answers from the Revelation community

At 25 JUN 2002 02:56:40PM a becker wrote:

I have an order file that has one key and that key is a sequential counter. Many users can create an order.

Problem: I had two users obtain the same sequential counter and the one user overwrote the other user's order resulting, of course, in the first user's order not being filled. (How could it, it was overwritten.)

Does anyone have any idea how I can prevent this from happening again?

Thanks

Andy Becker

IL State Lottery


At 26 JUN 2002 08:37AM Don Miller - C3 Inc. wrote:

Well .. do a search on sequential counter / keys. The AREV / OI way of doing this is totally flawed and, in general is pretty worthless (witness the problem you've had). The only satisfactory way to handle this is to roll your own sequential key routine. The way you construct this depends on whether your sequential key assignment will allow holes in the sequence. For example, if it's being used to assign check #'s, then it would be a no-no. However, if you're simply trying to assign a unique transaction number for new records then the logic is different.

The code necessary to do this is, I think, beyond the scope of this post .. besides that's how developers make their living anyway. Suffice it to say, the new key number should only be assigned and updated when the new record is written and not when the screen opens. Most assuredly, don't use it as a "default".

HTH

Don Miller

C3 Inc.


At 26 JUN 2002 11:09AM a becker wrote:

Thanks Don - if I would had realized that when I designed the system, I would have had more than one key on the orders file.

Oh well - I'll figure something out

Thanks

Andy Becker

IL State Lottery


At 26 JUN 2002 11:19AM [url=http://www.sprezzatura.com" onMouseOver=window.status= Click here to visit our web site?';return(true)]The Sprezzatura Group[/url] wrote:

At 26 JUN 2002 05:59PM Richard Hunt wrote:

I use sequential counters (I call them next availables). The steps I use are as follows…

NOTE: At data entry of the record (row) id, if it is NULL then get the next sequential counter. I store the next sequential counter in a sequential counter file (table). The record (row) id is the file (table) name and field 1 in the record (row) is the last used sequential counter.

1) Lock the sequential counter record (row). Read the sequential counter record (row).

2) Lock the file record (row) using the sequential counter as the ID. If the lock fails skip to step 4. Otherwise read the file record (row) using the sequential counter as the ID. If the record (row) already exists then skip to step 4.

3) Write the sequential counter record (row). Unlock the sequential counter record (row). All done!

4) Unlock the file record (row). Increment the sequential counter and then go back to step 2.

This method will probably fail the first time almost always because the record (row) should already exist. Doing it this way should almost guarantee not skipping in the sequence (well about 99% of the time). I guess if user A is working on record (row) 1, and at the same time, user B is working on record (row) 2, and user A chooses to abort the entry, then record (row) 1 will never exist sequentially.


At 27 JUN 2002 08:57AM Don Miller - C3 Inc. wrote:

]] You said ..

(1) Lock the sequential counter record (row). Read the sequential counter record (row).

2) Lock the file record (row) using the sequential counter as the ID. If the lock fails skip to step 4. Otherwise read the file record (row) using the sequential counter as the ID. If the record (row) already exists then skip to step 4.

3) Write the sequential counter record (row). Unlock the sequential counter record (row). All done!

4) Unlock the file record (row). Increment the sequential counter and then go back to step 2.

This method will probably fail the first time almost always because the record (row) should already exist. Doing it this way should almost guarantee not skipping in the sequence (well about 99% of the time). I guess if user A is working on record (row) 1, and at the same time, user B is working on record (row) 2, and user A chooses to abort the entry, then record (row) 1 will never exist sequentially

This is ok if you don't mind holes in the numbering scheme. As you pointed out, if a record is aborted then possible holes. Another possibility is deleting an erroneous entry after saving. If holes are not allowed, then the delete cannot be allowed. Instead a "void" record needs to be created (I usually date/time/user stamp this too). The better way is to do the task at write time rather than when the record is begun.

Don Miller

C3 Inc.

View this thread on the forum...

  • third_party_content/community/commentary/forums_nonworks/ddc36a18e46b6c1685256be3006810fd.txt
  • Last modified: 2023/12/28 07:40
  • by 127.0.0.1