Issues

ZF-10736: Support nested transactions.

Description

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


<?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

Very cool. +1 on this.

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

Nice implementation +1 too.