mirror of
https://github.com/dg/dibi.git
synced 2025-08-13 17:44:11 +02:00
- implemented savepoints support
This commit is contained in:
@@ -330,18 +330,23 @@ class DibiConnection extends DibiObject
|
||||
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optinal savepoint name
|
||||
* @return void
|
||||
*/
|
||||
public function begin()
|
||||
public function begin($savepoint = NULL)
|
||||
{
|
||||
$this->connect();
|
||||
if ($this->inTxn) {
|
||||
if (!$savepoint && $this->inTxn) {
|
||||
throw new DibiException('There is already an active transaction.');
|
||||
}
|
||||
if ($this->profiler !== NULL) {
|
||||
$ticket = $this->profiler->before($this, IDibiProfiler::BEGIN);
|
||||
$ticket = $this->profiler->before($this, IDibiProfiler::BEGIN, $savepoint);
|
||||
}
|
||||
$this->driver->begin();
|
||||
if ($savepoint && !$this->inTxn) {
|
||||
$this->driver->begin();
|
||||
}
|
||||
$this->driver->begin($savepoint);
|
||||
|
||||
$this->inTxn = TRUE;
|
||||
if (isset($ticket)) {
|
||||
$this->profiler->after($ticket);
|
||||
@@ -352,18 +357,19 @@ class DibiConnection extends DibiObject
|
||||
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optinal savepoint name
|
||||
* @return void
|
||||
*/
|
||||
public function commit()
|
||||
public function commit($savepoint = NULL)
|
||||
{
|
||||
if (!$this->inTxn) {
|
||||
throw new DibiException('There is no active transaction.');
|
||||
}
|
||||
if ($this->profiler !== NULL) {
|
||||
$ticket = $this->profiler->before($this, IDibiProfiler::COMMIT);
|
||||
$ticket = $this->profiler->before($this, IDibiProfiler::COMMIT, $savepoint);
|
||||
}
|
||||
$this->driver->commit();
|
||||
$this->inTxn = FALSE;
|
||||
$this->driver->commit($savepoint);
|
||||
$this->inTxn = (bool) $savepoint;
|
||||
if (isset($ticket)) {
|
||||
$this->profiler->after($ticket);
|
||||
}
|
||||
@@ -373,18 +379,19 @@ class DibiConnection extends DibiObject
|
||||
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optinal savepoint name
|
||||
* @return void
|
||||
*/
|
||||
public function rollback()
|
||||
public function rollback($savepoint = NULL)
|
||||
{
|
||||
if (!$this->inTxn) {
|
||||
throw new DibiException('There is no active transaction.');
|
||||
}
|
||||
if ($this->profiler !== NULL) {
|
||||
$ticket = $this->profiler->before($this, IDibiProfiler::ROLLBACK);
|
||||
$ticket = $this->profiler->before($this, IDibiProfiler::ROLLBACK, $savepoint);
|
||||
}
|
||||
$this->driver->rollback();
|
||||
$this->inTxn = FALSE;
|
||||
$this->driver->rollback($savepoint);
|
||||
$this->inTxn = (bool) $savepoint;
|
||||
if (isset($ticket)) {
|
||||
$this->profiler->after($ticket);
|
||||
}
|
||||
@@ -392,6 +399,17 @@ class DibiConnection extends DibiObject
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is in transaction?
|
||||
* @return bool
|
||||
*/
|
||||
public function inTransaction()
|
||||
{
|
||||
return $this->inTxn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Encodes data for use in an SQL statement.
|
||||
* @param string unescaped string
|
||||
|
@@ -41,7 +41,7 @@ class DibiException extends Exception
|
||||
* @copyright Copyright (c) 2005, 2008 David Grudl
|
||||
* @package dibi
|
||||
*/
|
||||
class DibiDriverException extends DibiException implements /*Nette::*/IDebuggable
|
||||
class DibiDriverException extends DibiException implements /*Nette\*/IDebuggable
|
||||
{
|
||||
/** @var string */
|
||||
private static $errorMsg;
|
||||
@@ -85,7 +85,7 @@ class DibiDriverException extends DibiException implements /*Nette::*/IDebuggabl
|
||||
|
||||
|
||||
|
||||
/********************* interface Nette::IDebuggable ****************d*g**/
|
||||
/********************* interface Nette\IDebuggable ****************d*g**/
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -161,28 +161,31 @@ interface IDibiDriver
|
||||
|
||||
/**
|
||||
* Begins a transaction (if supported).
|
||||
* @param string optinal savepoint name
|
||||
* @return void
|
||||
* @throws DibiDriverException
|
||||
*/
|
||||
function begin();
|
||||
function begin($savepoint = NULL);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Commits statements in a transaction.
|
||||
* @param string optinal savepoint name
|
||||
* @return void
|
||||
* @throws DibiDriverException
|
||||
*/
|
||||
function commit();
|
||||
function commit($savepoint = NULL);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Rollback changes in a transaction.
|
||||
* @param string optinal savepoint name
|
||||
* @return void
|
||||
* @throws DibiDriverException
|
||||
*/
|
||||
function rollback();
|
||||
function rollback($savepoint = NULL);
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user