Skip to content

Commit

Permalink
optimize Select::fetchRow() and Select::fetchOne(), remove useless
Browse files Browse the repository at this point in the history
DataObjectCluster.php
  • Loading branch information
shen2 committed May 28, 2015
1 parent 50cb996 commit f208f47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 63 deletions.
46 changes: 0 additions & 46 deletions src/DataObjectCluster.php

This file was deleted.

27 changes: 10 additions & 17 deletions src/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -1286,27 +1286,20 @@ public function fetchClass($class, $ctor_args = array()){
* Fetches the first row of the SQL result.
* Uses the current fetchMode for the adapter.
*
* @param mixed $fetchMode Override current fetch mode.
* @return array|DataObject
*/
public function fetchRow($fetchMode = null)
public function fetchRow()
{
if (isset($this->_table)){
$this->_parts[self::LIMIT_COUNT] = 1;

$result = $this->_adapter->query($this->assemble());

if ($result->num_rows == 0){
return null;
}

$this->_parts[self::LIMIT_COUNT] = 1;
$result = $this->_adapter->newStatement($this)->getResult();
$data = $result->fetch_assoc();

if (isset($this->_table) && $data !== null){
$rowClass = $this->_table;

return new $rowClass($result->fetch_assoc(), true, $this->isReadOnly());
return new $rowClass($data, true, $this->isReadOnly());
}

$result = $this->_adapter->query($this->assemble());
return $result->fetch_assoc();
return $data;
}

/**
Expand All @@ -1316,8 +1309,8 @@ public function fetchRow($fetchMode = null)
*/
public function fetchOne()
{
$result = $this->_adapter->query($this->assemble());
$row = $result->fetch_array(\MYSQLI_NUM);
$result = $this->_adapter->newStatement($this)->getResult();
$row = $result->fetch_row();
return $row === null ? null : $row[0];
}

Expand Down

0 comments on commit f208f47

Please sign in to comment.