Skip to content

Commit

Permalink
Implemented Statement::fetch(PDO::FETCH_COLUMN) in non-PDO driveres
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jan 5, 2018
1 parent a5d3e33 commit 2b3c899
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE

$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
switch ($fetchMode) {
case \PDO::FETCH_COLUMN:
return $this->fetchColumn();

case \PDO::FETCH_BOTH:
return db2_fetch_both($this->_stmt);
case \PDO::FETCH_ASSOC:
Expand Down
8 changes: 6 additions & 2 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
return false;
}

$fetchMode = $fetchMode ?: $this->_defaultFetchMode;

if ($fetchMode == PDO::FETCH_COLUMN) {
return $this->fetchColumn();
}

$values = $this->_fetch();
if (null === $values) {
return false;
Expand All @@ -281,8 +287,6 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
}

$fetchMode = $fetchMode ?: $this->_defaultFetchMode;

switch ($fetchMode) {
case PDO::FETCH_NUM:
return $values;
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE

$fetchMode = $fetchMode ?: $this->_defaultFetchMode;

if ($fetchMode == PDO::FETCH_COLUMN) {
return $this->fetchColumn();
}

if (PDO::FETCH_OBJ == $fetchMode) {
return oci_fetch_object($this->_sth);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
$fetchMode = $fetchMode ?: $this->defaultFetchMode;

switch ($fetchMode) {
case PDO::FETCH_COLUMN:
return $this->fetchColumn();

case PDO::FETCH_ASSOC:
return sasql_fetch_assoc($this->result);
case PDO::FETCH_BOTH:
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX
$args = func_get_args();
$fetchMode = $fetchMode ?: $this->defaultFetchMode;

if ($fetchMode == PDO::FETCH_COLUMN) {
return $this->fetchColumn();
}

if (isset(self::$fetchMap[$fetchMode])) {
return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]) ?: false;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,13 @@ function (Statement $stmt) {
),
);
}

public function testFetchInColumnMode()
{
$platform = $this->_conn->getDatabasePlatform();
$query = $platform->getDummySelectSQL();
$result = $this->_conn->executeQuery($query)->fetch(\PDO::FETCH_COLUMN);

self::assertEquals(1, $result);
}
}

0 comments on commit 2b3c899

Please sign in to comment.