Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up code in AkibanSrvStatement class around fetching of results.

  • Loading branch information...
commit 1aa82786f9e9a1bb4673a2ed86bf6a110093ebc0 1 parent 0eef622
@posulliv authored
Showing with 24 additions and 22 deletions.
  1. +24 −22 lib/Doctrine/DBAL/Driver/AkibanSrv/AkibanSrvStatement.php
View
46 lib/Doctrine/DBAL/Driver/AkibanSrv/AkibanSrvStatement.php
@@ -117,6 +117,15 @@ private function convertPositionalToNumberedParameters($statement)
return $statement;
}
+ private function fetchRows($fetchMode)
+ {
+ $result = array();
+ for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
+ $result[] = $this->fetch($fetchMode, $i);
+ }
+ return $result;
+ }
+
/**
* {@inheritdoc}
*/
@@ -250,7 +259,9 @@ public function fetchAll($fetchMode = null)
$result = array();
- if ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) {
+ switch ($fetchMode) {
+ case PDO::FETCH_OBJ:
+ case PDO::FETCH_CLASS:
$className = null;
$ctorArgs = null;
if (func_num_args() >= 2) {
@@ -258,34 +269,25 @@ public function fetchAll($fetchMode = null)
$this->_className = $args[1];
$this->_ctorArgs = (isset($args[2])) ? $args[2] : array();
}
- for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
- $result[] = $this->fetch($fetchMode, $i);
- }
- return $result;
- }
-
- if (self::$fetchModeMap[$fetchMode] == PGSQL_BOTH) {
- for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
- $result[] = $this->fetch($fetchMode, $i);
- }
- return $result;
- } else if (self::$fetchModeMap[$fetchMode] == PGSQL_NUM) {
- for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
- $result[] = $this->fetch($fetchMode, $i);
- }
- return $result;
- } else if ($fetchMode == PDO::FETCH_COLUMN) {
+ $result = $this->fetchRows($fetchMode);
+ break;
+ case PDO::FETCH_BOTH:
+ case PDO::FETCH_NUM:
+ $result = $this->fetchRows($fetchMode);
+ break;
+ case PDO::FETCH_COLUMN:
for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
for ($col = 0; $col < $this->columnCount(); $col++) {
$result[] = $this->fetchColumn($col, $i);
}
}
- return $result;
- } else {
- return pg_fetch_all($this->_results);
+ break;
+ default:
+ $result = pg_fetch_all($this->_results);
+ break;
}
- return false;
+ return empty($result) ? false : $result;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.