This would allow me to begin and then commit/rollback transactions.
However this does not perform row level locking.

I will show an example to illustrate what I mean.

$DS=$this->getDataSource();
$DS->begin();

$user=$this->findById(1);

              // <-------------------------- A different process might
update this user here setting "is_admin" to false

if($user['User']['is_admin'])  // ---------------------------- Therefore I
cannot ensure that this value is still the same
{
   if($this->save(array('User'=>array('id'=>1,'privileges'=>'all'))))  //
------------------ The save will be successful even though the user is no
longer admin
        {
           $DS->commit();   // ----------------------------------------   I
just committed giving all privileges to a user who is not an admin
        }
   else $DS->rollback();
}


What I really need is somethign like this:

$user=$this->findById(1,array('lock'=>'for update'));  //ps: i know there's
no such thing in cakephp

// this would lock the row with id=1 until I commit or rollback my
transaction
//the actual query would be like this: SELECT * FROM users where id=1 FOR
UPDATE


Thanks :)

On Fri, Aug 12, 2011 at 9:29 PM, Dr. Loboto <[email protected]> wrote:

> Start transaction, select, save, close transaction. Something like
> this:
>
> $DS = $this->getDataSource();
> $DS->begin();
> $this->find(...);
> if ($this->save(...)) {
>    $DS->commit();
> }
> else {
>    $DS->rollback();
> }
>
> On 11 авг, 00:10, Teddy Zeenny <[email protected]> wrote:
> > Hi,
> >
> > Is there a way in cakephp to use SELECT .. FOR UPDATE (for InnoDB row
> > level locking) without using the $Model::query function (as this is
> > highly not recommended) ?
> >
> > If not, does anyone know an alternative ?
> >
> > Thanks,
> >
> > Teddy
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to