in reply to Executing a Script to Completion

Two people trying to add the same surname simultaneously is already handled because add_surname.cgi first checks if an entry already exists for the surname in question.
This makes two people adding the same surname less likely, but not impossible. Imagine your code is like this:
1. Check if surname exists
2. Add surname
and you have two clients, Alice and Bob, both adding the same surname. If things happen to be ordered like this:
Alice: Check if surname exists (it doesn't)
  Bob: Check if surname exists (it doesn't)
Alice: Add surname
  Bob: Add surname
you'll have the same problem. One solution is to enforce only a single surname in the database, with UNIQUE constraints on columns.

Replies are listed 'Best First'.
Re: Re: Executing a Script to Completion
by exussum0 (Vicar) on Jan 02, 2004 at 12:35 UTC
    The only thing I don't like about this solution is, it doubles the number of sql queries in the worst case. If your db is already heavily loaded at time of execution, it makes matters worse. If your db is sitting around doing nothing, it works really well.

    ++sgifford, since it works really well on small inputs regardless. :)


    Play that funky music white boy..