From: moodler Date: Wed, 23 Jul 2003 04:33:40 +0000 (+0000) Subject: Added some additional error checking of get_record_sql when in debug mode X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4d7a373539255686a980be06fb54248f6da260bd;p=moodle.git Added some additional error checking of get_record_sql when in debug mode --- diff --git a/lib/datalib.php b/lib/datalib.php index 9c63d1a7ff..a4dfa9a035 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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() !"); + } } }