Saturday, June 28, 2014

Re: database table locking across supported database

Hi,

On Wed, Jun 18, 2014 at 1:34 PM, José Lorenzo <jose.zap@gmail.com> wrote:
> Why do you want to lock it?

let assume a database schema : id (primary, auto inc), receipt_number
(varchar), amount (float)

The "receipt_number" is to be incremented on every insert. This is not
the id field which is auto incremented by the database itself. Its a
different field from 'id' that can have numbers, characters, special
characters, etc. The receipt_number has to be incremented in the code
and cannot be done automatically for various other reasons.

Now let say I want to insert a row, I will read the last
receipt_number, increment it and write the new row back to database.
At the same time another user is also inserting a row, he read the
last entry receipt_number which is the same as I read since I have not
yet written the new row. He will also increment to the same value and
write it back. This will lead to a conflict. That is why I need a
reliable way to lock the table so that no one else can read/write to
the table until I have finished with reading and writing the new row
as one atomic operation.

http://docs.doctrine-project.org/en/2.0.x/reference/transactions-and-concurrency.html

Regards.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: