From 9c7fee6c21c750632f149f2536a8ad4fad2b83e4 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 9 Mar 2004 16:32:24 +0000 Subject: [PATCH] Lots of error checking now on most database functions ... if debugging is turned on then you get notifications printed in the web page. Good for catching bad SQL. Thanks to Howard Miller for the boot up the bum! :-) --- lib/datalib.php | 50 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/datalib.php b/lib/datalib.php index e843e7a77b..e9a157af7c 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -258,8 +258,12 @@ function record_exists_sql($sql) { global $db; - $rs = $db->Execute($sql); - if (empty($rs)) return false; + if (!$rs = $db->Execute($sql)) { + if ($CFG->debug > 7) { + notify($db->ErrorMsg()."

$sql"); + } + return false; + } if ( $rs->RecordCount() ) { return true; @@ -327,7 +331,12 @@ function count_records_sql($sql) { global $db; $rs = $db->Execute("$sql"); - if (empty($rs)) return 0; + if (!$rs) { + if ($CFG->debug > 7) { + notify($db->ErrorMsg()."

$sql"); + } + return 0; + } return $rs->fields[0]; } @@ -387,9 +396,7 @@ function get_record_sql($sql) { if (!$rs = $db->Execute("$sql$limit")) { if ($CFG->debug > 7) { // Debugging mode - print checks - $db->debug=true; - $db->Execute("$sql$limit"); - $db->debug=false; + notify( $db->ErrorMsg() . "

$sql$limit" ); } return false; } @@ -556,10 +563,14 @@ function get_records_list($table, $field="", $values="", $sort="", $fields="*") */ function get_records_sql($sql) { - global $db; + global $CFG,$db; - $rs = $db->Execute("$sql"); - if (empty($rs)) return false; + if (!$rs = $db->Execute($sql)) { + if ($CFG->debug > 7) { + notify($db->ErrorMsg()."

$sql"); + } + return false; + } if ( $rs->RecordCount() > 0 ) { if ($records = $rs->GetAssoc(true)) { @@ -639,8 +650,12 @@ function get_records_sql_menu($sql) { global $db; - $rs = $db->Execute("$sql"); - if (empty($rs)) return false; + if (!$rs = $db->Execute($sql)) { + if ($CFG->debug > 7) { + notify($db->ErrorMsg()."

$sql"); + } + return false; + } if ( $rs->RecordCount() > 0 ) { while (!$rs->EOF) { @@ -675,7 +690,12 @@ function get_field($table, $return, $field1, $value1, $field2="", $value2="", $f } $rs = $db->Execute("SELECT $return FROM $CFG->prefix$table $select"); - if (empty($rs)) return false; + if (!$rs) { + if ($CFG->debug > 7) { + notify($db->ErrorMsg()."

SELECT $return FROM $CFG->prefix$table $select"); + } + return false; + } if ( $rs->RecordCount() == 1 ) { return $rs->fields["$return"]; @@ -777,6 +797,9 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') { /// Run the SQL statement if (!$rs = $db->Execute($insertSQL)) { + if ($CFG->debug > 7) { + notify($db->ErrorMsg()."

$insertSQL"); + } return false; } @@ -848,6 +871,9 @@ function update_record($table, $dataobject) { if ($rs = $db->Execute("UPDATE $CFG->prefix$table SET $update WHERE id = '$dataobject->id'")) { return true; } else { + if ($CFG->debug > 7) { + notify($db->ErrorMsg()."

UPDATE $CFG->prefix$table SET $update WHERE id = '$dataobject->id'"); + } return false; } } -- 2.39.5