From 2d6967f062c7bab83d963e2f6e45ac594269f458 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 10 Jul 2020 08:35:19 -0700 Subject: [PATCH 1/6] Replace $conn->query()->fetch*() with $conn->fetch*() --- tests/Functional/BlobTest.php | 2 +- tests/Functional/DataAccessTest.php | 2 +- tests/Functional/Driver/PDO/PgSQL/ConnectionTest.php | 3 +-- tests/Functional/Platform/DateExpressionTest.php | 2 +- tests/Functional/Platform/DefaultExpressionTest.php | 4 ++-- tests/Functional/PortabilityTest.php | 3 +-- .../Schema/SchemaManagerFunctionalTestCase.php | 12 ++++++------ tests/Functional/Schema/SqliteSchemaManagerTest.php | 6 +++--- tests/Functional/Ticket/DBAL202Test.php | 4 ++-- tests/Functional/WriteTest.php | 5 +++-- 10 files changed, 21 insertions(+), 22 deletions(-) diff --git a/tests/Functional/BlobTest.php b/tests/Functional/BlobTest.php index 0248b8d9912..8b50d084202 100644 --- a/tests/Functional/BlobTest.php +++ b/tests/Functional/BlobTest.php @@ -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); diff --git a/tests/Functional/DataAccessTest.php b/tests/Functional/DataAccessTest.php index 38d5d032527..824ea61f8e1 100644 --- a/tests/Functional/DataAccessTest.php +++ b/tests/Functional/DataAccessTest.php @@ -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); } diff --git a/tests/Functional/Driver/PDO/PgSQL/ConnectionTest.php b/tests/Functional/Driver/PDO/PgSQL/ConnectionTest.php index 6164c7ec907..c846d5ab5e9 100644 --- a/tests/Functional/Driver/PDO/PgSQL/ConnectionTest.php +++ b/tests/Functional/Driver/PDO/PgSQL/ConnectionTest.php @@ -40,8 +40,7 @@ public function testConnectsWithValidCharsetOption(string $charset): void self::assertEquals( $charset, - $connection->query('SHOW client_encoding') - ->fetchOne() + $connection->fetchOne('SHOW client_encoding') ); } diff --git a/tests/Functional/Platform/DateExpressionTest.php b/tests/Functional/Platform/DateExpressionTest.php index aacfaa9d38b..4f3fc3d8e14 100644 --- a/tests/Functional/Platform/DateExpressionTest.php +++ b/tests/Functional/Platform/DateExpressionTest.php @@ -27,7 +27,7 @@ public function testDifference(string $date1, string $date2, int $expected): voi $platform = $this->connection->getDatabasePlatform(); $sql = sprintf('SELECT %s FROM date_expr_test', $platform->getDateDiffExpression('date1', 'date2')); - $diff = $this->connection->query($sql)->fetchOne(); + $diff = $this->connection->fetchOne($sql); self::assertEquals($expected, $diff); } diff --git a/tests/Functional/Platform/DefaultExpressionTest.php b/tests/Functional/Platform/DefaultExpressionTest.php index 9a7eeb75937..510fc0cbd6a 100644 --- a/tests/Functional/Platform/DefaultExpressionTest.php +++ b/tests/Functional/Platform/DefaultExpressionTest.php @@ -69,9 +69,9 @@ private function assertDefaultExpression(string $type, callable $expression): vo ) ); - [$actualValue, $defaultValue] = $this->connection->query( + [$actualValue, $defaultValue] = $this->connection->fetchNumeric( 'SELECT default_value, actual_value FROM default_expr_test' - )->fetchNumeric(); + ); self::assertEquals($actualValue, $defaultValue); } diff --git a/tests/Functional/PortabilityTest.php b/tests/Functional/PortabilityTest.php index 3679cb79c8f..4a08ae38aa5 100644 --- a/tests/Functional/PortabilityTest.php +++ b/tests/Functional/PortabilityTest.php @@ -145,9 +145,8 @@ public static function fetchColumnProvider(): iterable public function testFetchAllNullColumn(): void { - $result = $this->connection->query('SELECT Test_Null FROM portability_table'); + $column = $this->connection->fetchFirstColumn('SELECT Test_Null FROM portability_table'); - $column = $result->fetchFirstColumn(); self::assertSame([null, null], $column); } } diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index a2b9fdd9c6e..669f339fdeb 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1440,17 +1440,17 @@ public function testPrimaryKeyAutoIncrement(): void $this->connection->insert('test_pk_auto_increment', ['text' => '1']); - $result = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'1\''); - - $lastUsedIdBeforeDelete = (int) $result->fetchOne(); + $lastUsedIdBeforeDelete = (int) $this->connection->fetchOne( + "SELECT id FROM test_pk_auto_increment WHERE text = '1'" + ); $this->connection->query('DELETE FROM test_pk_auto_increment'); $this->connection->insert('test_pk_auto_increment', ['text' => '2']); - $result = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'2\''); - - $lastUsedIdAfterDelete = (int) $result->fetchOne(); + $lastUsedIdAfterDelete = (int) $this->connection->fetchOne( + "SELECT id FROM test_pk_auto_increment WHERE text = '2'" + ); self::assertGreaterThan($lastUsedIdBeforeDelete, $lastUsedIdAfterDelete); } diff --git a/tests/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Functional/Schema/SqliteSchemaManagerTest.php index ea382f38145..7162b3b223a 100644 --- a/tests/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Functional/Schema/SqliteSchemaManagerTest.php @@ -238,9 +238,9 @@ public function testPrimaryKeyNoAutoIncrement(): void $this->connection->insert('test_pk_auto_increment', ['text' => '2']); - $result = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = "2"'); - - $lastUsedIdAfterDelete = (int) $result->fetchOne(); + $lastUsedIdAfterDelete = (int) $this->connection->fetchOne( + 'SELECT id FROM test_pk_auto_increment WHERE text = "2"' + ); // with an empty table, non autoincrement rowid is always 1 self::assertEquals(1, $lastUsedIdAfterDelete); diff --git a/tests/Functional/Ticket/DBAL202Test.php b/tests/Functional/Ticket/DBAL202Test.php index d1efd3b1db6..f84c7e75ac8 100644 --- a/tests/Functional/Ticket/DBAL202Test.php +++ b/tests/Functional/Ticket/DBAL202Test.php @@ -36,7 +36,7 @@ public function testStatementRollback(): void $stmt->execute(); $this->connection->rollBack(); - self::assertEquals(0, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchOne()); + self::assertEquals(0, $this->connection->fetchOne('SELECT COUNT(1) FROM DBAL202')); } public function testStatementCommit(): void @@ -46,6 +46,6 @@ public function testStatementCommit(): void $stmt->execute(); $this->connection->commit(); - self::assertEquals(1, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchOne()); + self::assertEquals(1, $this->connection->fetchOne('SELECT COUNT(1) FROM DBAL202')); } } diff --git a/tests/Functional/WriteTest.php b/tests/Functional/WriteTest.php index 9e88072effa..93b4175fce7 100644 --- a/tests/Functional/WriteTest.php +++ b/tests/Functional/WriteTest.php @@ -174,8 +174,9 @@ public function testLastInsertIdSequence(): void return strtolower($sequence->getName()) === 'write_table_id_seq'; })); - $result = $this->connection->query($this->connection->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq')); - $nextSequenceVal = $result->fetchOne(); + $nextSequenceVal = $this->connection->fetchOne( + $this->connection->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq') + ); $lastInsertId = $this->lastInsertId('write_table_id_seq'); From 3c07b4ad4fec79908450fb22058d6bea48e596c3 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 11 Jul 2020 15:54:01 -0700 Subject: [PATCH 2/6] Replace $conn->query() with $conn->executeQuery() and $conn->executeStatement() --- ci/continuousphp/bootstrap.php | 2 +- tests/Functional/Connection/ConnectionLostTest.php | 2 +- tests/Functional/PortabilityTest.php | 6 +++--- tests/Functional/Schema/MySqlSchemaManagerTest.php | 8 ++++---- .../Functional/Schema/SchemaManagerFunctionalTestCase.php | 2 +- tests/Functional/Schema/SqliteSchemaManagerTest.php | 2 +- tests/Functional/TransactionTest.php | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ci/continuousphp/bootstrap.php b/ci/continuousphp/bootstrap.php index 899fd6d5e16..7395d779cf4 100644 --- a/ci/continuousphp/bootstrap.php +++ b/ci/continuousphp/bootstrap.php @@ -12,5 +12,5 @@ 'user' => 'ORACLE', 'password' => 'ORACLE', 'dbname' => 'XE', - ])->query('ALTER USER ORACLE IDENTIFIED BY ORACLE'); + ])->executeStatement('ALTER USER ORACLE IDENTIFIED BY ORACLE'); })(); diff --git a/tests/Functional/Connection/ConnectionLostTest.php b/tests/Functional/Connection/ConnectionLostTest.php index 34640a9b909..14324738008 100644 --- a/tests/Functional/Connection/ConnectionLostTest.php +++ b/tests/Functional/Connection/ConnectionLostTest.php @@ -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); diff --git a/tests/Functional/PortabilityTest.php b/tests/Functional/PortabilityTest.php index 4a08ae38aa5..985738339ec 100644 --- a/tests/Functional/PortabilityTest.php +++ b/tests/Functional/PortabilityTest.php @@ -53,7 +53,7 @@ public function testFullFetchMode(): void $rows = $this->connection->fetchAllAssociative('SELECT * FROM portability_table'); $this->assertFetchResultRows($rows); - $result = $this->connection->query('SELECT * FROM portability_table'); + $result = $this->connection->executeQuery('SELECT * FROM portability_table'); while (($row = $result->fetchAssociative())) { $this->assertFetchResultRow($row); @@ -73,7 +73,7 @@ public function testConnFetchMode(): void $rows = $this->connection->fetchAllAssociative('SELECT * FROM portability_table'); $this->assertFetchResultRows($rows); - $result = $this->connection->query('SELECT * FROM portability_table'); + $result = $this->connection->executeQuery('SELECT * FROM portability_table'); while (($row = $result->fetchAssociative())) { $this->assertFetchResultRow($row); } @@ -120,7 +120,7 @@ public function assertFetchResultRow(array $row): void */ public function testFetchColumn(string $field, array $expected): void { - $result = $this->connection->query('SELECT ' . $field . ' FROM portability_table'); + $result = $this->connection->executeQuery('SELECT ' . $field . ' FROM portability_table'); $column = $result->fetchFirstColumn(); self::assertEquals($expected, $column); diff --git a/tests/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Functional/Schema/MySqlSchemaManagerTest.php index 6842e8f84dc..fc14fee4f10 100644 --- a/tests/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Functional/Schema/MySqlSchemaManagerTest.php @@ -520,7 +520,7 @@ public function testColumnDefaultValuesCurrentTimeAndDate(): void public function testEnsureTableOptionsAreReflectedInMetadata(): void { - $this->connection->query('DROP TABLE IF EXISTS test_table_metadata'); + $this->connection->executeStatement('DROP TABLE IF EXISTS test_table_metadata'); $sql = <<<'SQL' CREATE TABLE test_table_metadata( @@ -534,7 +534,7 @@ public function testEnsureTableOptionsAreReflectedInMetadata(): void PARTITION BY HASH (col1) SQL; - $this->connection->query($sql); + $this->connection->executeStatement($sql); $onlineTable = $this->schemaManager->listTableDetails('test_table_metadata'); self::assertEquals('InnoDB', $onlineTable->getOption('engine')); @@ -549,9 +549,9 @@ public function testEnsureTableOptionsAreReflectedInMetadata(): void public function testEnsureTableWithoutOptionsAreReflectedInMetadata(): void { - $this->connection->query('DROP TABLE IF EXISTS test_table_empty_metadata'); + $this->connection->executeStatement('DROP TABLE IF EXISTS test_table_empty_metadata'); - $this->connection->query('CREATE TABLE test_table_empty_metadata(col1 INT NOT NULL)'); + $this->connection->executeStatement('CREATE TABLE test_table_empty_metadata(col1 INT NOT NULL)'); $onlineTable = $this->schemaManager->listTableDetails('test_table_empty_metadata'); self::assertNotEmpty($onlineTable->getOption('engine')); diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 669f339fdeb..f78d7462b2d 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1444,7 +1444,7 @@ public function testPrimaryKeyAutoIncrement(): void "SELECT id FROM test_pk_auto_increment WHERE text = '1'" ); - $this->connection->query('DELETE FROM test_pk_auto_increment'); + $this->connection->executeStatement('DELETE FROM test_pk_auto_increment'); $this->connection->insert('test_pk_auto_increment', ['text' => '2']); diff --git a/tests/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Functional/Schema/SqliteSchemaManagerTest.php index 7162b3b223a..2b5261bf6e5 100644 --- a/tests/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Functional/Schema/SqliteSchemaManagerTest.php @@ -234,7 +234,7 @@ public function testPrimaryKeyNoAutoIncrement(): void $this->connection->insert('test_pk_auto_increment', ['text' => '1']); - $this->connection->query('DELETE FROM test_pk_auto_increment'); + $this->connection->executeStatement('DELETE FROM test_pk_auto_increment'); $this->connection->insert('test_pk_auto_increment', ['text' => '2']); diff --git a/tests/Functional/TransactionTest.php b/tests/Functional/TransactionTest.php index 940068afc90..97cb54fa356 100644 --- a/tests/Functional/TransactionTest.php +++ b/tests/Functional/TransactionTest.php @@ -29,7 +29,7 @@ protected function tearDown(): void public function testCommitFalse(): void { - $this->connection->query('SET SESSION wait_timeout=1'); + $this->connection->executeStatement('SET SESSION wait_timeout=1'); self::assertTrue($this->connection->beginTransaction()); From d47675e29acf74238de46a249bd4928b607daf44 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 10 Jul 2020 08:43:01 -0700 Subject: [PATCH 3/6] Remove Connection::query() --- UPGRADE.md | 7 ++- src/Connection.php | 26 ----------- .../PrimaryReadReplicaConnection.php | 27 +----------- tests/ConnectionTest.php | 6 --- tests/Functional/DataAccessTest.php | 1 - .../PrimaryReadReplicaConnectionTest.php | 44 ------------------- 6 files changed, 7 insertions(+), 104 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 025346a569b..abc0a1fcf34 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,11 @@ # 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 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: The following driver-level methods are allowed to throw a Driver\Exception: - `Connection::prepare()` -- `Connection::query()` - `Connection::exec()` - `Connection::lastInsertId()` - `Connection::beginTransaction()` diff --git a/src/Connection.php b/src/Connection.php index b4935e5962a..22f32d295bd 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -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; @@ -1028,31 +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. diff --git a/src/Connections/PrimaryReadReplicaConnection.php b/src/Connections/PrimaryReadReplicaConnection.php index 37bf9cf0a9c..f1e310174ab 100644 --- a/src/Connections/PrimaryReadReplicaConnection.php +++ b/src/Connections/PrimaryReadReplicaConnection.php @@ -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 @@ -31,8 +28,7 @@ * 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. + * '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. * @@ -392,27 +388,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(); diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 18b3ad2a377..031e9f5d6de 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -180,12 +180,6 @@ static function (Connection $connection, string $statement): void { }, ]; - yield 'query' => [ - static function (Connection $connection, string $statement): void { - $connection->query($statement); - }, - ]; - yield 'executeQuery' => [ static function (Connection $connection, string $statement): void { $connection->executeQuery($statement); diff --git a/tests/Functional/DataAccessTest.php b/tests/Functional/DataAccessTest.php index 824ea61f8e1..2392588970f 100644 --- a/tests/Functional/DataAccessTest.php +++ b/tests/Functional/DataAccessTest.php @@ -614,7 +614,6 @@ public function testEmptyFetchOneReturnsFalse(): void $this->connection->beginTransaction(); $this->connection->exec('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(); } diff --git a/tests/Functional/PrimaryReadReplicaConnectionTest.php b/tests/Functional/PrimaryReadReplicaConnectionTest.php index 3457e47ae9b..933d95ba801 100644 --- a/tests/Functional/PrimaryReadReplicaConnectionTest.php +++ b/tests/Functional/PrimaryReadReplicaConnectionTest.php @@ -189,48 +189,4 @@ public function testPrimaryReadReplicaConnectionCloseAndReconnect(): void $conn->ensureConnectedToPrimary(); 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']); - } } From 45736a18446bbd8918d0ff7aadd6b0774b548eea Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 10 Jul 2020 08:54:46 -0700 Subject: [PATCH 4/6] Replace $conn->exec() and $conn->executeUpdate() with $conn->executeStatement() --- src/Connection.php | 23 +++---------------- src/Event/Listeners/SQLSessionInit.php | 2 +- src/Schema/SQLServerSchemaManager.php | 2 +- .../AbstractSchemaSynchronizer.php | 4 ++-- tests/Events/SQLSessionInitTest.php | 2 +- tests/Functional/DataAccessTest.php | 4 ++-- tests/Functional/ExceptionTest.php | 14 +++++------ tests/Functional/ModifyLimitQueryTest.php | 11 +++++++-- .../Platform/DefaultExpressionTest.php | 2 +- ...imaryKeyWithNewAutoIncrementColumnTest.php | 2 +- tests/Functional/Schema/ForeignKeyTest.php | 2 +- .../Schema/OracleSchemaManagerTest.php | 2 +- .../Schema/PostgreSqlSchemaManagerTest.php | 14 +++++------ .../SchemaManagerFunctionalTestCase.php | 6 ++--- .../Schema/SqliteSchemaManagerTest.php | 4 ++-- tests/Functional/TableGeneratorTest.php | 2 +- tests/Functional/TemporaryTableTest.php | 18 +++++++++++---- tests/Functional/Ticket/DBAL202Test.php | 2 +- tests/Functional/Ticket/DBAL630Test.php | 4 ++-- tests/Functional/Ticket/DBAL752Test.php | 2 +- tests/Functional/WriteTest.php | 6 ++--- tests/TestUtil.php | 2 +- 22 files changed, 64 insertions(+), 66 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 22f32d295bd..4322d8fef5d 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1027,23 +1027,6 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc return new Result($result, $this); } - /** - * 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 $params The query parameters. - * @param array $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. * @@ -1410,7 +1393,7 @@ public function createSavepoint($savepoint) throw ConnectionException::savepointsNotSupported(); } - $this->executeUpdate($this->platform->createSavePoint($savepoint)); + $this->executeStatement($this->platform->createSavePoint($savepoint)); } /** @@ -1432,7 +1415,7 @@ public function releaseSavepoint($savepoint) return; } - $this->executeUpdate($this->platform->releaseSavePoint($savepoint)); + $this->executeStatement($this->platform->releaseSavePoint($savepoint)); } /** @@ -1450,7 +1433,7 @@ public function rollbackSavepoint($savepoint) throw ConnectionException::savepointsNotSupported(); } - $this->executeUpdate($this->platform->rollbackSavePoint($savepoint)); + $this->executeStatement($this->platform->rollbackSavePoint($savepoint)); } /** diff --git a/src/Event/Listeners/SQLSessionInit.php b/src/Event/Listeners/SQLSessionInit.php index 7dc27574026..a1fd2a9ac4e 100644 --- a/src/Event/Listeners/SQLSessionInit.php +++ b/src/Event/Listeners/SQLSessionInit.php @@ -30,7 +30,7 @@ public function __construct($sql) */ public function postConnect(ConnectionEventArgs $args) { - $args->getConnection()->executeUpdate($this->sql); + $args->getConnection()->executeStatement($this->sql); } /** diff --git a/src/Schema/SQLServerSchemaManager.php b/src/Schema/SQLServerSchemaManager.php index 00f6cb97da5..50613bd9ff6 100644 --- a/src/Schema/SQLServerSchemaManager.php +++ b/src/Schema/SQLServerSchemaManager.php @@ -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, diff --git a/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php b/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php index 1a3cc95bce3..9f5ccbfb78e 100644 --- a/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php +++ b/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php @@ -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) { } } @@ -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); } } } diff --git a/tests/Events/SQLSessionInitTest.php b/tests/Events/SQLSessionInitTest.php index eb5ab0a00ca..56f72f98e4b 100644 --- a/tests/Events/SQLSessionInitTest.php +++ b/tests/Events/SQLSessionInitTest.php @@ -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); diff --git a/tests/Functional/DataAccessTest.php b/tests/Functional/DataAccessTest.php index 2392588970f..cfccd032c0f 100644 --- a/tests/Functional/DataAccessTest.php +++ b/tests/Functional/DataAccessTest.php @@ -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 = []; @@ -612,7 +612,7 @@ 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')); $this->connection->rollBack(); } diff --git a/tests/Functional/ExceptionTest.php b/tests/Functional/ExceptionTest.php index 45a6f8b12a8..c717ad4f90e 100644 --- a/tests/Functional/ExceptionTest.php +++ b/tests/Functional/ExceptionTest.php @@ -86,7 +86,7 @@ public function testTableExistsException(): void public function testForeignKeyConstraintViolationExceptionOnInsert(): void { if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') { - $this->connection->exec('PRAGMA foreign_keys=ON'); + $this->connection->executeStatement('PRAGMA foreign_keys=ON'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); @@ -231,7 +231,7 @@ public function testNotNullConstraintViolationException(): void $table->setPrimaryKey(['id']); foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } $this->expectException(Exception\NotNullConstraintViolationException::class); @@ -246,7 +246,7 @@ public function testInvalidFieldNameException(): void $table->addColumn('id', 'integer', []); foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } $this->expectException(Exception\InvalidFieldNameException::class); @@ -264,7 +264,7 @@ public function testNonUniqueFieldNameException(): void $table2->addColumn('id', 'integer'); foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } $sql = 'SELECT id FROM ambiguous_list_table, ambiguous_list_table_2'; @@ -281,7 +281,7 @@ public function testUniqueConstraintViolationException(): void $table->addUniqueIndex(['id']); foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } $this->connection->insert('unique_field_table', ['id' => 5]); @@ -345,7 +345,7 @@ public function testConnectionExceptionSqLite(): void try { foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) { - $conn->exec($sql); + $conn->executeStatement($sql); } } finally { $this->cleanupReadOnlyFile($filename); @@ -390,7 +390,7 @@ public function testConnectionException(array $params): void $this->expectException(Exception\ConnectionException::class); foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) { - $conn->exec($sql); + $conn->executeStatement($sql); } } diff --git a/tests/Functional/ModifyLimitQueryTest.php b/tests/Functional/ModifyLimitQueryTest.php index 49d6df30e48..08bf29cbd6e 100644 --- a/tests/Functional/ModifyLimitQueryTest.php +++ b/tests/Functional/ModifyLimitQueryTest.php @@ -35,8 +35,15 @@ protected function setUp(): void self::$tableCreated = true; } - $this->connection->exec($this->connection->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table')); - $this->connection->exec($this->connection->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table2')); + $platform = $this->connection->getDatabasePlatform(); + + $this->connection->executeStatement( + $platform->getTruncateTableSQL('modify_limit_table') + ); + + $this->connection->executeStatement( + $platform->getTruncateTableSQL('modify_limit_table2') + ); } public function testModifyLimitQuerySimpleQuery(): void diff --git a/tests/Functional/Platform/DefaultExpressionTest.php b/tests/Functional/Platform/DefaultExpressionTest.php index 510fc0cbd6a..466b750c293 100644 --- a/tests/Functional/Platform/DefaultExpressionTest.php +++ b/tests/Functional/Platform/DefaultExpressionTest.php @@ -62,7 +62,7 @@ private function assertDefaultExpression(string $type, callable $expression): vo $table->addColumn('default_value', $type, ['default' => $defaultSql]); $this->connection->getSchemaManager()->dropAndCreateTable($table); - $this->connection->exec( + $this->connection->executeStatement( sprintf( 'INSERT INTO default_expr_test (actual_value) VALUES (%s)', $defaultSql diff --git a/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php b/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php index dec3fad6b59..74f95998c53 100644 --- a/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php +++ b/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php @@ -48,7 +48,7 @@ public function testAlterPrimaryKeyToAutoIncrementColumn(): void $diff = (new Comparator())->compare($schema, $newSchema); foreach ($diff->toSql($this->getPlatform()) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } $validationSchema = $schemaManager->createSchema(); diff --git a/tests/Functional/Schema/ForeignKeyTest.php b/tests/Functional/Schema/ForeignKeyTest.php index 62183825c92..c4e4695980e 100644 --- a/tests/Functional/Schema/ForeignKeyTest.php +++ b/tests/Functional/Schema/ForeignKeyTest.php @@ -26,7 +26,7 @@ public function testCreatingATableWithAForeignKey(): void ); foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } self::assertCount( diff --git a/tests/Functional/Schema/OracleSchemaManagerTest.php b/tests/Functional/Schema/OracleSchemaManagerTest.php index 956b34f97a4..e47a51309f5 100644 --- a/tests/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Functional/Schema/OracleSchemaManagerTest.php @@ -28,7 +28,7 @@ protected function setUp(): void } TestUtil::getPrivilegedConnection() - ->exec('GRANT ALL PRIVILEGES TO ' . $GLOBALS['db_user']); + ->executeStatement('GRANT ALL PRIVILEGES TO ' . $GLOBALS['db_user']); self::$privilegesGranted = true; } diff --git a/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php index 67325a59d8d..86b73aab5f2 100644 --- a/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -66,10 +66,10 @@ public function testGetSchemaNames(): void public function testSupportDomainTypeFallback(): void { $createDomainTypeSQL = 'CREATE DOMAIN MyMoney AS DECIMAL(18,2)'; - $this->connection->exec($createDomainTypeSQL); + $this->connection->executeStatement($createDomainTypeSQL); $createTableSQL = 'CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)'; - $this->connection->exec($createTableSQL); + $this->connection->executeStatement($createTableSQL); $table = $this->connection->getSchemaManager()->listTableDetails('domain_type_test'); self::assertInstanceOf(DecimalType::class, $table->getColumn('value')->getType()); @@ -154,7 +154,7 @@ public function testAlterTableAutoIncrementDrop(): void */ public function testTableWithSchema(): void { - $this->connection->exec('CREATE SCHEMA nested'); + $this->connection->executeStatement('CREATE SCHEMA nested'); $nestedRelatedTable = new Table('nested.schemarelated'); $column = $nestedRelatedTable->addColumn('id', 'integer'); @@ -190,10 +190,10 @@ public function testTableWithSchema(): void public function testReturnQuotedAssets(): void { $sql = 'create table dbal91_something ( id integer CONSTRAINT id_something PRIMARY KEY NOT NULL ,"table" integer );'; - $this->connection->exec($sql); + $this->connection->executeStatement($sql); $sql = 'ALTER TABLE dbal91_something ADD CONSTRAINT something_input FOREIGN KEY( "table" ) REFERENCES dbal91_something ON UPDATE CASCADE;'; - $this->connection->exec($sql); + $this->connection->executeStatement($sql); $table = $this->schemaManager->listTableDetails('dbal91_something'); @@ -349,8 +349,8 @@ public function testListQuotedTable(): void public function testListTableDetailsWhenCurrentSchemaNameQuoted(): void { - $this->connection->exec('CREATE SCHEMA "001_test"'); - $this->connection->exec('SET search_path TO "001_test"'); + $this->connection->executeStatement('CREATE SCHEMA "001_test"'); + $this->connection->executeStatement('SET search_path TO "001_test"'); try { $this->testListQuotedTable(); diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index f78d7462b2d..9b6d452b488 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -86,7 +86,7 @@ protected function tearDown(): void //TODO: SchemaDiff does not drop removed namespaces? try { //sql server versions below 2016 do not support 'IF EXISTS' so we have to catch the exception here - $this->connection->exec('DROP SCHEMA testschema'); + $this->connection->executeStatement('DROP SCHEMA testschema'); } catch (DBALException $e) { return; } @@ -643,7 +643,7 @@ public function testTableInNamespace(): void $diff->newNamespaces[] = 'testschema'; foreach ($diff->toSql($this->schemaManager->getDatabasePlatform()) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } //test if table is create in namespace @@ -1505,7 +1505,7 @@ public function testSchemaDiffForeignKeys(): void $sqls = $diff->toSql($platform); foreach ($sqls as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } $schema = new Schema([ diff --git a/tests/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Functional/Schema/SqliteSchemaManagerTest.php index 2b5261bf6e5..4983ff8ab6b 100644 --- a/tests/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Functional/Schema/SqliteSchemaManagerTest.php @@ -77,7 +77,7 @@ public function createListTableColumns(): Table public function testListForeignKeysFromExistingDatabase(): void { - $this->connection->exec(<<connection->executeStatement(<<connection->exec($sql); + $this->connection->executeStatement($sql); $columns = $this->schemaManager->listTableColumns('dbal_1779'); diff --git a/tests/Functional/TableGeneratorTest.php b/tests/Functional/TableGeneratorTest.php index 1e9e1634c23..c961b14ca37 100644 --- a/tests/Functional/TableGeneratorTest.php +++ b/tests/Functional/TableGeneratorTest.php @@ -31,7 +31,7 @@ protected function setUp(): void $schema->visit($visitor); foreach ($schema->toSql($platform) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } } catch (Throwable $e) { } diff --git a/tests/Functional/TemporaryTableTest.php b/tests/Functional/TemporaryTableTest.php index 13178f5b142..4cf702f8232 100644 --- a/tests/Functional/TemporaryTableTest.php +++ b/tests/Functional/TemporaryTableTest.php @@ -13,7 +13,9 @@ protected function setUp(): void { parent::setUp(); try { - $this->connection->exec($this->connection->getDatabasePlatform()->getDropTableSQL('nontemporary')); + $this->connection->executeStatement( + $this->connection->getDatabasePlatform()->getDropTableSQL('nontemporary') + ); } catch (Throwable $e) { } } @@ -23,7 +25,9 @@ protected function tearDown(): void if ($this->connection) { try { $tempTable = $this->connection->getDatabasePlatform()->getTemporaryTableName('my_temporary'); - $this->connection->exec($this->connection->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable)); + $this->connection->executeStatement( + $this->connection->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable) + ); } catch (Throwable $e) { } } @@ -56,7 +60,9 @@ public function testDropTemporaryTableNotAutoCommitTransaction(): void $this->connection->beginTransaction(); $this->connection->insert('nontemporary', ['id' => 1]); - $this->connection->exec($platform->getDropTemporaryTableSQL($tempTable)); + $this->connection->executeStatement( + $platform->getDropTemporaryTableSQL($tempTable) + ); $this->connection->insert('nontemporary', ['id' => 2]); $this->connection->rollBack(); @@ -90,13 +96,15 @@ public function testCreateTemporaryTableNotAutoCommitTransaction(): void $this->connection->beginTransaction(); $this->connection->insert('nontemporary', ['id' => 1]); - $this->connection->exec($createTempTableSQL); + $this->connection->executeStatement($createTempTableSQL); $this->connection->insert('nontemporary', ['id' => 2]); $this->connection->rollBack(); try { - $this->connection->exec($platform->getDropTemporaryTableSQL($tempTable)); + $this->connection->executeStatement( + $platform->getDropTemporaryTableSQL($tempTable) + ); } catch (Throwable $e) { } diff --git a/tests/Functional/Ticket/DBAL202Test.php b/tests/Functional/Ticket/DBAL202Test.php index f84c7e75ac8..1bc7a7de0f4 100644 --- a/tests/Functional/Ticket/DBAL202Test.php +++ b/tests/Functional/Ticket/DBAL202Test.php @@ -19,7 +19,7 @@ protected function setUp(): void } if ($this->connection->getSchemaManager()->tablesExist('DBAL202')) { - $this->connection->exec('DELETE FROM DBAL202'); + $this->connection->executeStatement('DELETE FROM DBAL202'); } else { $table = new Table('DBAL202'); $table->addColumn('id', 'integer'); diff --git a/tests/Functional/Ticket/DBAL630Test.php b/tests/Functional/Ticket/DBAL630Test.php index 2fe1a6768d2..2e30041fd6b 100644 --- a/tests/Functional/Ticket/DBAL630Test.php +++ b/tests/Functional/Ticket/DBAL630Test.php @@ -26,8 +26,8 @@ protected function setUp(): void } try { - $this->connection->exec('CREATE TABLE dbal630 (id SERIAL, bool_col BOOLEAN NOT NULL);'); - $this->connection->exec('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);'); + $this->connection->executeStatement('CREATE TABLE dbal630 (id SERIAL, bool_col BOOLEAN NOT NULL);'); + $this->connection->executeStatement('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);'); } catch (DBALException $e) { } diff --git a/tests/Functional/Ticket/DBAL752Test.php b/tests/Functional/Ticket/DBAL752Test.php index 5948c029d9d..9fc02de5aad 100644 --- a/tests/Functional/Ticket/DBAL752Test.php +++ b/tests/Functional/Ticket/DBAL752Test.php @@ -23,7 +23,7 @@ protected function setUp(): void public function testUnsignedIntegerDetection(): void { - $this->connection->exec(<<connection->executeStatement(<<getCreateTableSQL($table) as $sql) { - $this->connection->exec($sql); + $this->connection->executeStatement($sql); } $seqName = $platform->usesSequenceEmulatedIdentityColumns() @@ -286,11 +286,11 @@ public function testEmptyIdentityInsert(): void $sql = $platform->getEmptyIdentityInsertSQL('test_empty_identity', 'id'); - $this->connection->exec($sql); + $this->connection->executeStatement($sql); $firstId = $this->lastInsertId($seqName); - $this->connection->exec($sql); + $this->connection->executeStatement($sql); $secondId = $this->lastInsertId($seqName); diff --git a/tests/TestUtil.php b/tests/TestUtil.php index 2e01d580ea3..44f543d4468 100644 --- a/tests/TestUtil.php +++ b/tests/TestUtil.php @@ -106,7 +106,7 @@ private static function initializeDatabase(): void $stmts = $schema->toDropSql($testConn->getDatabasePlatform()); foreach ($stmts as $stmt) { - $testConn->exec($stmt); + $testConn->executeStatement($stmt); } } } From 684b4b5386cdda00035ccf7bba6b0190bfc78650 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 10 Jul 2020 08:55:36 -0700 Subject: [PATCH 5/6] Remove unnecessary method overrides in PrimaryReplicaConnection All removed methods are implemented via executeStatement() that ensures connection to the primary instance. --- .../PrimaryReadReplicaConnection.php | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/src/Connections/PrimaryReadReplicaConnection.php b/src/Connections/PrimaryReadReplicaConnection.php index f1e310174ab..e92679f0f0d 100644 --- a/src/Connections/PrimaryReadReplicaConnection.php +++ b/src/Connections/PrimaryReadReplicaConnection.php @@ -308,16 +308,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} */ @@ -331,33 +321,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} */ From ea020aa5d7c491a3d2d707b0caca6e7bf710076b Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 10 Jul 2020 08:56:17 -0700 Subject: [PATCH 6/6] Remove Connection::exec() and Connection::executeUpdate() --- UPGRADE.md | 3 ++- src/Connection.php | 25 ------------------- .../PrimaryReadReplicaConnection.php | 14 +---------- tests/ConnectionTest.php | 6 ----- 4 files changed, 3 insertions(+), 45 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index abc0a1fcf34..3a637f080fb 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -5,6 +5,8 @@ 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 @@ -56,7 +58,6 @@ The following classes have been renamed: The following driver-level methods are allowed to throw a Driver\Exception: - `Connection::prepare()` -- `Connection::exec()` - `Connection::lastInsertId()` - `Connection::beginTransaction()` - `Connection::commit()` diff --git a/src/Connection.php b/src/Connection.php index 4322d8fef5d..c068bce1e4a 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1083,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. * diff --git a/src/Connections/PrimaryReadReplicaConnection.php b/src/Connections/PrimaryReadReplicaConnection.php index e92679f0f0d..0e0278cc97c 100644 --- a/src/Connections/PrimaryReadReplicaConnection.php +++ b/src/Connections/PrimaryReadReplicaConnection.php @@ -27,7 +27,7 @@ * * 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', + * 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. @@ -256,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} */ diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 031e9f5d6de..57fc6d6f2bd 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -174,12 +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 'executeQuery' => [ static function (Connection $connection, string $statement): void { $connection->executeQuery($statement);