From: moodler Date: Thu, 19 Jun 2003 02:18:51 +0000 (+0000) Subject: Add LIMIT of 1 to get_record functions ... the behaviour of returning false X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dc7e8cb582ab3010a2c37444a10ddd4a3aa02667;p=moodle.git Add LIMIT of 1 to get_record functions ... the behaviour of returning false when there were more than one record returned was sometimes causing problems if the data was unclean due to a bug somewhere. For example, if there are two copies of a section, then Moodle keeps creating new ones because it can't find ONE. This fix prevents that. --- diff --git a/lib/datalib.php b/lib/datalib.php index 4599ef7ebd..2663acf56a 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -301,10 +301,11 @@ 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 global $db; - $rs = $db->Execute("$sql"); + $rs = $db->Execute("$sql LIMIT 1"); if (empty($rs)) return false; if ( $rs->RecordCount() == 1 ) {