Changeset:
331249866f8e
https://sourceforge.net/p/mrbs/hg-code/ci/331249866f8eefae96f7a610c508d8e421007641
Author:
Campbell Morrison <[email protected]>
Date:
Thu Sep 29 12:55:39 2016 +0100
Log message:
Made sql_command() throw an exception and removed error checking after calls to
sql_command().
diffstat:
web/day.php | 6 ------
web/del.php | 27 +++++++++++----------------
web/edit_area_room.php | 23 ++++++-----------------
web/edit_users.php | 42 ++----------------------------------------
web/functions_ical.inc | 20 ++++----------------
web/lib/MRBS/DB.php | 5 ++---
web/mrbs_sql.inc | 48 +++++++++++++-----------------------------------
web/upgrade.inc | 10 ++--------
web/upgrade/13/post.inc | 9 +--------
web/upgrade/15/post.inc | 7 +------
web/upgrade/16/post.inc | 6 +-----
web/upgrade/17/post.inc | 26 ++++----------------------
web/upgrade/2/post.inc | 8 +-------
web/upgrade/21/post.inc | 7 +------
web/upgrade/24/post.inc | 10 ++++++----
web/upgrade/32/post.inc | 6 +-----
web/upgrade/34/post.inc | 6 +-----
web/upgrade/4/post.inc | 9 +--------
web/upgrade/43/post.inc | 9 +--------
web/upgrade/47/post.inc | 10 ++++++----
web/upgrade/5/post.inc | 10 +---------
web/upgrade/6/post.inc | 22 ++++------------------
web/upgrade/7/post.inc | 21 ++++-----------------
web/upgrade/8/post.inc | 6 +-----
24 files changed, 75 insertions(+), 278 deletions(-)
diffs (truncated from 670 to 300 lines):
diff -r 27d0fde3ea6d -r 331249866f8e web/day.php
--- a/web/day.php Thu Sep 29 10:51:13 2016 +0100
+++ b/web/day.php Thu Sep 29 12:55:39 2016 +0100
@@ -2,16 +2,10 @@
namespace MRBS;
// $Id$
-
require "defaultincludes.inc";
require_once "mincals.inc";
require_once "functions_table.inc";
-$sql = "SELECT id FROM $tbl_entry WHERE id=?";
-$result = sql_query1($sql, array(571407));
-var_dump($result);
-exit;
-
// Get non-standard form variables
$timetohighlight = get_form_var('timetohighlight', 'int');
$ajax = get_form_var('ajax', 'int');
diff -r 27d0fde3ea6d -r 331249866f8e web/del.php
--- a/web/del.php Thu Sep 29 10:51:13 2016 +0100
+++ b/web/del.php Thu Sep 29 12:55:39 2016 +0100
@@ -23,26 +23,21 @@
{
// They have confirmed it already, so go blast!
sql_begin();
- // First take out all appointments for this room
- $result = sql_command("DELETE FROM $tbl_entry WHERE room_id=?",
array($room));
- if ($result >= 0)
+ try
{
- $result = sql_command("DELETE FROM $tbl_repeat WHERE room_id=?",
array($room));
+ // First take out all appointments for this room
+ sql_command("DELETE FROM $tbl_entry WHERE room_id=?", array($room));
+ sql_command("DELETE FROM $tbl_repeat WHERE room_id=?", array($room));
// Now take out the room itself
- if ($result >= 0)
- {
- sql_command("DELETE FROM $tbl_room WHERE id=?", array($room));
- }
+ sql_command("DELETE FROM $tbl_room WHERE id=?", array($room));
+ }
+ catch (DBException $e)
+ {
+ sql_rollback();
+ throw $e;
}
- if ($result >= 0)
- {
- sql_commit();
- }
- else
- {
- sql_rollback();
- }
+ sql_commit();
// Go back to the admin page
Header("Location: admin.php?area=$area");
diff -r 27d0fde3ea6d -r 331249866f8e web/edit_area_room.php
--- a/web/edit_area_room.php Thu Sep 29 10:51:13 2016 +0100
+++ b/web/edit_area_room.php Thu Sep 29 12:55:39 2016 +0100
@@ -620,14 +620,9 @@
$sql .= implode(",", $assign_array) . " WHERE id=?";
$sql_params[] = $room;
- if (sql_command($sql, $sql_params) < 0)
- {
- echo get_vocab("update_room_failed") . "<br>\n";
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
- // if everything is OK, release the mutex and go back to
- // the admin page (for the new area)
+ sql_command($sql, $sql_params);
+
+ // Release the mutex and go back to the admin page (for the new area)
sql_mutex_unlock("$tbl_area");
Header("Location:
admin.php?day=$day&month=$month&year=$year&area=$new_area");
exit();
@@ -888,15 +883,9 @@
$sql .= implode(",", $assign_array) . " WHERE id=?";
$sql_params[] = $area;
- if (sql_command($sql, $sql_params) < 0)
- {
- echo $sql;
- echo sql_error();
- echo get_vocab("update_area_failed") . "<br>\n";
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
- // If the database update worked OK, go back to the admin page
+ sql_command($sql, $sql_params);
+
+ // Go back to the admin page
Header("Location:
admin.php?day=$day&month=$month&year=$year&area=$area");
exit();
}
diff -r 27d0fde3ea6d -r 331249866f8e web/edit_users.php
--- a/web/edit_users.php Thu Sep 29 10:51:13 2016 +0100
+++ b/web/edit_users.php Thu Sep 29 12:55:39 2016 +0100
@@ -769,27 +769,7 @@
/* DEBUG lines - check the actual sql statement going into the db */
//echo "Final SQL string: <code>" . htmlspecialchars($operation) .
"</code>";
//exit;
- $r = sql_command($operation, $sql_params);
- if ($r == -1)
- {
- // Get the error message before the print_header() call because the
print_header()
- // function can contain SQL queries and so reset the error message.
- trigger_error(sql_error(), E_USER_WARNING);
- print_header(0, 0, 0, "", "");
-
- // This is unlikely to happen in normal operation. Do not translate.
-
- print "<form class=\"edit_users_error\" method=\"post\" action=\"" .
htmlspecialchars(this_page()) . "\">\n";
- print " <fieldset>\n";
- print " <legend></legend>\n";
- print " <p class=\"error\">Error updating the $tbl_users
table.</p>\n";
- print " <input type=\"submit\" value=\" " . get_vocab("ok") . "
\">\n";
- print " </fieldset>\n";
- print "</form>\n";
-
- // Print footer and exit
- print_footer(TRUE);
- }
+ sql_command($operation, $sql_params);
/* Success. Redirect to the user list, to remove the form args */
Header("Location: edit_users.php");
@@ -815,25 +795,7 @@
exit();
}
- $r = sql_command("DELETE FROM $tbl_users WHERE id=?", array($Id));
- if ($r == -1)
- {
- print_header(0, 0, 0, "", "");
-
- // This is unlikely to happen in normal operation. Do not translate.
-
- print "<form class=\"edit_users_error\" method=\"post\" action=\"" .
htmlspecialchars(this_page()) . "\">\n";
- print " <fieldset>\n";
- print " <legend></legend>\n";
- print " <p class=\"error\">Error deleting entry $Id from the $tbl_users
table.</p>\n";
- print " <p class=\"error\">" . sql_error() . "</p>\n";
- print " <input type=\"submit\" value=\" " . get_vocab("ok") . " \">\n";
- print " </fieldset>\n";
- print "</form>\n";
-
- // Print footer and exit
- print_footer(TRUE);
- }
+ sql_command("DELETE FROM $tbl_users WHERE id=?", array($Id));
/* Success. Do not display a message. Simply fall through into the list
display. */
}
diff -r 27d0fde3ea6d -r 331249866f8e web/functions_ical.inc
--- a/web/functions_ical.inc Thu Sep 29 10:51:13 2016 +0100
+++ b/web/functions_ical.inc Thu Sep 29 12:55:39 2016 +0100
@@ -174,12 +174,7 @@
last_updated=?
WHERE timezone=?
AND outlook_compatible=?";
- if (sql_command($sql, array($vtimezone, time(), $tz,
$zoneinfo_outlook_compatible)) < 0)
- {
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
-
+ sql_command($sql, array($vtimezone, time(), $tz,
$zoneinfo_outlook_compatible));
}
}
// There's nothing in the database, so try and get a VTIMEZONE component
@@ -194,16 +189,9 @@
if (!empty($vtimezone))
{
$sql = "INSERT INTO $tbl_zoneinfo
- (timezone, outlook_compatible, vtimezone, last_updated)
- VALUES (?,
- ?,
- ?,
- ?)";
- if (sql_command($sql, array($tz, $zoneinfo_outlook_compatible,
$vtimezone, time())) < 0)
- {
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
+ (timezone, outlook_compatible, vtimezone,
last_updated)
+ VALUES (?, ?, ?, ?)";
+ sql_command($sql, array($tz, $zoneinfo_outlook_compatible, $vtimezone,
time()));
}
}
}
diff -r 27d0fde3ea6d -r 331249866f8e web/lib/MRBS/DB.php
--- a/web/lib/MRBS/DB.php Thu Sep 29 10:51:13 2016 +0100
+++ b/web/lib/MRBS/DB.php Thu Sep 29 12:55:39 2016 +0100
@@ -100,7 +100,7 @@
// Execute a non-SELECT SQL command (insert/update/delete).
// Returns the number of tuples affected if OK (a number >= 0).
- // Returns -1 on error; use error() to get the error message.
+ // Throws a DBException on error.
public function command($sql, $params = array())
{
try
@@ -110,8 +110,7 @@
}
catch (PDOException $e)
{
- trigger_error($sql . " " . $e->getMessage(), E_USER_WARNING);
- return -1;
+ throw new DBException($e->getMessage(), 0, $e, $sql, $params);
}
return $sth->rowCount();
diff -r 27d0fde3ea6d -r 331249866f8e web/mrbs_sql.inc
--- a/web/mrbs_sql.inc Thu Sep 29 10:51:13 2016 +0100
+++ b/web/mrbs_sql.inc Thu Sep 29 12:55:39 2016 +0100
@@ -728,12 +728,7 @@
$sql_col = array_map(__NAMESPACE__ . "\\sql_quote", $sql_col);
$sql = "INSERT INTO $table (" . implode(', ', $sql_col) . ") VALUES (" .
implode(', ',$sql_val) . ")";
- if (sql_command($sql, $sql_params) < 0)
- {
- // probably because the table hasn't been created properly
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(TRUE, get_vocab("fatal_db_error"));
- }
+ sql_command($sql, $sql_params);
return sql_insert_id($table, "id");
}
@@ -1103,14 +1098,13 @@
SET reminded=?,
ical_sequence=ical_sequence+1
WHERE id=?";
- if (sql_command($sql, array($now, $id)) >= 0)
- {
- $sql = "UPDATE $tbl_entry
- SET reminded=?,
- ical_sequence=ical_sequence+1
- WHERE repeat_id=?";
- return sql_command($sql, array($now, $id));
- }
+ sql_command($sql, array($now, $id));
+
+ $sql = "UPDATE $tbl_entry
+ SET reminded=?,
+ ical_sequence=ical_sequence+1
+ WHERE repeat_id=?";
+ return sql_command($sql, array($now, $id));
}
else
{
@@ -1185,11 +1179,7 @@
SET status=status&(~" . STATUS_AWAITING_APPROVAL . "),
ical_sequence=ical_sequence+1
WHERE id=?"; // PostgreSQL does not support LIMIT with UPDATE
- if (sql_command($sql, array($id)) < 0)
- {
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
+ sql_command($sql, array($id));
$id_column = 'repeat_id';
}
else
@@ -1212,11 +1202,7 @@
ical_sequence=ical_sequence+1
WHERE $condition"; // PostgreSQL does not support LIMIT with
UPDATE
- if (sql_command($sql, $sql_params) < 0)
- {
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
+ sql_command($sql, $sql_params);
}
if (is_array($start_times))
@@ -1666,11 +1652,7 @@
}
}
$sql = "INSERT INTO $tbl_area (" . implode(', ',$sql_col) . ") VALUES (" .
implode(', ',$sql_val) . ")";
- if (sql_command($sql, $sql_params) < 0)
- {
- trigger_error(sql_error(), E_USER_WARNING);
- fatal_error(TRUE, get_vocab("fatal_db_error"));
- }
+ sql_command($sql, $sql_params);
$area = sql_insert_id($tbl_area, 'id');
// Release the mutex
@@ -1716,13 +1698,9 @@
// If so, insert the room into the database
$sql = "INSERT INTO $tbl_room (room_name, sort_key, area_id, description,
capacity)
------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits