Remove Connection::query()

parent 3c07b4ad
# Upgrade to 3.0 # Upgrade to 3.0
## BC BREAK: removed wrapper `Connection` methods
The following methods of the `Connection` class have been removed:
1. `query()`.
## BC BREAK: Changes in the wrapper-level API ancestry ## BC BREAK: Changes in the wrapper-level API ancestry
The wrapper-level `Connection` and `Statement` classes no longer implement the corresponding driver-level interfaces. The wrapper-level `Connection` and `Statement` classes no longer implement the corresponding driver-level interfaces.
...@@ -50,7 +56,6 @@ The following classes have been renamed: ...@@ -50,7 +56,6 @@ The following classes have been renamed:
The following driver-level methods are allowed to throw a Driver\Exception: The following driver-level methods are allowed to throw a Driver\Exception:
- `Connection::prepare()` - `Connection::prepare()`
- `Connection::query()`
- `Connection::exec()` - `Connection::exec()`
- `Connection::lastInsertId()` - `Connection::lastInsertId()`
- `Connection::beginTransaction()` - `Connection::beginTransaction()`
......
...@@ -12,7 +12,6 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; ...@@ -12,7 +12,6 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Driver\API\ExceptionConverter; use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception as DriverException; use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Exception\ConnectionLost; use Doctrine\DBAL\Exception\ConnectionLost;
...@@ -1028,31 +1027,6 @@ class Connection ...@@ -1028,31 +1027,6 @@ class Connection
return new Result($result, $this); return new Result($result, $this);
} }
/**
* @deprecated Use {@link executeQuery()} instead.
*
* @throws DBALException
*/
public function query(string $sql): DriverResult
{
$connection = $this->getWrappedConnection();
$logger = $this->_config->getSQLLogger();
if ($logger !== null) {
$logger->startQuery($sql);
}
try {
return $connection->query($sql);
} catch (DriverException $e) {
throw $this->convertExceptionDuringQuery($e, $sql);
} finally {
if ($logger !== null) {
$logger->stopQuery();
}
}
}
/** /**
* Executes an SQL INSERT/UPDATE/DELETE query with the given parameters * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters
* and returns the number of affected rows. * and returns the number of affected rows.
......
...@@ -9,16 +9,13 @@ use Doctrine\DBAL\DBALException; ...@@ -9,16 +9,13 @@ use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception as DriverException; use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\DBAL\Statement; use Doctrine\DBAL\Statement;
use InvalidArgumentException; use InvalidArgumentException;
use function array_rand; use function array_rand;
use function assert;
use function count; use function count;
use function func_get_args;
/** /**
* Primary-Replica Connection * Primary-Replica Connection
...@@ -31,8 +28,7 @@ use function func_get_args; ...@@ -31,8 +28,7 @@ use function func_get_args;
* 1. Replica if primary was never picked before and ONLY if 'getWrappedConnection' * 1. Replica if primary was never picked before and ONLY if 'getWrappedConnection'
* or 'executeQuery' is used. * or 'executeQuery' is used.
* 2. Primary picked when 'exec', 'executeUpdate', 'executeStatement', 'insert', 'delete', 'update', 'createSavepoint', * 2. Primary picked when 'exec', 'executeUpdate', 'executeStatement', 'insert', 'delete', 'update', 'createSavepoint',
* 'releaseSavepoint', 'beginTransaction', 'rollback', 'commit', 'query' or * 'releaseSavepoint', 'beginTransaction', 'rollback', 'commit' or 'prepare' is called.
* 'prepare' is called.
* 3. If Primary was picked once during the lifetime of the connection it will always get picked afterwards. * 3. If Primary was picked once during the lifetime of the connection it will always get picked afterwards.
* 4. One replica connection is randomly picked ONCE during a request. * 4. One replica connection is randomly picked ONCE during a request.
* *
...@@ -392,27 +388,6 @@ class PrimaryReadReplicaConnection extends Connection ...@@ -392,27 +388,6 @@ class PrimaryReadReplicaConnection extends Connection
parent::rollbackSavepoint($savepoint); parent::rollbackSavepoint($savepoint);
} }
public function query(string $sql): Result
{
$this->ensureConnectedToPrimary();
assert($this->_conn instanceof DriverConnection);
$args = func_get_args();
$logger = $this->getConfiguration()->getSQLLogger();
if ($logger !== null) {
$logger->startQuery($sql);
}
$statement = $this->_conn->query($sql);
if ($logger !== null) {
$logger->stopQuery();
}
return $statement;
}
public function prepare(string $sql): Statement public function prepare(string $sql): Statement
{ {
$this->ensureConnectedToPrimary(); $this->ensureConnectedToPrimary();
......
...@@ -180,12 +180,6 @@ class ConnectionTest extends TestCase ...@@ -180,12 +180,6 @@ class ConnectionTest extends TestCase
}, },
]; ];
yield 'query' => [
static function (Connection $connection, string $statement): void {
$connection->query($statement);
},
];
yield 'executeQuery' => [ yield 'executeQuery' => [
static function (Connection $connection, string $statement): void { static function (Connection $connection, string $statement): void {
$connection->executeQuery($statement); $connection->executeQuery($statement);
......
...@@ -614,7 +614,6 @@ class DataAccessTest extends FunctionalTestCase ...@@ -614,7 +614,6 @@ class DataAccessTest extends FunctionalTestCase
$this->connection->beginTransaction(); $this->connection->beginTransaction();
$this->connection->exec('DELETE FROM fetch_table'); $this->connection->exec('DELETE FROM fetch_table');
self::assertFalse($this->connection->fetchOne('SELECT test_int FROM fetch_table')); self::assertFalse($this->connection->fetchOne('SELECT test_int FROM fetch_table'));
self::assertFalse($this->connection->query('SELECT test_int FROM fetch_table')->fetchOne());
$this->connection->rollBack(); $this->connection->rollBack();
} }
......
...@@ -189,48 +189,4 @@ class PrimaryReadReplicaConnectionTest extends FunctionalTestCase ...@@ -189,48 +189,4 @@ class PrimaryReadReplicaConnectionTest extends FunctionalTestCase
$conn->ensureConnectedToPrimary(); $conn->ensureConnectedToPrimary();
self::assertTrue($conn->isConnectedToPrimary()); self::assertTrue($conn->isConnectedToPrimary());
} }
public function testQueryOnPrimary(): void
{
$conn = $this->createPrimaryReadReplicaConnection();
$query = 'SELECT count(*) as num FROM primary_replica_table';
$result = $conn->query($query);
//Query must be executed only on Primary
self::assertTrue($conn->isConnectedToPrimary());
$data = $result->fetchAllAssociative();
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 testQueryOnReplica(): void
{
$conn = $this->createPrimaryReadReplicaConnection();
$conn->ensureConnectedToReplica();
$query = 'SELECT count(*) as num FROM primary_replica_table';
$result = $conn->query($query);
//Query must be executed only on Primary, even when we connect to the replica
self::assertTrue($conn->isConnectedToPrimary());
$data = $result->fetchAllAssociative();
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