mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
Merge pull request #54 from dhensby/pulls/transaction-fixes
FIX Make sure nested transactions get reset on implicit commits
This commit is contained in:
commit
34fb10580a
@ -475,9 +475,16 @@ class MSSQLDatabase extends Database
|
||||
|
||||
public function transactionRollback($savepoint = false)
|
||||
{
|
||||
// Named transaction
|
||||
if ($savepoint) {
|
||||
$this->query("ROLLBACK TRANSACTION \"$savepoint\"");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fail if transaction isn't available
|
||||
if (!$this->transactionNesting) {
|
||||
return false;
|
||||
}
|
||||
--$this->transactionNesting;
|
||||
if ($this->transactionNesting > 0) {
|
||||
$this->transactionRollback('NESTEDTRANSACTION' . $this->transactionNesting);
|
||||
@ -486,11 +493,15 @@ class MSSQLDatabase extends Database
|
||||
} else {
|
||||
$this->query('ROLLBACK TRANSACTION');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function transactionEnd($chain = false)
|
||||
{
|
||||
// Fail if transaction isn't available
|
||||
if (!$this->transactionNesting) {
|
||||
return false;
|
||||
}
|
||||
--$this->transactionNesting;
|
||||
if ($this->transactionNesting <= 0) {
|
||||
$this->transactionNesting = 0;
|
||||
@ -500,6 +511,36 @@ class MSSQLDatabase extends Database
|
||||
$this->query('COMMIT TRANSACTION');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* In error condition, set transactionNesting to zero
|
||||
*/
|
||||
protected function resetTransactionNesting()
|
||||
{
|
||||
$this->transactionNesting = 0;
|
||||
}
|
||||
|
||||
public function query($sql, $errorLevel = E_USER_ERROR)
|
||||
{
|
||||
$this->inspectQuery($sql);
|
||||
return parent::query($sql, $errorLevel);
|
||||
}
|
||||
|
||||
public function preparedQuery($sql, $parameters, $errorLevel = E_USER_ERROR)
|
||||
{
|
||||
$this->inspectQuery($sql);
|
||||
return parent::preparedQuery($sql, $parameters, $errorLevel);
|
||||
}
|
||||
|
||||
protected function inspectQuery($sql)
|
||||
{
|
||||
// Any DDL discards transactions.
|
||||
$isDDL = $this->getConnector()->isQueryDDL($sql);
|
||||
if ($isDDL) {
|
||||
$this->resetTransactionNesting();
|
||||
}
|
||||
}
|
||||
|
||||
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, $parameterised = false)
|
||||
|
Loading…
Reference in New Issue
Block a user