From 6e7ea782c0e4924540f7929dfef7bf78f8abab4d Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 31 May 2017 14:46:27 +0200 Subject: [PATCH] fix cloning of DB connection for sqlite in-memory db fixes #14131 close #14232 --- framework/db/Connection.php | 5 ++++- tests/framework/db/ConnectionTest.php | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/framework/db/Connection.php b/framework/db/Connection.php index 7531644..a75c80a 100644 --- a/framework/db/Connection.php +++ b/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; + } } } diff --git a/tests/framework/db/ConnectionTest.php b/tests/framework/db/ConnectionTest.php index 7d6a112..772ce09 100644 --- a/tests/framework/db/ConnectionTest.php +++ b/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); + } } }