Skip to content

Commit

Permalink
always use nested transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Oct 2, 2023
1 parent 5a555f8 commit 5ec6236
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1640,16 +1640,16 @@ public function insert(array $row)
{
$entity = $this->createEntity();

$hasArrayValue = false;
$hasRefs = false;
foreach ($row as $v) {
if (is_array($v)) {
$hasArrayValue = true;
$hasRefs = true;

break;
}
}

if (!$hasArrayValue) {
if (!$hasRefs) {
$entity->_insert($row);
} else {
$this->atomic(static function () use ($entity, $row) {
Expand Down
2 changes: 2 additions & 0 deletions src/Persistence/Sql/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public static function connect($dsn, $user = null, $password = null, $defaults =
$dbalConnection = $connectionClass::connectFromDbalDriverConnection($dbalDriverConnection);
}

$dbalConnection->setNestTransactionsWithSavepoints(true); // remove once DBAL 3.x support is dropped

$connection = new $connectionClass($defaults);
$connection->_connection = $dbalConnection;

Expand Down
7 changes: 5 additions & 2 deletions tests/Schema/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function testLogQuery(): void
"START TRANSACTION";
"SAVEPOINT";
insert into `t` (`name`, `int`, `float`, `null`)
values
(
Expand Down Expand Up @@ -86,9 +89,9 @@ public function testLogQuery(): void
and `id` = 1
EOF
. $makeLimitSqlFx(2)
. ";\n\n"
. ($this->getDatabasePlatform()->supportsReleaseSavepoints() ? "\n\"RELEASE SAVEPOINT\";\n\n" : '')
. <<<'EOF'
;
"COMMIT";
Expand Down
2 changes: 0 additions & 2 deletions tests/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public function testAtomicWithRollbackToSavepoint(): void
$m->addField('name');
$m->setOrder('id');

$this->getConnection()->getConnection()->setNestTransactionsWithSavepoints(true);

$this->db->atomic(function () use ($m) {
foreach ($m as $entity) {
$rollback = $entity->get('name') === 'Sue';
Expand Down

0 comments on commit 5ec6236

Please sign in to comment.