Commit e0d1cd21 authored by Nicolas Grekas's avatar Nicolas Grekas

add setFetchMode() at Connection level

parent d2655e48
......@@ -173,6 +173,8 @@ class Connection implements DriverConnection
*/
private $_isRollbackOnly = false;
private $_defaultFetchStyle = PDO::FETCH_ASSOC;
/**
* Initializes a new instance of the Connection class.
*
......@@ -356,6 +358,16 @@ class Connection implements DriverConnection
return true;
}
/**
* setFetchMode
*
* @param integer $fetchStyle
*/
public function setFetchMode($fetchStyle)
{
$this->_defaultFetchStyle = $fetchStyle;
}
/**
* Prepares and executes an SQL query and returns the first row of the result
* as an associative array.
......@@ -579,7 +591,7 @@ class Connection implements DriverConnection
*/
public function fetchAll($sql, array $params = array())
{
return $this->executeQuery($sql, $params)->fetchAll(PDO::FETCH_ASSOC);
return $this->executeQuery($sql, $params)->fetchAll();
}
/**
......@@ -592,7 +604,10 @@ class Connection implements DriverConnection
{
$this->connect();
return new Statement($statement, $this);
$stmt = new Statement($statement, $this);
$stmt->setFetchMode($this->_defaultFetchStyle);
return $stmt;
}
/**
......@@ -635,6 +650,8 @@ class Connection implements DriverConnection
$stmt = $this->_conn->query($query);
}
$stmt->setFetchMode($this->_defaultFetchStyle);
if ($logger) {
$logger->stopQuery();
}
......@@ -664,12 +681,19 @@ class Connection implements DriverConnection
if ($data = $resultCache->fetch($cacheKey)) {
// is the real key part of this row pointers map or is the cache only pointing to other cache keys?
if (isset($data[$realKey])) {
return new ArrayStatement($data[$realKey]);
$stmt = new ArrayStatement($data[$realKey]);
} else if (array_key_exists($realKey, $data)) {
return new ArrayStatement(array());
$stmt = new ArrayStatement(array());
}
}
return new ResultCacheStatement($this->executeQuery($query, $params, $types), $resultCache, $cacheKey, $realKey, $qcp->getLifetime());
if (!isset($stmt)) {
$stmt = new ResultCacheStatement($this->executeQuery($query, $params, $types), $resultCache, $cacheKey, $realKey, $qcp->getLifetime());
}
$stmt->setFetchMode($this->_defaultFetchStyle);
return $stmt;
}
/**
......@@ -716,6 +740,7 @@ class Connection implements DriverConnection
}
$statement = call_user_func_array(array($this->_conn, 'query'), $args);
$statement->setFetchMode($this->_defaultFetchStyle);
if ($logger) {
$logger->stopQuery();
......
......@@ -189,7 +189,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testFetchBoth()
{
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
$row = $this->_conn->executeQuery($sql, array(1, 'foo'))->fetch();
$row = $this->_conn->executeQuery($sql, array(1, 'foo'))->fetch(\PDO::FETCH_BOTH);
$this->assertTrue($row !== false);
......
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