Skip to content

Commit

Permalink
(split)- Patch #742042 by kkaefer:DBTNG: ->fetchAllAssoc() doesn't re…
Browse files Browse the repository at this point in the history
…spect fetch mode set during ->execute().
  • Loading branch information
dries committed Apr 30, 2010
1 parent 7b3bdad commit ff4fda2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
28 changes: 16 additions & 12 deletions database.inc
Expand Up @@ -1916,12 +1916,13 @@ interface DatabaseStatementInterface extends Traversable {
* @param $fetch
* The fetchmode to use. If set to PDO::FETCH_ASSOC, PDO::FETCH_NUM, or
* PDO::FETCH_BOTH the returned value with be an array of arrays. For any
* other value it will be an array of objects.
* other value it will be an array of objects. By default, the fetch mode
* set for the query will be used.
*
* @return
* An associative array.
*/
public function fetchAllAssoc($key, $fetch = PDO::FETCH_OBJ);
public function fetchAllAssoc($key, $fetch = NULL);
}

/**
Expand Down Expand Up @@ -1987,19 +1988,22 @@ class DatabaseStatementBase extends PDOStatement implements DatabaseStatementInt
return $this->fetchAll(PDO::FETCH_COLUMN, $index);
}

public function fetchAllAssoc($key, $fetch = PDO::FETCH_OBJ) {
public function fetchAllAssoc($key, $fetch = NULL) {
$return = array();
$this->setFetchMode($fetch);
if (in_array($fetch, array(PDO::FETCH_ASSOC, PDO::FETCH_NUM, PDO::FETCH_BOTH))) {
foreach ($this as $record) {
$return[$record[$key]] = $record;
if (isset($fetch)) {
if (is_string($fetch)) {
$this->setFetchMode(PDO::FETCH_CLASS, $fetch);
}
}
else {
foreach ($this as $record) {
$return[$record->$key] = $record;
else {
$this->setFetchMode($fetch);
}
}

foreach ($this as $record) {
$record_key = is_object($record) ? $record->$key : $record[$key];
$return[$record_key] = $record;
}

return $return;
}

Expand Down Expand Up @@ -2080,7 +2084,7 @@ class DatabaseStatementEmpty implements Iterator, DatabaseStatementInterface {
return array();
}

public function fetchAllAssoc($key, $fetch = PDO::FETCH_OBJ) {
public function fetchAllAssoc($key, $fetch = NULL) {
return array();
}

Expand Down
4 changes: 2 additions & 2 deletions prefetch.inc
Expand Up @@ -475,8 +475,8 @@ class DatabaseStatementPrefetch implements Iterator, DatabaseStatementInterface
return $result;
}

public function fetchAllAssoc($key, $fetch_style = PDO::FETCH_OBJ) {
$this->fetchStyle = $fetch_style;
public function fetchAllAssoc($key, $fetch_style = NULL) {
$this->fetchStyle = isset($fetch_style) ? $fetch_style : $this->defaultFetchStyle;
$this->fetchOptions = $this->defaultFetchOptions;

$result = array();
Expand Down

0 comments on commit ff4fda2

Please sign in to comment.