Skip to content

Commit

Permalink
Merge pull request #4167 from morozov/remove-wrapper-query-exec
Browse files Browse the repository at this point in the history
Remove deprecated methods from the wrapper Connection
  • Loading branch information
morozov authored Jul 21, 2020
2 parents 5ceeed8 + ea020aa commit 4d17281
Show file tree
Hide file tree
Showing 34 changed files with 107 additions and 286 deletions.
10 changes: 8 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Upgrade to 3.0

## BC BREAK: removed wrapper `Connection` methods

The following methods of the `Connection` class have been removed:

1. `query()`.
2. `exec()`.
3. `executeUpdate()`.

## BC BREAK: Changes in the wrapper-level API ancestry

The wrapper-level `Connection` and `Statement` classes no longer implement the corresponding driver-level interfaces.
Expand Down Expand Up @@ -50,8 +58,6 @@ The following classes have been renamed:
The following driver-level methods are allowed to throw a Driver\Exception:

- `Connection::prepare()`
- `Connection::query()`
- `Connection::exec()`
- `Connection::lastInsertId()`
- `Connection::beginTransaction()`
- `Connection::commit()`
Expand Down
2 changes: 1 addition & 1 deletion ci/continuousphp/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
'user' => 'ORACLE',
'password' => 'ORACLE',
'dbname' => 'XE',
])->query('ALTER USER ORACLE IDENTIFIED BY ORACLE');
])->executeStatement('ALTER USER ORACLE IDENTIFIED BY ORACLE');
})();
74 changes: 3 additions & 71 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Exception\ConnectionLost;
Expand Down Expand Up @@ -1028,48 +1027,6 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc
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
* and returns the number of affected rows.
*
* @deprecated Use {@link executeStatement()} instead.
*
* @param string $query The SQL query.
* @param array<mixed> $params The query parameters.
* @param array<int|string|null> $types The parameter types.
*
* @throws DBALException
*/
public function executeUpdate(string $query, array $params = [], array $types = []): int
{
return $this->executeStatement($query, $params, $types);
}

/**
* Executes an SQL statement with the given parameters and returns the number of affected rows.
*
Expand Down Expand Up @@ -1126,31 +1083,6 @@ public function executeStatement($sql, array $params = [], array $types = [])
}
}

/**
* @deprecated Use {@link executeStatement()} instead.
*
* @throws DBALException
*/
public function exec(string $statement): int
{
$connection = $this->getWrappedConnection();

$logger = $this->_config->getSQLLogger();
if ($logger !== null) {
$logger->startQuery($statement);
}

try {
return $connection->exec($statement);
} catch (DriverException $e) {
throw $this->convertExceptionDuringQuery($e, $statement);
} finally {
if ($logger !== null) {
$logger->stopQuery();
}
}
}

/**
* Returns the current transaction nesting level.
*
Expand Down Expand Up @@ -1436,7 +1368,7 @@ public function createSavepoint($savepoint)
throw ConnectionException::savepointsNotSupported();
}

$this->executeUpdate($this->platform->createSavePoint($savepoint));
$this->executeStatement($this->platform->createSavePoint($savepoint));
}

/**
Expand All @@ -1458,7 +1390,7 @@ public function releaseSavepoint($savepoint)
return;
}

$this->executeUpdate($this->platform->releaseSavePoint($savepoint));
$this->executeStatement($this->platform->releaseSavePoint($savepoint));
}

/**
Expand All @@ -1476,7 +1408,7 @@ public function rollbackSavepoint($savepoint)
throw ConnectionException::savepointsNotSupported();
}

$this->executeUpdate($this->platform->rollbackSavePoint($savepoint));
$this->executeStatement($this->platform->rollbackSavePoint($savepoint));
}

/**
Expand Down
78 changes: 2 additions & 76 deletions src/Connections/PrimaryReadReplicaConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Statement;
use InvalidArgumentException;

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

/**
* Primary-Replica Connection
Expand All @@ -30,9 +27,8 @@
*
* 1. Replica if primary was never picked before and ONLY if 'getWrappedConnection'
* or 'executeQuery' is used.
* 2. Primary picked when 'exec', 'executeUpdate', 'executeStatement', 'insert', 'delete', 'update', 'createSavepoint',
* 'releaseSavepoint', 'beginTransaction', 'rollback', 'commit', 'query' or
* 'prepare' is called.
* 2. Primary picked when 'executeStatement', 'insert', 'delete', 'update', 'createSavepoint',
* 'releaseSavepoint', 'beginTransaction', 'rollback', 'commit' or 'prepare' is called.
* 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.
*
Expand Down Expand Up @@ -260,18 +256,6 @@ protected function chooseConnectionConfiguration($connectionName, $params)
return $config;
}

/**
* {@inheritDoc}
*
* @deprecated Use {@link executeStatement()} instead.
*/
public function executeUpdate(string $query, array $params = [], array $types = []): int
{
$this->ensureConnectedToPrimary();

return parent::executeUpdate($query, $params, $types);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -312,16 +296,6 @@ public function rollBack()
return parent::rollBack();
}

/**
* {@inheritDoc}
*/
public function delete($tableName, array $identifier, array $types = [])
{
$this->ensureConnectedToPrimary();

return parent::delete($tableName, $identifier, $types);
}

/**
* {@inheritDoc}
*/
Expand All @@ -335,33 +309,6 @@ public function close()
$this->connections = ['primary' => null, 'replica' => null];
}

/**
* {@inheritDoc}
*/
public function update($tableName, array $data, array $identifier, array $types = [])
{
$this->ensureConnectedToPrimary();

return parent::update($tableName, $data, $identifier, $types);
}

/**
* {@inheritDoc}
*/
public function insert($tableName, array $data, array $types = [])
{
$this->ensureConnectedToPrimary();

return parent::insert($tableName, $data, $types);
}

public function exec(string $statement): int
{
$this->ensureConnectedToPrimary();

return parent::exec($statement);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -392,27 +339,6 @@ public function 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
{
$this->ensureConnectedToPrimary();
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Listeners/SQLSessionInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct($sql)
*/
public function postConnect(ConnectionEventArgs $args)
{
$args->getConnection()->executeUpdate($this->sql);
$args->getConnection()->executeStatement($this->sql);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function alterTable(TableDiff $tableDiff)
foreach ($tableDiff->removedColumns as $col) {
$columnConstraintSql = $this->getColumnConstraintSQL($tableDiff->name, $col->getName());
foreach ($this->_conn->fetchAllAssociative($columnConstraintSql) as $constraint) {
$this->_conn->exec(
$this->_conn->executeStatement(
sprintf(
'ALTER TABLE %s DROP CONSTRAINT %s',
$tableDiff->name,
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/Synchronizer/AbstractSchemaSynchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function processSqlSafely(array $sql)
{
foreach ($sql as $s) {
try {
$this->conn->exec($s);
$this->conn->executeStatement($s);
} catch (Throwable $e) {
}
}
Expand All @@ -44,7 +44,7 @@ protected function processSqlSafely(array $sql)
protected function processSql(array $sql)
{
foreach ($sql as $s) {
$this->conn->exec($s);
$this->conn->executeStatement($s);
}
}
}
12 changes: 0 additions & 12 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,6 @@ public function testDriverExceptionIsWrapped(callable $callback): void
*/
public static function getQueryMethods(): iterable
{
yield 'exec' => [
static function (Connection $connection, string $statement): void {
$connection->exec($statement);
},
];

yield 'query' => [
static function (Connection $connection, string $statement): void {
$connection->query($statement);
},
];

yield 'executeQuery' => [
static function (Connection $connection, string $statement): void {
$connection->executeQuery($statement);
Expand Down
2 changes: 1 addition & 1 deletion tests/Events/SQLSessionInitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testPostConnect(): void
{
$connectionMock = $this->createMock(Connection::class);
$connectionMock->expects(self::once())
->method('executeUpdate')
->method('executeStatement')
->with(self::equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'"));

$eventArgs = new ConnectionEventArgs($connectionMock);
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function testBindParamProcessesStream(): void

private function assertBlobContains(string $text): void
{
$rows = $this->connection->query('SELECT blobfield FROM blob_table')->fetchFirstColumn();
$rows = $this->connection->fetchFirstColumn('SELECT blobfield FROM blob_table');

self::assertCount(1, $rows);

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Connection/ConnectionLostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function tearDown(): void

public function testConnectionLost(): void
{
$this->connection->query('SET SESSION wait_timeout=1');
$this->connection->executeStatement('SET SESSION wait_timeout=1');

sleep(2);

Expand Down
7 changes: 3 additions & 4 deletions tests/Functional/DataAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public function testQuoteSQLInjection(): void
*/
public function testBitComparisonExpressionSupport(): void
{
$this->connection->exec('DELETE FROM fetch_table');
$this->connection->executeStatement('DELETE FROM fetch_table');
$platform = $this->connection->getDatabasePlatform();
$bitmap = [];

Expand Down Expand Up @@ -601,7 +601,7 @@ public function testFetchAllStyleColumn(): void
$this->connection->insert('fetch_table', ['test_int' => 10, 'test_string' => 'foo']);

$sql = 'SELECT test_int FROM fetch_table';
$values = $this->connection->query($sql)->fetchFirstColumn();
$values = $this->connection->fetchFirstColumn($sql);

self::assertEquals([1, 10], $values);
}
Expand All @@ -612,9 +612,8 @@ public function testFetchAllStyleColumn(): void
public function testEmptyFetchOneReturnsFalse(): void
{
$this->connection->beginTransaction();
$this->connection->exec('DELETE FROM fetch_table');
$this->connection->executeStatement('DELETE 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();
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Functional/Driver/PDO/PgSQL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function testConnectsWithValidCharsetOption(string $charset): void

self::assertEquals(
$charset,
$connection->query('SHOW client_encoding')
->fetchOne()
$connection->fetchOne('SHOW client_encoding')
);
}

Expand Down
Loading

0 comments on commit 4d17281

Please sign in to comment.