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,21 +477,30 @@ class MSSQLDatabase extends Database
|
|||||||
{
|
{
|
||||||
if ($savepoint) {
|
if ($savepoint) {
|
||||||
$this->query("ROLLBACK TRANSACTION \"$savepoint\"");
|
$this->query("ROLLBACK TRANSACTION \"$savepoint\"");
|
||||||
|
} else {
|
||||||
|
--$this->transactionNesting;
|
||||||
|
if ($this->transactionNesting > 0) {
|
||||||
|
$this->transactionRollback('NESTEDTRANSACTION' . $this->transactionNesting);
|
||||||
} elseif ($this->connector instanceof SQLServerConnector) {
|
} elseif ($this->connector instanceof SQLServerConnector) {
|
||||||
$this->connector->transactionRollback();
|
$this->connector->transactionRollback();
|
||||||
} else {
|
} else {
|
||||||
$this->query('ROLLBACK TRANSACTION');
|
$this->query('ROLLBACK TRANSACTION');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function transactionEnd($chain = false)
|
public function transactionEnd($chain = false)
|
||||||
{
|
{
|
||||||
|
--$this->transactionNesting;
|
||||||
|
if ($this->transactionNesting <= 0) {
|
||||||
|
$this->transactionNesting = 0;
|
||||||
if ($this->connector instanceof SQLServerConnector) {
|
if ($this->connector instanceof SQLServerConnector) {
|
||||||
$this->connector->transactionEnd();
|
$this->connector->transactionEnd();
|
||||||
} else {
|
} else {
|
||||||
$this->query('COMMIT TRANSACTION');
|
$this->query('COMMIT TRANSACTION');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false)
|
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user