Skip to content

Commit bc23831

Browse files
committed
Implemented Statement::fetch(PDO::FETCH_COLUMN) in non-PDO driveres
Fixes #2953.
1 parent 8575c25 commit bc23831

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
216216

217217
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
218218
switch ($fetchMode) {
219+
case \PDO::FETCH_COLUMN:
220+
return $this->fetchColumn();
221+
219222
case \PDO::FETCH_BOTH:
220223
return db2_fetch_both($this->_stmt);
221224
case \PDO::FETCH_ASSOC:

lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
272272
return false;
273273
}
274274

275+
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
276+
277+
if ($fetchMode === PDO::FETCH_COLUMN) {
278+
return $this->fetchColumn();
279+
}
280+
275281
$values = $this->_fetch();
276282
if (null === $values) {
277283
return false;
@@ -281,8 +287,6 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
281287
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
282288
}
283289

284-
$fetchMode = $fetchMode ?: $this->_defaultFetchMode;
285-
286290
switch ($fetchMode) {
287291
case PDO::FETCH_NUM:
288292
return $values;

lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
387387

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

390+
if ($fetchMode === PDO::FETCH_COLUMN) {
391+
return $this->fetchColumn();
392+
}
393+
390394
if (PDO::FETCH_OBJ == $fetchMode) {
391395
return oci_fetch_object($this->_sth);
392396
}

lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
203203
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
204204

205205
switch ($fetchMode) {
206+
case PDO::FETCH_COLUMN:
207+
return $this->fetchColumn();
208+
206209
case PDO::FETCH_ASSOC:
207210
return sasql_fetch_assoc($this->result);
208211
case PDO::FETCH_BOTH:

lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX
315315
$args = func_get_args();
316316
$fetchMode = $fetchMode ?: $this->defaultFetchMode;
317317

318+
if ($fetchMode === PDO::FETCH_COLUMN) {
319+
return $this->fetchColumn();
320+
}
321+
318322
if (isset(self::$fetchMap[$fetchMode])) {
319323
return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]) ?: false;
320324
}

tests/Doctrine/Tests/DBAL/Functional/StatementTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,13 @@ function (Statement $stmt) {
282282
),
283283
);
284284
}
285+
286+
public function testFetchInColumnMode() : void
287+
{
288+
$platform = $this->_conn->getDatabasePlatform();
289+
$query = $platform->getDummySelectSQL();
290+
$result = $this->_conn->executeQuery($query)->fetch(\PDO::FETCH_COLUMN);
291+
292+
self::assertEquals(1, $result);
293+
}
285294
}

0 commit comments

Comments
 (0)