An implementation of DatabaseStatementInterface that prefetches all data.
Code
publicfunctioncurrent() {
if (isset($this->currentRow)) {
switch ($this->fetchStyle) {
casePDO::FETCH_ASSOC:
return$this->currentRow;
casePDO::FETCH_BOTH:
// PDO::FETCH_BOTH returns an array indexed by both the column name
// and the column number.
return$this->currentRow + array_values($this->currentRow);
casePDO::FETCH_NUM:
returnarray_values($this->currentRow);
casePDO::FETCH_LAZY:
// We do not do lazy as everything is fetched already. Fallback to
// PDO::FETCH_OBJ.
casePDO::FETCH_OBJ:
return(object)$this->currentRow;
casePDO::FETCH_CLASS:
if (!isset($class_name)) {
$class_name = $this->fetchOptions['class'];
}
if (count($this->fetchOptions['constructor_args'])) {
// Verify the current db connection to avoid this code being called
// in an inappropriate context.
$db_connection_options = Database::getConnection()->getConnectionOptions();
$valid_db_drivers = array('sqlite', 'oracle');
if (!in_array($db_connection_options['driver'], $valid_db_drivers)) {
throw newBadMethodCallException();
}
$reflector = newReflectionClass($class_name);
$result = $reflector->newInstanceArgs($this->fetchOptions['constructor_args']);
}
else {
$result = new$class_name();
}
foreach ($this->currentRowas$k => $v) {
$result->$k = $v;
}
return$result;
casePDO::FETCH_INTO:
foreach ($this->currentRowas$k => $v) {
$this->fetchOptions['object']->$k = $v;
}
return$this->fetchOptions['object'];
casePDO::FETCH_COLUMN:
if (isset($this->columnNames[$this->fetchOptions['column']])) {
return$this->currentRow[$this->columnNames[$this->fetchOptions['column']]];
}
else {
returnNULL;
}
}
}
returnNULL;
}