Skip to content
Permalink
Browse files

Added some additional error checking of get_record_sql when in debug …

…mode
  • Loading branch information...
moodler
moodler committed Jul 23, 2003
1 parent a4a4b85 commit 4d7a373539255686a980be06fb54248f6da260bd
Showing with 22 additions and 7 deletions.
  1. +22 −7 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() !");
}
}
}

0 comments on commit 4d7a373

Please sign in to comment.
You can’t perform that action at this time.