Commit c9de54b4 authored by guilhermeblanco's avatar guilhermeblanco

[2.0] Changed Connection::execute() to Connection::executeQuery() as defined as a todo.

parent 7af6aa1d
...@@ -316,7 +316,7 @@ class Connection implements DriverConnection ...@@ -316,7 +316,7 @@ class Connection implements DriverConnection
*/ */
public function fetchRow($statement, array $params = array()) 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 ...@@ -329,7 +329,7 @@ class Connection implements DriverConnection
*/ */
public function fetchArray($statement, array $params = array()) 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 ...@@ -343,7 +343,7 @@ class Connection implements DriverConnection
*/ */
public function fetchColumn($statement, array $params = array(), $colnum = 0) 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 ...@@ -524,7 +524,7 @@ class Connection implements DriverConnection
*/ */
public function fetchAll($sql, array $params = array()) 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 ...@@ -549,10 +549,9 @@ class Connection implements DriverConnection
* @param string $query The SQL query to execute. * @param string $query The SQL query to execute.
* @param array $params The parameters to bind to the query, if any. * @param array $params The parameters to bind to the query, if any.
* @return Doctrine\DBAL\Driver\Statement The executed statement. * @return Doctrine\DBAL\Driver\Statement The executed statement.
* @todo Rename to executeQuery ?
* @internal PERF: Directly prepares a driver statement, not a wrapper. * @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(); $this->connect();
...@@ -589,7 +588,7 @@ class Connection implements DriverConnection ...@@ -589,7 +588,7 @@ class Connection implements DriverConnection
public function project($query, array $params = array(), Closure $function) public function project($query, array $params = array(), Closure $function)
{ {
$result = array(); $result = array();
$stmt = $this->execute($query, $params); $stmt = $this->executeQuery($query, $params);
while ($row = $stmt->fetch()) { while ($row = $stmt->fetch()) {
$result[] = $function($row); $result[] = $function($row);
......
...@@ -128,7 +128,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -128,7 +128,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$columnNameSql = "SELECT attnum, attname FROM pg_attribute $columnNameSql = "SELECT attnum, attname FROM pg_attribute
WHERE attrelid={$row['indrelid']} AND attnum $colNumbersSql ORDER BY attnum ASC;"; WHERE attrelid={$row['indrelid']} AND attnum $colNumbersSql ORDER BY attnum ASC;";
$stmt = $this->_conn->execute($columnNameSql); $stmt = $this->_conn->executeQuery($columnNameSql);
$indexColumns = $stmt->fetchAll(); $indexColumns = $stmt->fetchAll();
// required for getting the order of the columns right. // required for getting the order of the columns right.
......
...@@ -80,7 +80,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -80,7 +80,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
$indexBuffer = array(); $indexBuffer = array();
// fetch primary // fetch primary
$stmt = $this->_conn->execute( "PRAGMA TABLE_INFO ('$tableName')" ); $stmt = $this->_conn->executeQuery( "PRAGMA TABLE_INFO ('$tableName')" );
$indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC); $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach($indexArray AS $indexColumnRow) { foreach($indexArray AS $indexColumnRow) {
if($indexColumnRow['pk'] == "1") { if($indexColumnRow['pk'] == "1") {
...@@ -101,7 +101,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -101,7 +101,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
$idx['primary'] = false; $idx['primary'] = false;
$idx['non_unique'] = $tableIndex['unique']?false:true; $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); $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ( $indexArray as $indexColumnRow ) { foreach ( $indexArray as $indexColumnRow ) {
......
...@@ -157,7 +157,7 @@ class RunSqlTask extends AbstractTask ...@@ -157,7 +157,7 @@ class RunSqlTask extends AbstractTask
$em = $this->getConfiguration()->getAttribute('em'); $em = $this->getConfiguration()->getAttribute('em');
if (preg_match('/^select/i', $arguments['sql'])) { 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); $resultSet = $stmt->fetchAll(\Doctrine\DBAL\Connection::FETCH_ASSOC);
} else { } else {
$resultSet = $em->getConnection()->executeUpdate($arguments['sql']); $resultSet = $em->getConnection()->executeUpdate($arguments['sql']);
......
...@@ -429,7 +429,7 @@ class StandardEntityPersister ...@@ -429,7 +429,7 @@ class StandardEntityPersister
{ {
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc); $sql = $this->_getSelectEntitiesSQL($criteria, $assoc);
$params = array_values($criteria); $params = array_values($criteria);
$stmt = $this->_conn->execute($sql, $params); $stmt = $this->_conn->executeQuery($sql, $params);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -447,7 +447,7 @@ class StandardEntityPersister ...@@ -447,7 +447,7 @@ class StandardEntityPersister
$sql = $this->_getSelectEntitiesSQL($id); $sql = $this->_getSelectEntitiesSQL($id);
$params = array_values($id); $params = array_values($id);
$stmt = $this->_conn->execute($sql, $params); $stmt = $this->_conn->executeQuery($sql, $params);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -530,7 +530,7 @@ class StandardEntityPersister ...@@ -530,7 +530,7 @@ class StandardEntityPersister
$sql = $this->_getSelectEntitiesSQL($criteria); $sql = $this->_getSelectEntitiesSQL($criteria);
$params = array_values($criteria); $params = array_values($criteria);
$stmt = $this->_conn->execute($sql, $params); $stmt = $this->_conn->executeQuery($sql, $params);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC); $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
...@@ -553,7 +553,7 @@ class StandardEntityPersister ...@@ -553,7 +553,7 @@ class StandardEntityPersister
$owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedBy]; $owningAssoc = $this->_class->associationMappings[$coll->getMapping()->mappedBy];
$sql = $this->_getSelectEntitiesSQL($criteria, $owningAssoc, $assoc->orderBy); $sql = $this->_getSelectEntitiesSQL($criteria, $owningAssoc, $assoc->orderBy);
$params = array_values($criteria); $params = array_values($criteria);
$stmt = $this->_conn->execute($sql, $params); $stmt = $this->_conn->executeQuery($sql, $params);
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result)); $coll->hydrateAdd($this->_createEntity($result));
} }
...@@ -571,7 +571,7 @@ class StandardEntityPersister ...@@ -571,7 +571,7 @@ class StandardEntityPersister
{ {
$sql = $this->_getSelectManyToManyEntityCollectionSQL($assoc, $criteria); $sql = $this->_getSelectManyToManyEntityCollectionSQL($assoc, $criteria);
$params = array_values($criteria); $params = array_values($criteria);
$stmt = $this->_conn->execute($sql, $params); $stmt = $this->_conn->executeQuery($sql, $params);
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
$coll->hydrateAdd($this->_createEntity($result)); $coll->hydrateAdd($this->_createEntity($result));
} }
......
...@@ -43,6 +43,6 @@ class SingleSelectExecutor extends AbstractSqlExecutor ...@@ -43,6 +43,6 @@ class SingleSelectExecutor extends AbstractSqlExecutor
public function execute(Connection $conn, array $params, array $types) public function execute(Connection $conn, array $params, array $types)
{ {
return $conn->execute($this->_sqlStatements, $params, $types); return $conn->executeQuery($this->_sqlStatements, $params, $types);
} }
} }
...@@ -85,7 +85,7 @@ class SchemaTool ...@@ -85,7 +85,7 @@ class SchemaTool
$conn = $this->_em->getConnection(); $conn = $this->_em->getConnection();
foreach ($createSchemaSql as $sql) { foreach ($createSchemaSql as $sql) {
$conn->execute($sql); $conn->executeQuery($sql);
} }
} }
...@@ -482,7 +482,7 @@ class SchemaTool ...@@ -482,7 +482,7 @@ class SchemaTool
$conn = $this->_em->getConnection(); $conn = $this->_em->getConnection();
foreach ($dropSchemaSql as $sql) { foreach ($dropSchemaSql as $sql) {
$conn->execute($sql); $conn->executeQuery($sql);
} }
} }
...@@ -570,7 +570,7 @@ class SchemaTool ...@@ -570,7 +570,7 @@ class SchemaTool
$conn = $this->_em->getConnection(); $conn = $this->_em->getConnection();
foreach ($updateSchemaSql as $sql) { foreach ($updateSchemaSql as $sql) {
$conn->execute($sql); $conn->executeQuery($sql);
} }
} }
......
...@@ -27,13 +27,12 @@ class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctiona ...@@ -27,13 +27,12 @@ class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctiona
protected function _countForeignKeys($firstId, $secondId) protected function _countForeignKeys($firstId, $secondId)
{ {
return count($this->_em->getConnection() return count($this->_em->getConnection()->executeQuery("
->execute("SELECT {$this->_firstField} SELECT {$this->_firstField}
FROM {$this->_table} FROM {$this->_table}
WHERE {$this->_firstField}=? WHERE {$this->_firstField} = ?
AND {$this->_secondField}=?", AND {$this->_secondField} = ?
array($firstId, $secondId)) ", array($firstId, $secondId))->fetchAll());
->fetchAll());
} }
public function assertCollectionEquals(Collection $first, Collection $second) public function assertCollectionEquals(Collection $first, Collection $second)
......
...@@ -120,8 +120,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -120,8 +120,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush(); $this->_em->flush();
// Check that the foreign key has been set // Check that the foreign key has been set
$userId = $this->_em->getConnection()->execute("SELECT user_id FROM cms_addresses WHERE id=?", $userId = $this->_em->getConnection()->executeQuery(
array($address->id))->fetchColumn(); "SELECT user_id FROM cms_addresses WHERE id=?", array($address->id)
)->fetchColumn();
$this->assertTrue(is_numeric($userId)); $this->assertTrue(is_numeric($userId));
$this->_em->clear(); $this->_em->clear();
...@@ -158,8 +159,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -158,8 +159,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush(); $this->_em->flush();
// Check that the link in the association table has been deleted // Check that the link in the association table has been deleted
$count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups", $count = $this->_em->getConnection()->executeQuery(
array())->fetchColumn(); "SELECT COUNT(*) FROM cms_users_groups", array()
)->fetchColumn();
$this->assertEquals(0, $count); $this->assertEquals(0, $count);
} }
...@@ -182,8 +184,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -182,8 +184,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush(); $this->_em->flush();
// Check that there are indeed 10 links in the association table // Check that there are indeed 10 links in the association table
$count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups", $count = $this->_em->getConnection()->executeQuery(
array())->fetchColumn(); "SELECT COUNT(*) FROM cms_users_groups", array()
)->fetchColumn();
$this->assertEquals(10, $count); $this->assertEquals(10, $count);
$user->groups->clear(); $user->groups->clear();
...@@ -192,8 +195,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -192,8 +195,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush(); $this->_em->flush();
// Check that the links in the association table have been deleted // Check that the links in the association table have been deleted
$count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups", $count = $this->_em->getConnection()->executeQuery(
array())->fetchColumn(); "SELECT COUNT(*) FROM cms_users_groups", array()
)->fetchColumn();
$this->assertEquals(0, $count); $this->assertEquals(0, $count);
} }
...@@ -220,8 +224,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -220,8 +224,9 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush(); $this->_em->flush();
// Check that there are just 2 phonenumbers left // Check that there are just 2 phonenumbers left
$count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_phonenumbers", $count = $this->_em->getConnection()->executeQuery(
array())->fetchColumn(); "SELECT COUNT(*) FROM cms_phonenumbers", array()
)->fetchColumn();
$this->assertEquals(2, $count); // only 2 remaining $this->assertEquals(2, $count); // only 2 remaining
} }
......
...@@ -51,7 +51,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -51,7 +51,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
// Manually update/increment the version so we can try and save the same // 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 // $test and make sure the exception is thrown saying the record was
// changed or updated since you read it // 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 // Now lets change a property and try and save it again
$test->whatever = 'ok'; $test->whatever = 'ok';
...@@ -80,7 +80,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -80,7 +80,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
// Manually update/increment the version so we can try and save the same // 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 // $test and make sure the exception is thrown saying the record was
// changed or updated since you read it // 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 // Now lets change a property and try and save it again
$test->name = 'WHATT???'; $test->name = 'WHATT???';
...@@ -109,7 +109,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -109,7 +109,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
// Manually update/increment the version so we can try and save the same // 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 // $test and make sure the exception is thrown saying the record was
// changed or updated since you read it // 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 // Now lets change a property and try and save it again
$test->name = 'WHATT???'; $test->name = 'WHATT???';
...@@ -139,7 +139,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -139,7 +139,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase
// Manually increment the version datetime column // Manually increment the version datetime column
$format = $this->_em->getConnection()->getDatabasePlatform()->getDateTimeFormatString(); $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 // Try and update the record and it should throw an exception
$test->name = 'Testing again'; $test->name = 'Testing again';
......
...@@ -162,7 +162,10 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona ...@@ -162,7 +162,10 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
} }
public function assertFeatureForeignKeyIs($value, ECommerceFeature $feature) { 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); $this->assertEquals($value, $foreignKey);
} }
} }
...@@ -116,7 +116,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio ...@@ -116,7 +116,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio
} }
public function assertForeignKeyIs($value, ECommerceCategory $child) { 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); $this->assertEquals($value, $foreignKey);
} }
} }
...@@ -144,7 +144,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional ...@@ -144,7 +144,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
} }
public function assertCartForeignKeyIs($value) { 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); $this->assertEquals($value, $foreignKey);
} }
} }
...@@ -110,7 +110,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction ...@@ -110,7 +110,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction
} }
public function assertForeignKeyIs($value) { 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); $this->assertEquals($value, $foreignKey);
} }
......
...@@ -99,7 +99,10 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona ...@@ -99,7 +99,10 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
} }
public function assertForeignKeyIs($value) { 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); $this->assertEquals($value, $foreignKey);
} }
} }
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