From c9de54b4a2a534571e9b8e6f9cd3b38077cdfe00 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Wed, 31 Mar 2010 21:13:34 +0000 Subject: [PATCH] [2.0] Changed Connection::execute() to Connection::executeQuery() as defined as a todo. --- lib/Doctrine/DBAL/Connection.php | 13 +++++----- .../DBAL/Schema/PostgreSqlSchemaManager.php | 2 +- .../DBAL/Schema/SqliteSchemaManager.php | 4 +-- .../DBAL/Tools/CLI/Tasks/RunSqlTask.php | 2 +- .../Persisters/StandardEntityPersister.php | 10 ++++---- .../ORM/Query/Exec/SingleSelectExecutor.php | 2 +- lib/Doctrine/ORM/Tools/SchemaTool.php | 6 ++--- .../AbstractManyToManyAssociationTestCase.php | 13 +++++----- .../ORM/Functional/BasicFunctionalTest.php | 25 +++++++++++-------- .../ORM/Functional/Locking/OptimisticTest.php | 8 +++--- .../OneToManyBidirectionalAssociationTest.php | 5 +++- ...neToManySelfReferentialAssociationTest.php | 2 +- .../OneToOneBidirectionalAssociationTest.php | 2 +- ...OneToOneSelfReferentialAssociationTest.php | 2 +- .../OneToOneUnidirectionalAssociationTest.php | 5 +++- 15 files changed, 55 insertions(+), 46 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index a2957c35a..92a3480d9 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -316,7 +316,7 @@ class Connection implements DriverConnection */ public function fetchRow($statement, array $params = array()) { - return $this->execute($statement, $params)->fetch(PDO::FETCH_ASSOC); + return $this->executeQuery($statement, $params)->fetch(PDO::FETCH_ASSOC); } /** @@ -329,7 +329,7 @@ class Connection implements DriverConnection */ public function fetchArray($statement, array $params = array()) { - return $this->execute($statement, $params)->fetch(PDO::FETCH_NUM); + return $this->executeQuery($statement, $params)->fetch(PDO::FETCH_NUM); } /** @@ -343,7 +343,7 @@ class Connection implements DriverConnection */ public function fetchColumn($statement, array $params = array(), $colnum = 0) { - return $this->execute($statement, $params)->fetchColumn($colnum); + return $this->executeQuery($statement, $params)->fetchColumn($colnum); } /** @@ -524,7 +524,7 @@ class Connection implements DriverConnection */ public function fetchAll($sql, array $params = array()) { - return $this->execute($sql, $params)->fetchAll(PDO::FETCH_ASSOC); + return $this->executeQuery($sql, $params)->fetchAll(PDO::FETCH_ASSOC); } /** @@ -549,10 +549,9 @@ class Connection implements DriverConnection * @param string $query The SQL query to execute. * @param array $params The parameters to bind to the query, if any. * @return Doctrine\DBAL\Driver\Statement The executed statement. - * @todo Rename to executeQuery ? * @internal PERF: Directly prepares a driver statement, not a wrapper. */ - public function execute($query, array $params = array(), $types = array()) + public function executeQuery($query, array $params = array(), $types = array()) { $this->connect(); @@ -589,7 +588,7 @@ class Connection implements DriverConnection public function project($query, array $params = array(), Closure $function) { $result = array(); - $stmt = $this->execute($query, $params); + $stmt = $this->executeQuery($query, $params); while ($row = $stmt->fetch()) { $result[] = $function($row); diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 30df271c9..70e6a6051 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -128,7 +128,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager $columnNameSql = "SELECT attnum, attname FROM pg_attribute WHERE attrelid={$row['indrelid']} AND attnum $colNumbersSql ORDER BY attnum ASC;"; - $stmt = $this->_conn->execute($columnNameSql); + $stmt = $this->_conn->executeQuery($columnNameSql); $indexColumns = $stmt->fetchAll(); // required for getting the order of the columns right. diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 695e0161b..e9953097d 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -80,7 +80,7 @@ class SqliteSchemaManager extends AbstractSchemaManager $indexBuffer = array(); // fetch primary - $stmt = $this->_conn->execute( "PRAGMA TABLE_INFO ('$tableName')" ); + $stmt = $this->_conn->executeQuery( "PRAGMA TABLE_INFO ('$tableName')" ); $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC); foreach($indexArray AS $indexColumnRow) { if($indexColumnRow['pk'] == "1") { @@ -101,7 +101,7 @@ class SqliteSchemaManager extends AbstractSchemaManager $idx['primary'] = false; $idx['non_unique'] = $tableIndex['unique']?false:true; - $stmt = $this->_conn->execute( "PRAGMA INDEX_INFO ( '{$keyName}' )" ); + $stmt = $this->_conn->executeQuery( "PRAGMA INDEX_INFO ( '{$keyName}' )" ); $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC); foreach ( $indexArray as $indexColumnRow ) { diff --git a/lib/Doctrine/DBAL/Tools/CLI/Tasks/RunSqlTask.php b/lib/Doctrine/DBAL/Tools/CLI/Tasks/RunSqlTask.php index bacc92e18..687f5e071 100644 --- a/lib/Doctrine/DBAL/Tools/CLI/Tasks/RunSqlTask.php +++ b/lib/Doctrine/DBAL/Tools/CLI/Tasks/RunSqlTask.php @@ -157,7 +157,7 @@ class RunSqlTask extends AbstractTask $em = $this->getConfiguration()->getAttribute('em'); if (preg_match('/^select/i', $arguments['sql'])) { - $stmt = $em->getConnection()->execute($arguments['sql']); + $stmt = $em->getConnection()->executeQuery($arguments['sql']); $resultSet = $stmt->fetchAll(\Doctrine\DBAL\Connection::FETCH_ASSOC); } else { $resultSet = $em->getConnection()->executeUpdate($arguments['sql']); diff --git a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php index f79f8a5ab..a02a9b191 100644 --- a/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php @@ -429,7 +429,7 @@ class StandardEntityPersister { $sql = $this->_getSelectEntitiesSQL($criteria, $assoc); $params = array_values($criteria); - $stmt = $this->_conn->execute($sql, $params); + $stmt = $this->_conn->executeQuery($sql, $params); $result = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -447,7 +447,7 @@ class StandardEntityPersister $sql = $this->_getSelectEntitiesSQL($id); $params = array_values($id); - $stmt = $this->_conn->execute($sql, $params); + $stmt = $this->_conn->executeQuery($sql, $params); $result = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -530,7 +530,7 @@ class StandardEntityPersister $sql = $this->_getSelectEntitiesSQL($criteria); $params = array_values($criteria); - $stmt = $this->_conn->execute($sql, $params); + $stmt = $this->_conn->executeQuery($sql, $params); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -553,7 +553,7 @@ class StandardEntityPersister $owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedBy]; $sql = $this->_getSelectEntitiesSQL($criteria, $owningAssoc, $assoc->orderBy); $params = array_values($criteria); - $stmt = $this->_conn->execute($sql, $params); + $stmt = $this->_conn->executeQuery($sql, $params); while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { $coll->hydrateAdd($this->_createEntity($result)); } @@ -571,7 +571,7 @@ class StandardEntityPersister { $sql = $this->_getSelectManyToManyEntityCollectionSQL($assoc, $criteria); $params = array_values($criteria); - $stmt = $this->_conn->execute($sql, $params); + $stmt = $this->_conn->executeQuery($sql, $params); while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { $coll->hydrateAdd($this->_createEntity($result)); } diff --git a/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php b/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php index e096bed10..4e08e0f9c 100644 --- a/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php @@ -43,6 +43,6 @@ class SingleSelectExecutor extends AbstractSqlExecutor public function execute(Connection $conn, array $params, array $types) { - return $conn->execute($this->_sqlStatements, $params, $types); + return $conn->executeQuery($this->_sqlStatements, $params, $types); } } diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 968f5e94a..129c9aa02 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -85,7 +85,7 @@ class SchemaTool $conn = $this->_em->getConnection(); foreach ($createSchemaSql as $sql) { - $conn->execute($sql); + $conn->executeQuery($sql); } } @@ -482,7 +482,7 @@ class SchemaTool $conn = $this->_em->getConnection(); foreach ($dropSchemaSql as $sql) { - $conn->execute($sql); + $conn->executeQuery($sql); } } @@ -570,7 +570,7 @@ class SchemaTool $conn = $this->_em->getConnection(); foreach ($updateSchemaSql as $sql) { - $conn->execute($sql); + $conn->executeQuery($sql); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php b/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php index 201565c67..f11ad2622 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php +++ b/tests/Doctrine/Tests/ORM/Functional/AbstractManyToManyAssociationTestCase.php @@ -27,13 +27,12 @@ class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctiona protected function _countForeignKeys($firstId, $secondId) { - return count($this->_em->getConnection() - ->execute("SELECT {$this->_firstField} - FROM {$this->_table} - WHERE {$this->_firstField}=? - AND {$this->_secondField}=?", - array($firstId, $secondId)) - ->fetchAll()); + return count($this->_em->getConnection()->executeQuery(" + SELECT {$this->_firstField} + FROM {$this->_table} + WHERE {$this->_firstField} = ? + AND {$this->_secondField} = ? + ", array($firstId, $secondId))->fetchAll()); } public function assertCollectionEquals(Collection $first, Collection $second) diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index 385b72a95..3ac3de8eb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -120,8 +120,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); // Check that the foreign key has been set - $userId = $this->_em->getConnection()->execute("SELECT user_id FROM cms_addresses WHERE id=?", - array($address->id))->fetchColumn(); + $userId = $this->_em->getConnection()->executeQuery( + "SELECT user_id FROM cms_addresses WHERE id=?", array($address->id) + )->fetchColumn(); $this->assertTrue(is_numeric($userId)); $this->_em->clear(); @@ -158,8 +159,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); // Check that the link in the association table has been deleted - $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups", - array())->fetchColumn(); + $count = $this->_em->getConnection()->executeQuery( + "SELECT COUNT(*) FROM cms_users_groups", array() + )->fetchColumn(); $this->assertEquals(0, $count); } @@ -182,8 +184,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); // Check that there are indeed 10 links in the association table - $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups", - array())->fetchColumn(); + $count = $this->_em->getConnection()->executeQuery( + "SELECT COUNT(*) FROM cms_users_groups", array() + )->fetchColumn(); $this->assertEquals(10, $count); $user->groups->clear(); @@ -192,8 +195,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); // Check that the links in the association table have been deleted - $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups", - array())->fetchColumn(); + $count = $this->_em->getConnection()->executeQuery( + "SELECT COUNT(*) FROM cms_users_groups", array() + )->fetchColumn(); $this->assertEquals(0, $count); } @@ -220,8 +224,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); // Check that there are just 2 phonenumbers left - $count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_phonenumbers", - array())->fetchColumn(); + $count = $this->_em->getConnection()->executeQuery( + "SELECT COUNT(*) FROM cms_phonenumbers", array() + )->fetchColumn(); $this->assertEquals(2, $count); // only 2 remaining } diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index 56a0e6d47..947afdc68 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -51,7 +51,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase // Manually update/increment the version so we can try and save the same // $test and make sure the exception is thrown saying the record was // changed or updated since you read it - $this->_conn->execute('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', array(2, $test->id)); + $this->_conn->executeQuery('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', array(2, $test->id)); // Now lets change a property and try and save it again $test->whatever = 'ok'; @@ -80,7 +80,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase // Manually update/increment the version so we can try and save the same // $test and make sure the exception is thrown saying the record was // changed or updated since you read it - $this->_conn->execute('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', array(2, $test->id)); + $this->_conn->executeQuery('UPDATE optimistic_joined_parent SET version = ? WHERE id = ?', array(2, $test->id)); // Now lets change a property and try and save it again $test->name = 'WHATT???'; @@ -109,7 +109,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase // Manually update/increment the version so we can try and save the same // $test and make sure the exception is thrown saying the record was // changed or updated since you read it - $this->_conn->execute('UPDATE optimistic_standard SET version = ? WHERE id = ?', array(2, $test->id)); + $this->_conn->executeQuery('UPDATE optimistic_standard SET version = ? WHERE id = ?', array(2, $test->id)); // Now lets change a property and try and save it again $test->name = 'WHATT???'; @@ -139,7 +139,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase // Manually increment the version datetime column $format = $this->_em->getConnection()->getDatabasePlatform()->getDateTimeFormatString(); - $this->_conn->execute('UPDATE optimistic_timestamp SET version = ? WHERE id = ?', array(date($format, strtotime($test->version->format($format)) + 3600), $test->id)); + $this->_conn->executeQuery('UPDATE optimistic_timestamp SET version = ? WHERE id = ?', array(date($format, strtotime($test->version->format($format)) + 3600), $test->id)); // Try and update the record and it should throw an exception $test->name = 'Testing again'; diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index 29ae93e57..16a633dde 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -162,7 +162,10 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona } public function assertFeatureForeignKeyIs($value, ECommerceFeature $feature) { - $foreignKey = $this->_em->getConnection()->execute('SELECT product_id FROM ecommerce_features WHERE id=?', array($feature->getId()))->fetchColumn(); + $foreignKey = $this->_em->getConnection()->executeQuery( + 'SELECT product_id FROM ecommerce_features WHERE id=?', + array($feature->getId()) + )->fetchColumn(); $this->assertEquals($value, $foreignKey); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index 0fead683b..4aa94a3ce 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -116,7 +116,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio } public function assertForeignKeyIs($value, ECommerceCategory $child) { - $foreignKey = $this->_em->getConnection()->execute('SELECT parent_id FROM ecommerce_categories WHERE id=?', array($child->getId()))->fetchColumn(); + $foreignKey = $this->_em->getConnection()->executeQuery('SELECT parent_id FROM ecommerce_categories WHERE id=?', array($child->getId()))->fetchColumn(); $this->assertEquals($value, $foreignKey); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index c479f4c52..73363547c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -144,7 +144,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional } public function assertCartForeignKeyIs($value) { - $foreignKey = $this->_em->getConnection()->execute('SELECT customer_id FROM ecommerce_carts WHERE id=?', array($this->cart->getId()))->fetchColumn(); + $foreignKey = $this->_em->getConnection()->executeQuery('SELECT customer_id FROM ecommerce_carts WHERE id=?', array($this->cart->getId()))->fetchColumn(); $this->assertEquals($value, $foreignKey); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index 79cf0aa7b..a58384b7e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -110,7 +110,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction } public function assertForeignKeyIs($value) { - $foreignKey = $this->_em->getConnection()->execute('SELECT mentor_id FROM ecommerce_customers WHERE id=?', array($this->customer->getId()))->fetchColumn(); + $foreignKey = $this->_em->getConnection()->executeQuery('SELECT mentor_id FROM ecommerce_customers WHERE id=?', array($this->customer->getId()))->fetchColumn(); $this->assertEquals($value, $foreignKey); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index 4a3e61c25..af1ff2362 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -99,7 +99,10 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona } public function assertForeignKeyIs($value) { - $foreignKey = $this->_em->getConnection()->execute('SELECT shipping_id FROM ecommerce_products WHERE id=?', array($this->product->getId()))->fetchColumn(); + $foreignKey = $this->_em->getConnection()->executeQuery( + 'SELECT shipping_id FROM ecommerce_products WHERE id=?', + array($this->product->getId()) + )->fetchColumn(); $this->assertEquals($value, $foreignKey); } }