Skip to content

Commit

Permalink
fix cloning of DB connection for sqlite in-memory db
Browse files Browse the repository at this point in the history
fixes #14131
close #14232
  • Loading branch information
cebe committed Jun 1, 2017
1 parent 67b9a57 commit 6e7ea78
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion framework/db/Connection.php
Expand Up @@ -1090,8 +1090,11 @@ public function __clone()

$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 changes: 18 additions & 3 deletions tests/framework/db/ConnectionTest.php
Expand Up @@ -351,21 +351,36 @@ public function testClone()
$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();

$this->assertNotNull($connection->transaction);
$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);
}
}
}

0 comments on commit 6e7ea78

Please sign in to comment.