I have used this on one of my projects:

        function afterSave() {
                /*
                ** If new record find counter
                */
                if(! @$this->data['Protocolli']['id']) {
                        $id            = $this->getLastInsertId();
                        $anno          = $this->data['Protocolli']['anno'];
                        $segreteria_id =
$this->data['Protocolli']['segreteria_id'];

                        $sql = 'LOCK TABLES protocolli READ';
                        $this->execute($sql);

                        $sql = "SELECT MAX(numero) as maxnum 
                                      FROM protocolli 
                                     WHERE anno = {$anno} 
                                   AND segreteria_id = {$segreteria_id}";
                        $row = $this->execute($sql);

                        $num = (int) $row[0][0]['maxnum'] + 1;

                        $sql = 'LOCK TABLES protocolli WRITE';
                        $this->execute($sql);

                        $sql = "UPDATE protocolli 
                                       SET numero = {$num} 
                                 WHERE id = {$id}";
                        $this->execute($sql);

                        $sql = 'UNLOCK TABLES';
                        $this->execute($sql);
                }
                return parent::afterSave();
        } 

> -----Messaggio originale-----
> Da: cake-php@googlegroups.com 
> [mailto:[EMAIL PROTECTED] Per conto di Chris Hartjes
> Inviato: lunedì 20 agosto 2007 15.32
> A: cake-php@googlegroups.com
> Oggetto: Re: about row locking
> 
> 
> On 8/20/07, sharath <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> > I'm using cake & mysql for editing purpose.
> > Now i want to lock a particular row of a table. Can anybody tell me 
> > about how to do this in cake?
> >
> > Thanks in advance,
> > sharath.
> 
> That is a MySQL issue, not a CakePHP one.  I am not aware of 
> any functionality that exists in CakePHP to let you do this, 
> but my quess is this:  if you can lock a row with a MySQL 
> command then you can probably run it using 
> $this->Foo->query(...) if you need a response back or 
> $this->Foo->execute(...) if you don't.
> 
> Hope that helps.
> 
> --
> Chris Hartjes
> Senior Developer
> Cake Development Corporation
> 
> My motto for 2007:  "Just build it, damnit!"
> 
> @TheBallpark - http://www.littlehart.net/attheballpark
> @TheKeyboard - http://www.littlehart.net/atthekeyboard
> 
> > 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to