Commit d2655e48 authored by Nicolas Grekas's avatar Nicolas Grekas

fix defaultFetchStyle not being considered everywhere

parent d55b9fbb
...@@ -58,14 +58,15 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement ...@@ -58,14 +58,15 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
public function getIterator() public function getIterator()
{ {
$data = $this->fetchAll($this->defaultFetchStyle); $data = $this->fetchAll();
return new \ArrayIterator($data); return new \ArrayIterator($data);
} }
public function fetch($fetchStyle = PDO::FETCH_BOTH) public function fetch($fetchStyle = null)
{ {
if (isset($this->data[$this->num])) { if (isset($this->data[$this->num])) {
$row = $this->data[$this->num++]; $row = $this->data[$this->num++];
$fetchStyle = $fetchStyle ?: $this->defaultFetchStyle;
if ($fetchStyle === PDO::FETCH_ASSOC) { if ($fetchStyle === PDO::FETCH_ASSOC) {
return $row; return $row;
} else if ($fetchStyle === PDO::FETCH_NUM) { } else if ($fetchStyle === PDO::FETCH_NUM) {
...@@ -81,7 +82,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement ...@@ -81,7 +82,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
return false; return false;
} }
public function fetchAll($fetchStyle = PDO::FETCH_BOTH) public function fetchAll($fetchStyle = null)
{ {
$rows = array(); $rows = array();
while ($row = $this->fetch($fetchStyle)) { while ($row = $this->fetch($fetchStyle)) {
......
...@@ -139,7 +139,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -139,7 +139,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
public function getIterator() public function getIterator()
{ {
$data = $this->fetchAll($this->defaultFetchStyle); $data = $this->fetchAll();
return new \ArrayIterator($data); return new \ArrayIterator($data);
} }
...@@ -153,7 +153,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -153,7 +153,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
* *
* @return mixed * @return mixed
*/ */
public function fetch($fetchStyle = PDO::FETCH_BOTH) public function fetch($fetchStyle = null)
{ {
if ($this->data === null) { if ($this->data === null) {
$this->data = array(); $this->data = array();
...@@ -163,6 +163,8 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -163,6 +163,8 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
if ($row) { if ($row) {
$this->data[] = $row; $this->data[] = $row;
$fetchStyle = $fetchStyle ?: $this->defaultFetchStyle;
if ($fetchStyle == PDO::FETCH_ASSOC) { if ($fetchStyle == PDO::FETCH_ASSOC) {
return $row; return $row;
} else if ($fetchStyle == PDO::FETCH_NUM) { } else if ($fetchStyle == PDO::FETCH_NUM) {
...@@ -188,7 +190,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement ...@@ -188,7 +190,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
* *
* @return array * @return array
*/ */
public function fetchAll($fetchStyle = PDO::FETCH_BOTH) public function fetchAll($fetchStyle = null)
{ {
$rows = array(); $rows = array();
while ($row = $this->fetch($fetchStyle)) { while ($row = $this->fetch($fetchStyle)) {
......
...@@ -158,7 +158,7 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -158,7 +158,7 @@ class DB2Statement implements \IteratorAggregate, Statement
*/ */
public function getIterator() public function getIterator()
{ {
$data = $this->fetchAll($this->_defaultFetchStyle); $data = $this->fetchAll();
return new \ArrayIterator($data); return new \ArrayIterator($data);
} }
...@@ -185,7 +185,6 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -185,7 +185,6 @@ class DB2Statement implements \IteratorAggregate, Statement
*/ */
public function fetchAll($fetchStyle = null) public function fetchAll($fetchStyle = null)
{ {
$fetchStyle = $fetchStyle ?: $this->_defaultFetchStyle;
$rows = array(); $rows = array();
while ($row = $this->fetch($fetchStyle)) { while ($row = $this->fetch($fetchStyle)) {
$rows[] = $row; $rows[] = $row;
......
...@@ -253,18 +253,18 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -253,18 +253,18 @@ class MysqliStatement implements \IteratorAggregate, Statement
{ {
$fetchStyle = $fetchStyle ?: $this->_defaultFetchStyle; $fetchStyle = $fetchStyle ?: $this->_defaultFetchStyle;
$a = array(); $rows = array();
if (PDO::FETCH_COLUMN == $fetchStyle) { if (PDO::FETCH_COLUMN == $fetchStyle) {
while (($value = $this->fetchColumn()) !== false) { while (($row = $this->fetchColumn()) !== false) {
$a[] = $value; $rows[] = $row;
} }
} else { } else {
while (($row = $this->fetch($fetchStyle)) !== null) { while (($row = $this->fetch($fetchStyle)) !== null) {
$a[] = $row; $rows[] = $row;
} }
} }
return $a; return $rows;
} }
/** /**
...@@ -336,7 +336,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -336,7 +336,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/ */
public function getIterator() public function getIterator()
{ {
$data = $this->fetchAll($this->_defaultFetchStyle); $data = $this->fetchAll();
return new \ArrayIterator($data); return new \ArrayIterator($data);
} }
} }
...@@ -79,7 +79,7 @@ class OCI8Connection implements \Doctrine\DBAL\Driver\Connection ...@@ -79,7 +79,7 @@ class OCI8Connection implements \Doctrine\DBAL\Driver\Connection
{ {
$args = func_get_args(); $args = func_get_args();
$sql = $args[0]; $sql = $args[0];
//$fetchMode = $args[1]; //$fetchStyle = $args[1];
$stmt = $this->prepare($sql); $stmt = $this->prepare($sql);
$stmt->execute(); $stmt->execute();
return $stmt; return $stmt;
......
...@@ -200,7 +200,7 @@ class OCI8Statement implements \IteratorAggregate, Statement ...@@ -200,7 +200,7 @@ class OCI8Statement implements \IteratorAggregate, Statement
*/ */
public function getIterator() public function getIterator()
{ {
$data = $this->fetchAll($this->_defaultFetchStyle); $data = $this->fetchAll();
return new \ArrayIterator($data); return new \ArrayIterator($data);
} }
......
...@@ -64,7 +64,7 @@ interface ResultStatement extends \Traversable ...@@ -64,7 +64,7 @@ interface ResultStatement extends \Traversable
* *
* @return mixed * @return mixed
*/ */
function fetch($fetchStyle = PDO::FETCH_BOTH); function fetch($fetchStyle = null);
/** /**
* Returns an array containing all of the result set rows * Returns an array containing all of the result set rows
...@@ -75,7 +75,7 @@ interface ResultStatement extends \Traversable ...@@ -75,7 +75,7 @@ interface ResultStatement extends \Traversable
* *
* @return array * @return array
*/ */
function fetchAll($fetchStyle = PDO::FETCH_BOTH); function fetchAll($fetchStyle = null);
/** /**
* fetchColumn * fetchColumn
......
...@@ -185,7 +185,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -185,7 +185,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/ */
public function getIterator() public function getIterator()
{ {
$data = $this->fetchAll($this->defaultFetchStyle); $data = $this->fetchAll();
return new \ArrayIterator($data); return new \ArrayIterator($data);
} }
...@@ -194,7 +194,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -194,7 +194,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/ */
public function fetch($fetchStyle = null) public function fetch($fetchStyle = null)
{ {
$fetchStyle = ($fetchStyle)?:$this->defaultFetchStyle; $fetchStyle = $fetchStyle ?: $this->defaultFetchStyle;
if (isset(self::$fetchMap[$fetchStyle])) { if (isset(self::$fetchMap[$fetchStyle])) {
return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchStyle]); return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchStyle]);
} else if ($fetchStyle == PDO::FETCH_OBJ || $fetchStyle == PDO::FETCH_CLASS) { } else if ($fetchStyle == PDO::FETCH_OBJ || $fetchStyle == PDO::FETCH_CLASS) {
......
...@@ -109,12 +109,14 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement ...@@ -109,12 +109,14 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement
public function getIterator() public function getIterator()
{ {
$data = $this->fetchAll($this->defaultFetchStyle); $data = $this->fetchAll();
return new \ArrayIterator($data); return new \ArrayIterator($data);
} }
public function fetch($fetchStyle = PDO::FETCH_BOTH) public function fetch($fetchStyle = null)
{ {
$fetchStyle = $fetchStyle ?: $this->defaultFetchStyle;
$row = $this->stmt->fetch($fetchStyle); $row = $this->stmt->fetch($fetchStyle);
$row = $this->fixRow($row, $row = $this->fixRow($row,
...@@ -125,8 +127,10 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement ...@@ -125,8 +127,10 @@ class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement
return $row; return $row;
} }
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0) public function fetchAll($fetchStyle = null, $columnIndex = 0)
{ {
$fetchStyle = $fetchStyle ?: $this->defaultFetchStyle;
if ($columnIndex != 0) { if ($columnIndex != 0) {
$rows = $this->stmt->fetchAll($fetchStyle, $columnIndex); $rows = $this->stmt->fetchAll($fetchStyle, $columnIndex);
} else { } else {
......
...@@ -201,7 +201,7 @@ class Statement implements \IteratorAggregate, DriverStatement ...@@ -201,7 +201,7 @@ class Statement implements \IteratorAggregate, DriverStatement
* @return mixed The return value of this function on success depends on the fetch type. * @return mixed The return value of this function on success depends on the fetch type.
* In all cases, FALSE is returned on failure. * In all cases, FALSE is returned on failure.
*/ */
public function fetch($fetchStyle = PDO::FETCH_BOTH) public function fetch($fetchStyle = null)
{ {
return $this->stmt->fetch($fetchStyle); return $this->stmt->fetch($fetchStyle);
} }
...@@ -213,7 +213,7 @@ class Statement implements \IteratorAggregate, DriverStatement ...@@ -213,7 +213,7 @@ class Statement implements \IteratorAggregate, DriverStatement
* @param mixed $fetchArgument * @param mixed $fetchArgument
* @return array An array containing all of the remaining rows in the result set. * @return array An array containing all of the remaining rows in the result set.
*/ */
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $fetchArgument = 0) public function fetchAll($fetchStyle = null, $fetchArgument = 0)
{ {
if ($fetchArgument !== 0) { if ($fetchArgument !== 0) {
return $this->stmt->fetchAll($fetchStyle, $fetchArgument); return $this->stmt->fetchAll($fetchStyle, $fetchArgument);
......
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