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