Unverified Commit 125fb5e7 authored by Sergei Morozov's avatar Sergei Morozov

Merge branch 'bpo/2.9/#3305' into 2.9

parents f9a03ad5 f6dd1344
...@@ -354,6 +354,8 @@ class MasterSlaveConnection extends Connection ...@@ -354,6 +354,8 @@ class MasterSlaveConnection extends Connection
$statement = $this->_conn->query(...$args); $statement = $this->_conn->query(...$args);
$statement->setFetchMode($this->defaultFetchMode);
if ($logger) { if ($logger) {
$logger->stopQuery(); $logger->stopQuery();
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional; namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Connections\MasterSlaveConnection; use Doctrine\DBAL\Connections\MasterSlaveConnection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\DbalFunctionalTestCase;
...@@ -187,4 +188,54 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase ...@@ -187,4 +188,54 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
$conn->connect('master'); $conn->connect('master');
self::assertTrue($conn->isConnectedToMaster()); self::assertTrue($conn->isConnectedToMaster());
} }
public function testQueryOnMaster()
{
$conn = $this->createMasterSlaveConnection();
$query = 'SELECT count(*) as num FROM master_slave_table';
$statement = $conn->query($query);
self::assertInstanceOf(Statement::class, $statement);
//Query must be executed only on Master
self::assertTrue($conn->isConnectedToMaster());
$data = $statement->fetchAll();
//Default fetchmode is FetchMode::ASSOCIATIVE
self::assertArrayHasKey(0, $data);
self::assertArrayHasKey('num', $data[0]);
//Could be set in other fetchmodes
self::assertArrayNotHasKey(0, $data[0]);
self::assertEquals(1, $data[0]['num']);
}
public function testQueryOnSlave()
{
$conn = $this->createMasterSlaveConnection();
$conn->connect('slave');
$query = 'SELECT count(*) as num FROM master_slave_table';
$statement = $conn->query($query);
self::assertInstanceOf(Statement::class, $statement);
//Query must be executed only on Master, even when we connect to the slave
self::assertTrue($conn->isConnectedToMaster());
$data = $statement->fetchAll();
//Default fetchmode is FetchMode::ASSOCIATIVE
self::assertArrayHasKey(0, $data);
self::assertArrayHasKey('num', $data[0]);
//Could be set in other fetchmodes
self::assertArrayNotHasKey(0, $data[0]);
self::assertEquals(1, $data[0]['num']);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment