]> git.mjollnir.org Git - moodle.git/commitdiff
Added some additional error checking of get_record_sql when in debug mode
authormoodler <moodler>
Wed, 23 Jul 2003 04:33:40 +0000 (04:33 +0000)
committermoodler <moodler>
Wed, 23 Jul 2003 04:33:40 +0000 (04:33 +0000)
lib/datalib.php

index 9c63d1a7ff26f8874803b892100d02de00855a29..a4dfa9a035669543a6f7837734b3adf13c36d10e 100644 (file)
@@ -301,17 +301,32 @@ function get_record($table, $field1, $value1, $field2="", $value2="", $field3=""
 function get_record_sql($sql) {
 /// Get a single record as an object
 /// The sql statement is provided as a string.
-/// A LIMIT is added to keep limit the returned records to 1
+/// A LIMIT is normally added to only look for 1 record
 
-    global $db;
+    global $db, $CFG;
 
-    $rs = $db->Execute("$sql LIMIT 1");
-    if (empty($rs)) return false;
+    if ($CFG->debug > 7) {    // Debugging mode - don't use limit
+       $limit = "";
+    } else {
+       $limit = " LIMIT 1";    // Workaround - limit to one record
+    }
 
-    if ( $rs->RecordCount() == 1 ) {
+    $rs = $db->Execute("$sql$limit");
+
+    if (empty($rs)) {
+        return false;    // Nothing found
+    }
+
+    if ( $rs->RecordCount() == 1 ) { // Found one record
         return (object)$rs->fields;
-    } else {
-        return false;
+
+    } else {                         // Error: found more than one record
+        if ($records = $rs->GetAssoc(true)) {
+            print_object($records);
+            notice("Found more than one record in get_record_sql() !");
+        } else {
+            notice("Very strange error in get_record_sql() !");
+        }
     }
 }