if ($records = $rs->GetAssoc(true)) {
foreach ($records as $key => $record) {
$record = array($firstcolumn->name=>$key) + $record; /// Re-add the assoc field (as FIRST element since 2.0)
- if ($debugging && array_key_exists($key, $objects)) {
- debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate value '$key' found in column '".$firstcolumn->name."'.", DEBUG_DEVELOPER);
- }
$objects[$key] = (object) $record; /// To object
}
+ if ($debugging) {
+ if (count($objects) != $rs->_numOfRows) {
+ debugging("Did you remember to make the first column something unique in your call to get_records? Duplicate values found in column '".$firstcolumn->name."'.", DEBUG_DEVELOPER);
+ }
+ }
return $objects;
/// Fallback in case we only have 1 field in the recordset. MDL-5877
} else if ($rs->_numOfFields == 1 and $records = $rs->GetRows()) {
while($row = $result->fetch_assoc()) {
$row = array_change_key_case($row, CASE_LOWER);
$id = reset($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;
}
$result->close();
$row[$blob] = pg_unescape_bytea($row[$blob]);
}
}
+ 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;
}
}
$this->assertEqual(1, reset($records)->id);
$this->assertEqual(2, next($records)->id);
+ ob_start(); // hide debug warning
+ $records = $DB->get_records_sql('SELECT course AS id, course AS course FROM {testtable} ', null);
+ $debuginfo = ob_get_contents();
+ ob_end_clean();
+
+ $this->assertEqual(3, count($records));
+ $this->assertFalse($debuginfo === '');
}
public function test_get_records_menu() {