From 758ba89a63975b312e7d10340a06bd7b7739580a Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 21 Nov 2008 22:35:21 +0000 Subject: [PATCH] MDL-17347 reintroduced duplicate tests in get_records_sql() --- lib/dml/adodb_moodle_database.php | 8 +++++--- lib/dml/mysqli_native_moodle_database.php | 4 ++++ lib/dml/pgsql_native_moodle_database.php | 4 ++++ lib/dml/simpletest/testdml.php | 7 +++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/dml/adodb_moodle_database.php b/lib/dml/adodb_moodle_database.php index c729cc06a0..cf0608be70 100644 --- a/lib/dml/adodb_moodle_database.php +++ b/lib/dml/adodb_moodle_database.php @@ -444,11 +444,13 @@ abstract class adodb_moodle_database extends moodle_database { 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()) { diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index 28e39d263c..03edbc3861 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -492,6 +492,10 @@ class mysqli_native_moodle_database extends moodle_database { 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(); diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php index b433b18997..c6eb6b1e84 100644 --- a/lib/dml/pgsql_native_moodle_database.php +++ b/lib/dml/pgsql_native_moodle_database.php @@ -601,6 +601,10 @@ class pgsql_native_moodle_database extends moodle_database { $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; } } diff --git a/lib/dml/simpletest/testdml.php b/lib/dml/simpletest/testdml.php index 8a50af326c..f52439f17c 100755 --- a/lib/dml/simpletest/testdml.php +++ b/lib/dml/simpletest/testdml.php @@ -717,6 +717,13 @@ class dml_test extends UnitTestCase { $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() { -- 2.39.5