Victor Ng wrote: > If user A and user B are editting the same records and you enter a > race where they do this: > > A) retrieve record
Here you mean SELECT FOR UPDATE, right? > B) retrieve record Same here, right? > A) delete record > B) update record As SELECT FOR UPDATE starts a transaction, these two are in concurrent transactions, right? > The select for update that user B uses will succeed since the select > will simply return 0 rows. The update will succeed because 0 rows are > updated successfully. The update will not be tried if its SELECT FOR UPDATE returns 0 rows, since there is nothing to update. The UPDATE will be made only if SELECT FOR UPDATE returns exactly 1 row. Otherwise the transaction is rolled back and the client informed that he needs to try again (and why). The transaction is commited after the last table is UPDATED. On any error the transaction is rolled back. Similar for DELETE. Sorry, I was to be explicite that SELECT FOR UPDATE must return 1 row. Thus, in your example either DELETE or UPDATE will fail with a possibility for a good error message for the client. > SELECT FOR UPDATE really only helps if the SQL commands are running > concurrently. They are running concurrently in your example. At least I don't see why not. In case you mean by 'retrieve record' something else than SELECT FOR UPDATE, e.g. simple SELECT for GET (i.e. for the client to decide what to do with this row). We do not start any (lasting) transaction at this moment, just because we don't need to. One more clarification (correction). I said 'all information from all fields..', but I have examples of fields which might be (or might be not) omitted from the SELECT FOR UPDATE. For one, the last modification timestamp field. > vic > > -- > "Never attribute to malice that which can be adequately explained by > stupidity." - Hanlon's Razor --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---