]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17347 reintroduced duplicate tests in get_records_sql()
authorskodak <skodak>
Fri, 21 Nov 2008 22:35:21 +0000 (22:35 +0000)
committerskodak <skodak>
Fri, 21 Nov 2008 22:35:21 +0000 (22:35 +0000)
lib/dml/adodb_moodle_database.php
lib/dml/mysqli_native_moodle_database.php
lib/dml/pgsql_native_moodle_database.php
lib/dml/simpletest/testdml.php

index c729cc06a0173cf08f23568aaa02720db3110f69..cf0608be70e5827e8377271bcc7a76796747a8df 100644 (file)
@@ -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()) {
index 28e39d263cd17b9edd342503dfc331ab86fda5f6..03edbc38610ed413a4c23a13944d7521136dfcf0 100644 (file)
@@ -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();
index b433b1899764dfe5a239c12a42038b1406740091..c6eb6b1e8497d9d7f8f9f3def6fdbc125b341b7d 100644 (file)
@@ -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;
             }
         }
index 8a50af326c5547c6a034ab2485ec6c10bb397bc8..f52439f17cc42d8c1da8258614d21e261a2bc1a4 100755 (executable)
@@ -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() {