Implemented Statement::fetch(PDO::FETCH_COLUMN) in non-PDO driveres

Fixes #2953.
parent 8575c255
...@@ -216,6 +216,9 @@ class DB2Statement implements \IteratorAggregate, Statement ...@@ -216,6 +216,9 @@ class DB2Statement implements \IteratorAggregate, Statement
$fetchMode = $fetchMode ?: $this->_defaultFetchMode; $fetchMode = $fetchMode ?: $this->_defaultFetchMode;
switch ($fetchMode) { switch ($fetchMode) {
case \PDO::FETCH_COLUMN:
return $this->fetchColumn();
case \PDO::FETCH_BOTH: case \PDO::FETCH_BOTH:
return db2_fetch_both($this->_stmt); return db2_fetch_both($this->_stmt);
case \PDO::FETCH_ASSOC: case \PDO::FETCH_ASSOC:
......
...@@ -272,6 +272,12 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -272,6 +272,12 @@ class MysqliStatement implements \IteratorAggregate, Statement
return false; return false;
} }
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
if ($fetchMode === PDO::FETCH_COLUMN) {
return $this->fetchColumn();
}
$values = $this->_fetch(); $values = $this->_fetch();
if (null === $values) { if (null === $values) {
return false; return false;
...@@ -281,8 +287,6 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -281,8 +287,6 @@ class MysqliStatement implements \IteratorAggregate, Statement
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
} }
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
switch ($fetchMode) { switch ($fetchMode) {
case PDO::FETCH_NUM: case PDO::FETCH_NUM:
return $values; return $values;
......
...@@ -387,6 +387,10 @@ class OCI8Statement implements IteratorAggregate, Statement ...@@ -387,6 +387,10 @@ class OCI8Statement implements IteratorAggregate, Statement
$fetchMode = $fetchMode ?: $this->_defaultFetchMode; $fetchMode = $fetchMode ?: $this->_defaultFetchMode;
if ($fetchMode === PDO::FETCH_COLUMN) {
return $this->fetchColumn();
}
if (PDO::FETCH_OBJ == $fetchMode) { if (PDO::FETCH_OBJ == $fetchMode) {
return oci_fetch_object($this->_sth); return oci_fetch_object($this->_sth);
} }
......
...@@ -203,6 +203,9 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement ...@@ -203,6 +203,9 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$fetchMode = $fetchMode ?: $this->defaultFetchMode; $fetchMode = $fetchMode ?: $this->defaultFetchMode;
switch ($fetchMode) { switch ($fetchMode) {
case PDO::FETCH_COLUMN:
return $this->fetchColumn();
case PDO::FETCH_ASSOC: case PDO::FETCH_ASSOC:
return sasql_fetch_assoc($this->result); return sasql_fetch_assoc($this->result);
case PDO::FETCH_BOTH: case PDO::FETCH_BOTH:
......
...@@ -315,6 +315,10 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -315,6 +315,10 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$args = func_get_args(); $args = func_get_args();
$fetchMode = $fetchMode ?: $this->defaultFetchMode; $fetchMode = $fetchMode ?: $this->defaultFetchMode;
if ($fetchMode === PDO::FETCH_COLUMN) {
return $this->fetchColumn();
}
if (isset(self::$fetchMap[$fetchMode])) { if (isset(self::$fetchMap[$fetchMode])) {
return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]) ?: false; return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]) ?: false;
} }
......
...@@ -282,4 +282,13 @@ EOF ...@@ -282,4 +282,13 @@ EOF
), ),
); );
} }
public function testFetchInColumnMode() : void
{
$platform = $this->_conn->getDatabasePlatform();
$query = $platform->getDummySelectSQL();
$result = $this->_conn->executeQuery($query)->fetch(\PDO::FETCH_COLUMN);
self::assertEquals(1, $result);
}
} }
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