]> git.mjollnir.org Git - moodle.git/commitdiff
More debugging/checking on get_record_sql
authormoodler <moodler>
Wed, 23 Jul 2003 06:30:26 +0000 (06:30 +0000)
committermoodler <moodler>
Wed, 23 Jul 2003 06:30:26 +0000 (06:30 +0000)
lib/datalib.php

index a4dfa9a035669543a6f7837734b3adf13c36d10e..df060091eb012546a48b87659b136f85cdb8f90d 100644 (file)
@@ -311,22 +311,33 @@ function get_record_sql($sql) {
        $limit = " LIMIT 1";    // Workaround - limit to one record
     }
 
-    $rs = $db->Execute("$sql$limit");
+    if (!$rs = $db->Execute("$sql$limit")) {
+        if ($CFG->debug > 7) {    // Debugging mode - print checks
+            $db->debug=true;
+            $db->Execute("$sql$limit");
+            $db->debug=false;
+        }
+        return false;
+    }
 
-    if (empty($rs)) {
-        return false;    // Nothing found
+    if (!$recordcount = $rs->RecordCount()) {
+        return false;                 // Found no records
     }
 
-    if ( $rs->RecordCount() == 1 ) { // Found one record
+    if ($recordcount == 1) {          // Found one record
         return (object)$rs->fields;
 
-    } else {                         // Error: found more than one record
+    } else {                          // Error: found more than one record
+        notify("Error:  Turn off debugging to hide this error.");
+        notify("$sql$limit");
         if ($records = $rs->GetAssoc(true)) {
+            notify("Found more than one record in get_record_sql !");
             print_object($records);
-            notice("Found more than one record in get_record_sql() !");
         } else {
-            notice("Very strange error in get_record_sql() !");
+            notify("Very strange error in get_record_sql !");
+            print_object($rs);
         }
+        print_continue("$CFG->wwwroot/admin/config.php");
     }
 }