Issues

ZF-10736: Support nested transactions.

Issue Type: Improvement Created: 2010-11-23T19:38:23.000+0000 Last Updated: 2012-05-28T21:10:53.000+0000 Status: Open Fix version(s): Reporter: Dolf Schimmel (Freeaqingme) (freak) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db

Related issues: Attachments:

Description

Nested transactions would be nice. Code I used for this:

<pre class="highlight">
<?php

class Freak_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Mysql {

    protected $_commitStack = array();

    public function beginTransaction() {
        $count = count($this->_commitStack);
        array_push($this->_commitStack, 'ZFsavePoint'.$count);
        if($count == 0)
        {
            parent::beginTransaction();
        } else {
            $this->query('SAVEPOINT ZFsavePoint'.$count);
        }

        return $this;
    }

    public function commit() {
        if(count($this->_commitStack) == 1) {
            parent::commit();
        }

        array_pop($this->_commitStack);
        return $this;
    }
    
    public function rollback() {
        $lastTransaction = array_pop($this->_commitStack);
        if(count($this->_commitStack == 0)) {
            parent::rollback();
        } else {
            $this->query('ROLLBACK TO SAVEPOINT '.$lastTransaction);
        }

        return $this;        
    }
}

Comments

Posted by Marc Hodgins (mjh_ca) on 2010-11-23T20:57:00.000+0000

Very cool. +1 on this.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-11-24T07:51:53.000+0000

Sorry, forgot to assign a component (and as such, the appropriate assignee). Component assigned now.

Posted by William Vicary (williamvicary) on 2012-05-28T21:10:53.000+0000

Nice implementation +1 too.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts