8000 MasterSlaveConnection::query() throws driver-specific exceptions (e.g. PDOException etc) by supersmile2009 · Pull Request #4248 · doctrine/dbal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MasterSlaveConnection::query() throws driver-specific exceptions (e.g. PDOException etc) #4248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use InvalidArgumentException;

use function array_rand;
use function assert;
use function count;
use function func_get_args;

Expand Down Expand Up @@ -354,24 +353,8 @@ public function rollbackSavepoint($savepoint)
public function query()
{
$this->connect('master');
assert($this->_conn instanceof DriverConnection);

$args = func_get_args();

$logger = $this->getConfiguration()->getSQLLogger();
if ($logger) {
$logger->startQuery($args[0]);
}

$statement = $this->_conn->query(...$args);

$statement->setFetchMode($this->defaultFetchMode);

if ($logger) {
$logger->stopQuery();
}

return $statement;
return parent::query(...func_get_args());
}

/**
Expand Down
55 changes: 55 additions & 0 deletions tests/Doctrine/Tests/DBAL/Connection/MasterSlaveConnectionTest.php
6EBA
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\DBAL\Connection;

use Doctrine\DBAL\Connections\MasterSlaveConnection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\DriverManager;
use Doctrine\Tests\DbalTestCase;

class MasterSlaveConnectionTest extends DbalTestCase
{
/**
* @return array<int, array<int, mixed>>
*/
public static function getQueryMethods(): iterable
{
return [
['exec'],
['query'],
['executeQuery'],
['executeUpdate'],
['prepare'],
];
}

/**
* @requires extension pdo_sqlite
* @dataProvider getQueryMethods
*/
public function testDriverExceptionIsWrapped(string $method): void
{
$this->expectException(DBALException::class);
$this->expectExceptionMessage(
<<<EOF
An exception occurred while executing 'MUUHAAAAHAAAA':

SQLSTATE[HY000]: General error: 1 near "MUUHAAAAHAAAA"
EOF
);

$connection = DriverManager::getConnection(
[
'wrapperClass' => MasterSlaveConnection::class,
'memory' => true,
'driver' => 'pdo_sqlite',
'master' => [],
'slaves' => ['slave1' => ['driver' => 'pdo_sqlite']],
]
);

$connection->$method('MUUHAAAAHAAAA');
}
}
0