Home » Database » DB » Bug #2812
support for nested transactions (mysql)
Details
| Request #2812 | support for nested transactions (mysql) |
|---|---|
| Submitted | 2004-11-23 15:19 UTC |
| From | andre dot steffens at adress-research dot de |
| Assigned | danielc |
| Status | Bogus |
| Package | DB |
| PHP Version | 4.3.9 |
| OS | Win2k |
| Roadmaps | (Not assigned) |
Comments
[2004-11-23 15:19 UTC] andre dot steffens at adress-research dot de
Description:
------------
It would be nice to have a counter which is increment on 'begin' and decrement on 'rollback' or 'commit'. Only if the counter is 0 a commit or rollback is really done.
Also you can set a var like transaction_fails. A main transaction only can commit if all sub transactions are ok.
I think this function could be implemented in the methods commit(), rollback() and begin()
What do you think about it?
Thx
Andre
[2004-12-03 16:35 UTC] andre dot steffens at adress-research dot de
What do you think about the following solution?
// {{{ begin()
function begin()
{
if ($this->transaction_opcount == 0) {
if ($this->isError($x = $this->selectdb())) return $x;
$result = @mysql_query('BEGIN', $this->connection);
if (!$result) {
return $this->mysqlRaiseError();
}
$this->transaction_fail = false;
}
$this->transaction_opcount++;
return DB_OK;
}
// }}}
// {{{ commit()
function commit()
{
if ($this->transaction_fail) {
return $this->rollback();
}
if ($this->transaction_opcount > 0) {
$this->transaction_opcount--;
if ($this->transaction_opcount == 0) {
if ($this->isError($x = $this->selectdb())) {
return $x;
}
$result = @mysql_query('COMMIT', $this->connection);
$result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
if (!$result) {
return $this->mysqlRaiseError();
}
$this->transaction_fail = false;
}
}
return DB_OK;
}
// }}}
// {{{ rollback()
function rollback()
{
if ($this->transaction_opcount > 0) {
$this->transaction_opcount--;
if ($this->transaction_opcount == 0) {
if ($this->isError($x = $this->selectdb())) {
return $x;
}
$result = @mysql_query('ROLLBACK', $this->connection);
$result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
if (!$result) {
return $this->mysqlRaiseError();
}
$this->transaction_fail = false;
} else $this->transaction_fail = true;
}
return DB_OK;
}
// }}