Skip to content

Commit

Permalink
Simplify code in AkibanSrvStatement class.
Browse files Browse the repository at this point in the history
  • Loading branch information
posulliv committed Aug 23, 2012
1 parent af2cc93 commit 0eef622
Showing 1 changed file with 30 additions and 52 deletions.
82 changes: 30 additions & 52 deletions lib/Doctrine/DBAL/Driver/AkibanSrv/AkibanSrvStatement.php
Expand Up @@ -212,38 +212,26 @@ public function getIterator()
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetch($fetchMode = null, $rowPos = 0) public function fetch($fetchMode = null, $rowPos = NULL)
{ {
$fetchMode = $fetchMode ? : $this->_defaultFetchMode; $fetchMode = $fetchMode ? : $this->_defaultFetchMode;


if ( ! isset(self::$fetchModeMap[$fetchMode])) { if (! isset(self::$fetchModeMap[$fetchMode])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchMode); throw new \InvalidArgumentException("Invalid fetch style: " . $fetchMode);
} }


if ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) { if ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) {
if ($this->_results && $this->_className) { if ($this->_results && $this->_className) {
if (empty($this->_ctorArgs)) { if (empty($this->_ctorArgs)) {
if ($rowPos != 0) { return pg_fetch_object($this->_results, $rowPos, $this->_className);
return pg_fetch_object($this->_results, $rowPos, $this->_className);
} else {
return pg_fetch_object($this->_results, NULL, $this->_className);
}
} else { } else {
if ($rowPos != 0) { return pg_fetch_object($this->_results, $rowPos, $this->_className, $this->_ctorArgs);
return pg_fetch_object($this->_results, $rowPos, $this->_className, $this->_ctorArgs);
} else {
return pg_fetch_object($this->_results, NULL, $this->_className, $this->_ctorArgs);
}
} }
} }
} }


if ($this->_results) { if ($this->_results) {
if ($rowPos == 0) { return pg_fetch_array($this->_results, $rowPos, self::$fetchModeMap[$fetchMode]);
return pg_fetch_array($this->_results, NULL, self::$fetchModeMap[$fetchMode]);
} else {
return pg_fetch_array($this->_results, $rowPos, self::$fetchModeMap[$fetchMode]);
}
} }


return false; return false;
Expand All @@ -256,10 +244,12 @@ public function fetchAll($fetchMode = null)
{ {
$fetchMode = $fetchMode ? : $this->_defaultFetchMode; $fetchMode = $fetchMode ? : $this->_defaultFetchMode;


if ( ! isset(self::$fetchModeMap[$fetchMode])) { if (! isset(self::$fetchModeMap[$fetchMode])) {
throw new \InvalidArgumentException("Invalid fetch mode: " . $fetchMode); throw new \InvalidArgumentException("Invalid fetch mode: " . $fetchMode);
} }


$result = array();

if ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) { if ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) {
$className = null; $className = null;
$ctorArgs = null; $ctorArgs = null;
Expand All @@ -268,39 +258,31 @@ public function fetchAll($fetchMode = null)
$this->_className = $args[1]; $this->_className = $args[1];
$this->_ctorArgs = (isset($args[2])) ? $args[2] : array(); $this->_ctorArgs = (isset($args[2])) ? $args[2] : array();
} }
if ($this->_results && $this->_className) { for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
if (empty($this->_ctorArgs)) { $result[] = $this->fetch($fetchMode, $i);
return pg_fetch_object($this->_results, 0, $this->_className);
} else {
return pg_fetch_object($this->_results, 0, $this->_className, $this->_ctorArgs);
}
} }
return $result;
} }


if ($this->_results) { if (self::$fetchModeMap[$fetchMode] == PGSQL_BOTH) {
$result = array(); for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
if (self::$fetchModeMap[$fetchMode] == PGSQL_BOTH) { $result[] = $this->fetch($fetchMode, $i);
for ($i = 0; $i < pg_num_rows($this->_results); $i++) { }
$row = $this->fetch($fetchMode, $i); return $result;
$result[] = $row; } else if (self::$fetchModeMap[$fetchMode] == PGSQL_NUM) {
} for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
return $result; $result[] = $this->fetch($fetchMode, $i);
} else if (self::$fetchModeMap[$fetchMode] == PGSQL_NUM) { }
for ($i = 0; $i < pg_num_rows($this->_results); $i++) { return $result;
$row = $this->fetch($fetchMode, $i); } else if ($fetchMode == PDO::FETCH_COLUMN) {
$result[] = $row; for ($i = 0; $i < pg_num_rows($this->_results); $i++) {
} for ($col = 0; $col < $this->columnCount(); $col++) {
return $result; $result[] = $this->fetchColumn($col, $i);
} else if ($fetchMode == 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);
} }
return $result;
} else {
return pg_fetch_all($this->_results);
} }


return false; return false;
Expand All @@ -309,14 +291,10 @@ public function fetchAll($fetchMode = null)
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function fetchColumn($columnIndex = 0, $rowPos = 0) public function fetchColumn($columnIndex = 0, $rowPos = NULL)
{ {
if ($this->_results) { if ($this->_results) {
if ($rowPos != 0) { $row = pg_fetch_array($this->_results, $rowPos, PGSQL_NUM);
$row = pg_fetch_array($this->_results, $rowPos, PGSQL_NUM);
} else {
$row = pg_fetch_array($this->_results, NULL, PGSQL_NUM);
}
return isset($row[$columnIndex]) ? $row[$columnIndex] : false; return isset($row[$columnIndex]) ? $row[$columnIndex] : false;
} }
return false; return false;
Expand Down

0 comments on commit 0eef622

Please sign in to comment.