|
Posted by Chung Leong on 10/24/06 16:43
Rik napisal(a):
> Daz wrote:
> >> So, validate the names. Then use Chung's process for updating your
> >> table with the ones which are valid.
> >
> > Hi Jerry.
> >
> > Thanks for that.
> >
> > This brings be back to my original question.
> >
> > Is the best way to validate the names, by having the db names in one
> > array, and the users books in another, and iterating through the users
> > array using in_array() to check if it's a valid book in the db array.
>
> Create an array of what to add, capture all existing items in another array
> , then it's a simple question of array_diff() for items that are invalid.
>
> Then create an array of already owned items, array_intersect() will tell
> you what to update, the rest will have to be added.
> --
> Grtz
>
> Rik Wasmus
Then you end up with a race condition, I think even if a transaction is
used. If there are two threads trying to insert the same data running
simultaneously, a transaction would not block the second thread from
fetching the same result set as the first. Thus both threads could
think that a particular record doesn't exist and both would insert it.
You would need to lock the table for the duration of the entire
operation, which is pretty lousy.
[Back to original message]
|