Merge branch 'MDL-66327-master' of git://github.com/andrewnicols/moodle

This commit is contained in:
Adrian Greeve 2019-08-19 10:32:39 +08:00
commit ee8f44db8c

View file

@ -842,8 +842,7 @@ class pgsql_native_moodle_database extends moodle_database {
* @return array of objects, or empty array if no records were found * @return array of objects, or empty array if no records were found
* @throws dml_exception A DML specific exception is thrown for any errors. * @throws dml_exception A DML specific exception is thrown for any errors.
*/ */
public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0) { public function get_records_sql($sql, array $params = null, $limitfrom = 0, $limitnum = 0) {
list($limitfrom, $limitnum) = $this->normalise_limit_from_num($limitfrom, $limitnum); list($limitfrom, $limitnum) = $this->normalise_limit_from_num($limitfrom, $limitnum);
if ($limitnum) { if ($limitnum) {
@ -868,24 +867,19 @@ class pgsql_native_moodle_database extends moodle_database {
} }
} }
$rows = pg_fetch_all($result); $return = [];
pg_free_result($result); while ($row = pg_fetch_assoc($result)) {
$id = reset($row);
$return = array(); if ($blobs) {
if ($rows) { foreach ($blobs as $blob) {
foreach ($rows as $row) { $row[$blob] = ($row[$blob] !== null ? pg_unescape_bytea($row[$blob]) : null);
$id = reset($row);
if ($blobs) {
foreach ($blobs as $blob) {
$row[$blob] = ($row[$blob] !== null ? pg_unescape_bytea($row[$blob]) : null);
}
} }
if (isset($return[$id])) {
$colname = key($row);
debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate value '$id' found in column '$colname'.", DEBUG_DEVELOPER);
}
$return[$id] = (object)$row;
} }
if (isset($return[$id])) {
$colname = key($row);
debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate value '$id' found in column '$colname'.", DEBUG_DEVELOPER);
}
$return[$id] = (object) $row;
} }
return $return; return $return;