ENHANCMENT: Low-level performance improvements in database access.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84163 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-08-11 08:51:05 +00:00
parent 2b7572e21a
commit 07871f81e1
2 changed files with 12 additions and 22 deletions

View File

@ -711,10 +711,11 @@ abstract class Query implements Iterator {
public function column($column = null) {
$result = array();
foreach($this as $record) {
$result[] = ($column) ? $record[$column] : reset($record);
while($record = $this->next()) {
if($column) $result[] = $record[$column];
else $result[] = $record[key($record)];
}
return $result;
}
@ -726,7 +727,7 @@ abstract class Query implements Iterator {
public function keyedColumn() {
$column = array();
foreach($this as $record) {
$val = reset($record);
$val = $record[key($record)];
$column[$val] = $val;
}
return $column;
@ -759,9 +760,8 @@ abstract class Query implements Iterator {
* @return string
*/
public function value() {
foreach($this as $record) {
return reset($record);
}
$record = $this->next();
if($record) return $record[key($record)];
}
/**
@ -851,7 +851,8 @@ abstract class Query implements Iterator {
* @return boolean
*/
public function valid() {
return $this->current() !== false;
if(!$this->currentRecord) $this->next();
return $this->currentRecord !== false;
}
/**

View File

@ -893,20 +893,9 @@ class MySQLQuery extends Query {
}
public function nextRecord() {
// Coalesce rather than replace common fields.
if($data = mysql_fetch_row($this->handle)) {
foreach($data as $columnIdx => $value) {
$columnName = mysql_field_name($this->handle, $columnIdx);
// $value || !$ouput[$columnName] means that the *last* occurring value is shown
// !$ouput[$columnName] means that the *first* occurring value is shown
if(isset($value) || !isset($output[$columnName])) {
$output[$columnName] = $value;
}
}
return $output;
} else {
return false;
}
$data = mysql_fetch_assoc($this->handle);
if(!$data) $data = false;
return $data;
}