mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
FIX Support nested transactions
This commit is contained in:
parent
406fcee3cd
commit
6b3959ba48
@ -78,6 +78,11 @@ class MSSQLDatabase extends Database
|
|||||||
*/
|
*/
|
||||||
protected $fullTextEnabled = null;
|
protected $fullTextEnabled = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $transactionNesting = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the default collation of the MSSQL nvarchar fields that we create.
|
* Set the default collation of the MSSQL nvarchar fields that we create.
|
||||||
* We don't apply this to the database as a whole, so that we can use unicode collations.
|
* We don't apply this to the database as a whole, so that we can use unicode collations.
|
||||||
@ -453,11 +458,14 @@ class MSSQLDatabase extends Database
|
|||||||
*/
|
*/
|
||||||
public function transactionStart($transactionMode = false, $sessionCharacteristics = false)
|
public function transactionStart($transactionMode = false, $sessionCharacteristics = false)
|
||||||
{
|
{
|
||||||
if ($this->connector instanceof SQLServerConnector) {
|
if ($this->transactionNesting > 0) {
|
||||||
|
$this->transactionSavepoint('NESTEDTRANSACTION' . $this->transactionNesting);
|
||||||
|
} elseif ($this->connector instanceof SQLServerConnector) {
|
||||||
$this->connector->transactionStart();
|
$this->connector->transactionStart();
|
||||||
} else {
|
} else {
|
||||||
$this->query('BEGIN TRANSACTION');
|
$this->query('BEGIN TRANSACTION');
|
||||||
}
|
}
|
||||||
|
++$this->transactionNesting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transactionSavepoint($savepoint)
|
public function transactionSavepoint($savepoint)
|
||||||
@ -469,19 +477,28 @@ class MSSQLDatabase extends Database
|
|||||||
{
|
{
|
||||||
if ($savepoint) {
|
if ($savepoint) {
|
||||||
$this->query("ROLLBACK TRANSACTION \"$savepoint\"");
|
$this->query("ROLLBACK TRANSACTION \"$savepoint\"");
|
||||||
} elseif ($this->connector instanceof SQLServerConnector) {
|
|
||||||
$this->connector->transactionRollback();
|
|
||||||
} else {
|
} else {
|
||||||
$this->query('ROLLBACK TRANSACTION');
|
--$this->transactionNesting;
|
||||||
|
if ($this->transactionNesting > 0) {
|
||||||
|
$this->transactionRollback('NESTEDTRANSACTION' . $this->transactionNesting);
|
||||||
|
} elseif ($this->connector instanceof SQLServerConnector) {
|
||||||
|
$this->connector->transactionRollback();
|
||||||
|
} else {
|
||||||
|
$this->query('ROLLBACK TRANSACTION');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transactionEnd($chain = false)
|
public function transactionEnd($chain = false)
|
||||||
{
|
{
|
||||||
if ($this->connector instanceof SQLServerConnector) {
|
--$this->transactionNesting;
|
||||||
$this->connector->transactionEnd();
|
if ($this->transactionNesting <= 0) {
|
||||||
} else {
|
$this->transactionNesting = 0;
|
||||||
$this->query('COMMIT TRANSACTION');
|
if ($this->connector instanceof SQLServerConnector) {
|
||||||
|
$this->connector->transactionEnd();
|
||||||
|
} else {
|
||||||
|
$this->query('COMMIT TRANSACTION');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user