Changeset:
        8452098c0f9d
        
https://sourceforge.net/p/mrbs/hg-code/ci/8452098c0f9daba2a5df96e35e4ab4d3425de614
Author:
        John Beranek <[email protected]>
Date:
        Fri Sep 30 22:08:01 2016 +0100
Log message:

Removed sql_*() calls from everywhere but mrbs_sql.inc and the upgrade scripts

diffstat:

 convert_db_to_utf8.php     |   6 +++---
 web/admin.php              |  22 ++++++++++------------
 web/auth/auth_db.inc       |  16 ++++++++--------
 web/dbsys.inc              |  27 +++++++++++++++++++++------
 web/del.php                |  22 +++++++++++-----------
 web/del_entry_ajax.php     |   4 ++--
 web/edit_area_room.php     |  24 ++++++++++++------------
 web/edit_entry.php         |  26 +++++++++++++-------------
 web/edit_entry_handler.php |  10 +++++-----
 web/edit_users.php         |  37 ++++++++++++++++++++-----------------
 web/functions.inc          |  26 +++++++++++++-------------
 web/functions_error.inc    |   2 +-
 web/functions_ical.inc     |  26 +++++++++++++-------------
 web/functions_mail.inc     |   6 +++---
 web/functions_view.inc     |   2 +-
 web/help.php               |   2 +-
 web/pending.php            |   8 ++++----
 web/report.php             |  34 +++++++++++++++++-----------------
 web/search.php             |  24 ++++++++++++------------
 web/upgrade.inc            |   4 ++--
 web/view_entry.php         |   8 ++++----
 21 files changed, 176 insertions(+), 160 deletions(-)

diffs (truncated from 1176 to 300 lines):

diff -r 7f2f23d25675 -r 8452098c0f9d convert_db_to_utf8.php
--- a/convert_db_to_utf8.php    Fri Sep 30 08:00:02 2016 +0100
+++ b/convert_db_to_utf8.php    Fri Sep 30 22:08:01 2016 +0100
@@ -66,7 +66,7 @@
 <?php
   if ($dbsys == 'mysql' || $dbsys == 'mysqli')
   {
-    $ver = sql_version();
+    $ver = db()->version();
     // Sanitise the output to contain just the version number, hopefully
     $ver = preg_replace('/[^0-9.]/', '', $ver);
     // Pull out the floating point version number
@@ -74,8 +74,8 @@
     if ($version >= 4.1)
     {
       $not_unicode = FALSE;
-      $res = sql_query("SHOW FULL COLUMNS FROM $tbl_entry");
-      for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
+      $res = db()->query("SHOW FULL COLUMNS FROM $tbl_entry");
+      for ($i = 0; ($row = $res->row_keyed($i)); $i++)
       {
         if (!is_null($row['Collation']) &&
             !preg_match('/utf8/', $row['Collation']))
diff -r 7f2f23d25675 -r 8452098c0f9d web/admin.php
--- a/web/admin.php     Fri Sep 30 08:00:02 2016 +0100
+++ b/web/admin.php     Fri Sep 30 22:08:01 2016 +0100
@@ -43,16 +43,14 @@
 // Get the details we need for this area
 if (isset($area))
 {
-  $res = sql_query("SELECT area_name, custom_html FROM $tbl_area WHERE id=? 
LIMIT 1", array($area));
+  $res = db()->query("SELECT area_name, custom_html FROM $tbl_area WHERE id=? 
LIMIT 1", array($area));
 
-  if (sql_count($res) == 1)
+  if ($res->count() == 1)
   {
-    $row = sql_row_keyed($res, 0);
+    $row = $res->row_keyed(0);
     $area_name = $row['area_name'];
     $custom_html = $row['custom_html'];
   }
-  
-  sql_free($res);
 }
 
 
@@ -67,8 +65,8 @@
 $sql = "SELECT id, area_name, disabled
           FROM $tbl_area
       ORDER BY disabled, sort_key";
-$res = sql_query($sql);
-$areas_defined = $res && (sql_count($res) > 0);
+$res = db()->query($sql);
+$areas_defined = $res && ($res->count() > 0);
 if (!$areas_defined)
 {
   echo "<p>" . get_vocab("noareas") . "</p>\n";
@@ -80,7 +78,7 @@
   // admin whether any areas are enabled)
   $areas = array();
   $n_displayable_areas = 0;
-  for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
+  for ($i = 0; ($row = $res->row_keyed($i)); $i++)
   {
     $areas[] = $row;
     if ($is_admin || !$row['disabled'])
@@ -208,23 +206,23 @@
   echo "<div id=\"room_form\">\n";
   if (isset($area))
   {
-    $res = sql_query("SELECT * FROM $tbl_room WHERE area_id=? ORDER BY 
sort_key", array($area));
+    $res = db()->query("SELECT * FROM $tbl_room WHERE area_id=? ORDER BY 
sort_key", array($area));
 
-    if (sql_count($res) == 0)
+    if ($res->count() == 0)
     {
       echo "<p>" . get_vocab("norooms") . "</p>\n";
     }
     else
     {
        // Get the information about the fields in the room table
-      $fields = sql_field_info($tbl_room);
+      $fields = db()->field_info($tbl_room);
     
       // Build an array with the room info and also see if there are going
       // to be any rooms to display (in other words rooms if you are not an
       // admin whether any rooms are enabled)
       $rooms = array();
       $n_displayable_rooms = 0;
-      for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
+      for ($i = 0; ($row = $res->row_keyed($i)); $i++)
       {
         $rooms[] = $row;
         if ($is_admin || !$row['disabled'])
diff -r 7f2f23d25675 -r 8452098c0f9d web/auth/auth_db.inc
--- a/web/auth/auth_db.inc      Fri Sep 30 08:00:02 2016 +0100
+++ b/web/auth/auth_db.inc      Fri Sep 30 22:08:01 2016 +0100
@@ -41,20 +41,20 @@
 
   $sql_params = array();
 
-  // We use sql_syntax_casesensitive_equals() rather than just '=' because '=' 
in MySQL
+  // We use syntax_casesensitive_equals() rather than just '=' because '=' in 
MySQL
   // permits trailing spacings, eg 'john' = 'john '.   We could use LIKE, but 
that then
   // permits wildcards, so we could use a comnination of LIKE and '=' but 
that's a bit
   // messy.  WE could use STRCMP, but that's MySQL only.
   $sql = "SELECT password_hash
             FROM $tbl_users
            WHERE " .
-         sql_syntax_casesensitive_equals('name', utf8_strtolower($user), 
$sql_params) .
+         db()->syntax_casesensitive_equals('name', utf8_strtolower($user), 
$sql_params) .
          "
            LIMIT 1";
 
-  $res = sql_query($sql, $sql_params);
+  $res = db()->query($sql, $sql_params);
   
-  $row = sql_row_keyed($res, 0);
+  $row = $res->row_keyed(0);
 
   $do_rehash = false;
 
@@ -101,8 +101,8 @@
     $sql = "UPDATE $tbl_users
            SET password_hash=?
            WHERE " .
-      sql_syntax_casesensitive_equals('name', utf8_strtolower($user), 
$sql_params);
-    sql_command($sql, $sql_params);
+      db()->syntax_casesensitive_equals('name', utf8_strtolower($user), 
$sql_params);
+    db()->command($sql, $sql_params);
   }
 
   return $result;
@@ -126,7 +126,7 @@
     return 0;
   }
   
-  $result = sql_query1("SELECT level FROM $tbl_users WHERE name=? LIMIT 1",
+  $result = db()->query1("SELECT level FROM $tbl_users WHERE name=? LIMIT 1",
                        array(utf8_strtolower($user)));
 
   return ($result == -1) ? 0 : $result;
@@ -149,7 +149,7 @@
            WHERE name=?
            LIMIT 1";
            
-  $email = sql_query1($sql, array($user));
+  $email = db()->query1($sql, array($user));
   
   return ($email == -1) ? '' : $email;
 }
diff -r 7f2f23d25675 -r 8452098c0f9d web/dbsys.inc
--- a/web/dbsys.inc     Fri Sep 30 08:00:02 2016 +0100
+++ b/web/dbsys.inc     Fri Sep 30 22:08:01 2016 +0100
@@ -27,8 +27,23 @@
 $db_schema_version = 49;
 $local_db_schema_version = 1;
 
+// Convenience wrapper functions
 
-// Convenience wrapper functions
+function db()
+{
+  static $db_obj = null;
+
+  if (is_null($db_obj))
+  {
+    global $db_persist, $db_host, $db_login, $db_password,
+           $db_database, $db_port, $dbsys;
+
+    $db_obj = DBFactory::create($dbsys, $db_host, $db_login, $db_password,
+                                $db_database, $db_persist, $db_port);
+  }
+  return $db_obj;
+}
+
 
 function sql_free($stmt)
 {
@@ -176,7 +191,7 @@
 
 // Sanity check:  check that we can access the MRBS tables.  If we can't, it's
 // either because they don't exist or we don't have permission.
-if (!sql_table_exists($tbl_entry))
+if (!db()->table_exists($tbl_entry))
 {
   fatal_error(FALSE, get_vocab('fatal_no_tables'), FALSE);
 }
@@ -185,12 +200,12 @@
 $current_db_schema_version = 0;
 $current_local_db_schema_version = 0;
 
-if (sql_table_exists($tbl_variables))
+if (db()->table_exists($tbl_variables))
 {
-  $current_db_schema_version = sql_query1("SELECT variable_content ".
+  $current_db_schema_version = db()->query1("SELECT variable_content ".
                                           "FROM $tbl_variables ".
                                           "WHERE variable_name = 
'db_version'");
-  $current_local_db_schema_version = sql_query1("SELECT variable_content ".
+  $current_local_db_schema_version = db()->query1("SELECT variable_content ".
                                                 "FROM $tbl_variables ".
                                                 "WHERE variable_name = 
'local_db_version'");                                            
   if ($current_local_db_schema_version < 0)
@@ -270,7 +285,7 @@
 {
   // Find the maximum length of the CHAR and VARCHAR fields (we won't
   // worry about TEXT fields) 
-  $field_info = sql_field_info($$var);
+  $field_info = db()->field_info($$var);
   foreach ($field_info as $field)
   {
     if (($field['nature'] == 'character') && 
diff -r 7f2f23d25675 -r 8452098c0f9d web/del.php
--- a/web/del.php       Fri Sep 30 08:00:02 2016 +0100
+++ b/web/del.php       Fri Sep 30 22:08:01 2016 +0100
@@ -22,22 +22,22 @@
   if (isset($confirm))
   {
     // They have confirmed it already, so go blast!
-    sql_begin();
+    db()->begin();
     try
     {
       // 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));
+      db()->command("DELETE FROM $tbl_entry WHERE room_id=?", array($room));
+      db()->command("DELETE FROM $tbl_repeat WHERE room_id=?", array($room));
       // Now take out the room itself
-      sql_command("DELETE FROM $tbl_room WHERE id=?", array($room));
+      db()->command("DELETE FROM $tbl_room WHERE id=?", array($room));
     }
     catch (DBException $e)
     {
-      sql_rollback();
+      db()->rollback();
       throw $e;
     }
    
-    sql_commit();
+    db()->commit();
    
     // Go back to the admin page
     Header("Location: admin.php?area=$area");
@@ -50,9 +50,9 @@
     // Find out how many appointments would be deleted
    
     $sql = "SELECT name, start_time, end_time FROM $tbl_entry WHERE room_id=?";
-    $res = sql_query($sql, array($room));
+    $res = db()->query($sql, array($room));
     
-    if (sql_count($res) > 0)
+    if ($res->count() > 0)
     {
       echo "<p>\n";
       echo get_vocab("deletefollowing") . ":\n";
@@ -60,7 +60,7 @@
       
       echo "<ul>\n";
       
-      for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
+      for ($i = 0; ($row = $res->row_keyed($i)); $i++)
       {
         echo "<li>".htmlspecialchars($row['name'])." (";
         echo time_date_string($row['start_time']) . " -> ";
@@ -85,11 +85,11 @@
 {
   // We are only going to let them delete an area if there are
   // no rooms. its easier
-  $n = sql_query1("SELECT COUNT(*) FROM $tbl_room WHERE area_id=?", 
array($area));
+  $n = db()->query1("SELECT COUNT(*) FROM $tbl_room WHERE area_id=?", 
array($area));
   if ($n == 0)
   {
     // OK, nothing there, lets blast it away
-    sql_command("DELETE FROM $tbl_area WHERE id=?", array($area));
+    db()->command("DELETE FROM $tbl_area WHERE id=?", array($area));
    
     // Redirect back to the admin page
     header("Location: admin.php");
diff -r 7f2f23d25675 -r 8452098c0f9d web/del_entry_ajax.php
--- a/web/del_entry_ajax.php    Fri Sep 30 08:00:02 2016 +0100
+++ b/web/del_entry_ajax.php    Fri Sep 30 22:08:01 2016 +0100
@@ -62,11 +62,11 @@
 // rows in the repeat table ourselves - but this does not take long.
 
 $sql = "DELETE FROM $tbl_entry WHERE id IN (" . implode(',', $ids) . ")";
-$result = sql_command($sql);
+$result = db()->command($sql);
 
 // And delete any orphaned rows in the repeat table
 $sql = "DELETE FROM $tbl_repeat WHERE id NOT IN (SELECT repeat_id FROM 
$tbl_entry)";
-$orphan_result = sql_command($sql);
+$orphan_result = db()->command($sql);
 
 
 echo $result;
diff -r 7f2f23d25675 -r 8452098c0f9d web/edit_area_room.php
--- a/web/edit_area_room.php    Fri Sep 30 08:00:02 2016 +0100
+++ b/web/edit_area_room.php    Fri Sep 30 22:08:01 2016 +0100

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to