Browse Source

fix cloning of DB connection for sqlite in-memory db

fixes #14131
close #14232
tags/2.0.12
Carsten Brandt 7 years ago
parent
commit
6e7ea782c0
No known key found for this signature in database
GPG Key ID: BE4F41DE1DEEEED0
  1. 5
      framework/db/Connection.php
  2. 21
      tests/framework/db/ConnectionTest.php

5
framework/db/Connection.php

@ -1090,8 +1090,11 @@ class Connection extends Component
$this->_master = false;
$this->_slave = false;
$this->pdo = null;
$this->_schema = null;
$this->_transaction = null;
if (strncmp($this->dsn, 'sqlite::memory:', 15) !== 0) {
// reset PDO connection, unless its sqlite in-memory, which can only have one connection
$this->pdo = null;
}
}
}

21
tests/framework/db/ConnectionTest.php

@ -351,7 +351,12 @@ abstract class ConnectionTest extends DatabaseTestCase
$this->assertNotNull($connection->pdo);
$this->assertNull($conn2->transaction);
$this->assertNull($conn2->pdo);
if ($this->driverName === 'sqlite') {
// in-memory sqlite should not reset PDO
$this->assertNotNull($conn2->pdo);
} else {
$this->assertNull($conn2->pdo);
}
$connection->beginTransaction();
@ -359,13 +364,23 @@ abstract class ConnectionTest extends DatabaseTestCase
$this->assertNotNull($connection->pdo);
$this->assertNull($conn2->transaction);
$this->assertNull($conn2->pdo);
if ($this->driverName === 'sqlite') {
// in-memory sqlite should not reset PDO
$this->assertNotNull($conn2->pdo);
} else {
$this->assertNull($conn2->pdo);
}
$conn3 = clone $connection;
$this->assertNotNull($connection->transaction);
$this->assertNotNull($connection->pdo);
$this->assertNull($conn3->transaction);
$this->assertNull($conn3->pdo);
if ($this->driverName === 'sqlite') {
// in-memory sqlite should not reset PDO
$this->assertNotNull($conn3->pdo);
} else {
$this->assertNull($conn3->pdo);
}
}
}

Loading…
Cancel
Save