Changeset:
712c58de7e5c
https://sourceforge.net/p/mrbs/hg-code/ci/712c58de7e5ce85f27671a0f60302dcfa9ee8724
Author:
Campbell Morrison <[email protected]>
Date:
Thu Sep 29 15:40:32 2016 +0100
Log message:
Removed some more error checking now that we have exceptions.
diffstat:
web/auth/auth_db_ext.inc | 18 --------
web/lib/MRBS/DB.php | 17 ++-----
web/lib/MRBS/DB_mysql.php | 101 ++++++++++++++++++++++-----------------------
web/lib/MRBS/DB_pgsql.php | 64 +++++++++++++---------------
web/upgrade.inc | 7 ---
5 files changed, 83 insertions(+), 124 deletions(-)
diffs (289 lines):
diff -r 7faf747c7fdc -r 712c58de7e5c web/auth/auth_db_ext.inc
--- a/web/auth/auth_db_ext.inc Thu Sep 29 15:19:32 2016 +0100
+++ b/web/auth/auth_db_ext.inc Thu Sep 29 15:40:32 2016 +0100
@@ -66,12 +66,6 @@
$sql_params);
$stmt = $db_ext_conn->query($query, $sql_params);
-
- if ($stmt === FALSE)
- {
- trigger_error($db_ext_conn->error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
if ($stmt->count() == 1) // force a unique match
{
@@ -183,12 +177,6 @@
$stmt = $db_ext_conn->query($query, $sql_params);
- if ($stmt === FALSE)
- {
- trigger_error($db_ext_conn->error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
-
if ($stmt->count() == 0)
{
return 0;
@@ -237,12 +225,6 @@
$stmt = $db_ext_conn->query($query, $sql_params);
- if ($stmt === FALSE)
- {
- trigger_error($db_ext_conn->error(), E_USER_WARNING);
- fatal_error(FALSE, get_vocab("fatal_db_error"));
- }
-
if ($stmt->count() == 0)
{
return 0;
diff -r 7faf747c7fdc -r 712c58de7e5c web/lib/MRBS/DB.php
--- a/web/lib/MRBS/DB.php Thu Sep 29 15:19:32 2016 +0100
+++ b/web/lib/MRBS/DB.php Thu Sep 29 15:40:32 2016 +0100
@@ -151,24 +151,17 @@
// Run an SQL query that returns a simple one dimensional array of results.
// The SQL query must select only one column. Returns an empty array if
- // no results, or FALSE if there's an error
+ // no results; throws a DBException if there's an error
public function query_array($sql, $params = null)
{
$stmt = $this->query($sql, $params);
- if ($stmt === FALSE)
+ $result = array();
+ for ($i = 0; ($row = $stmt->row($i)); $i++)
{
- return FALSE;
+ $result[] = $row[0];
}
- else
- {
- $result = array();
- for ($i = 0; ($row = $stmt->row($i)); $i++)
- {
- $result[] = $row[0];
- }
- return $result;
- }
+ return $result;
}
diff -r 7faf747c7fdc -r 712c58de7e5c web/lib/MRBS/DB_mysql.php
--- a/web/lib/MRBS/DB_mysql.php Thu Sep 29 15:19:32 2016 +0100
+++ b/web/lib/MRBS/DB_mysql.php Thu Sep 29 15:40:32 2016 +0100
@@ -57,10 +57,13 @@
// timed out (for example, because another client has previously locked
the name),
// or NULL if an error occurred (such as running out of memory or the
thread was
// killed with mysqladmin kill)
- $stmt = $this->query("SELECT GET_LOCK(?, 20)", array($name));
- if ($stmt === FALSE)
+ try
{
- trigger_error($this->error(), E_USER_WARNING);
+ $stmt = $this->query("SELECT GET_LOCK(?, 20)", array($name));
+ }
+ catch (DBException $e)
+ {
+ trigger_error($e->getMessage(), E_USER_WARNING);
return FALSE;
}
@@ -162,57 +165,51 @@
'tinyint' => 1);
$stmt = $this->query("SHOW COLUMNS FROM $table", array());
- if ($stmt === FALSE)
+
+ $fields = array();
+ for ($i = 0; ($row = $stmt->row_keyed($i)); $i++)
{
- trigger_error($this->error(), E_USER_WARNING);
- fatal_error(TRUE, get_vocab("fatal_db_error"));
+ $name = $row['Field'];
+ $type = $row['Type'];
+ // split the type (eg 'varchar(25)') around the opening '('
+ $parts = explode('(', $type);
+ // map the type onto one of the generic natures, if a mapping exists
+ $nature = (array_key_exists($parts[0], $nature_map)) ?
$nature_map[$parts[0]] : $parts[0];
+ // now work out the length
+ if ($nature == 'integer')
+ {
+ // if it's one of the ints, then look up the length in bytes
+ $length = (array_key_exists($parts[0], $int_bytes)) ?
$int_bytes[$parts[0]] : 0;
+ }
+ elseif ($nature == 'character')
+ {
+ // if it's a character type then use the length that was in parentheses
+ // eg if it was a varchar(25), we want the 25
+ if (isset($parts[1]))
+ {
+ $length = preg_replace('/\)/', '', $parts[1]); // strip off the
closing ')'
+ }
+ // otherwise it could be any length (eg if it was a 'text')
+ else
+ {
+ $length = defined('PHP_INT_MAX') ? PHP_INT_MAX : 9999;
+ }
+ }
+ else // we're only dealing with a few simple cases at the moment
+ {
+ $length = NULL;
+ }
+ // Convert the is_nullable field to a boolean
+ $is_nullable = (utf8_strtolower($row['Null']) == 'yes') ? TRUE : FALSE;
+
+ $fields[$i]['name'] = $name;
+ $fields[$i]['type'] = $type;
+ $fields[$i]['nature'] = $nature;
+ $fields[$i]['length'] = $length;
+ $fields[$i]['is_nullable'] = $is_nullable;
}
- else
- {
- $fields = array();
- for ($i = 0; ($row = $stmt->row_keyed($i)); $i++)
- {
- $name = $row['Field'];
- $type = $row['Type'];
- // split the type (eg 'varchar(25)') around the opening '('
- $parts = explode('(', $type);
- // map the type onto one of the generic natures, if a mapping exists
- $nature = (array_key_exists($parts[0], $nature_map)) ?
$nature_map[$parts[0]] : $parts[0];
- // now work out the length
- if ($nature == 'integer')
- {
- // if it's one of the ints, then look up the length in bytes
- $length = (array_key_exists($parts[0], $int_bytes)) ?
$int_bytes[$parts[0]] : 0;
- }
- elseif ($nature == 'character')
- {
- // if it's a character type then use the length that was in
parentheses
- // eg if it was a varchar(25), we want the 25
- if (isset($parts[1]))
- {
- $length = preg_replace('/\)/', '', $parts[1]); // strip off the
closing ')'
- }
- // otherwise it could be any length (eg if it was a 'text')
- else
- {
- $length = defined('PHP_INT_MAX') ? PHP_INT_MAX : 9999;
- }
- }
- else // we're only dealing with a few simple cases at the moment
- {
- $length = NULL;
- }
- // Convert the is_nullable field to a boolean
- $is_nullable = (utf8_strtolower($row['Null']) == 'yes') ? TRUE : FALSE;
-
- $fields[$i]['name'] = $name;
- $fields[$i]['type'] = $type;
- $fields[$i]['nature'] = $nature;
- $fields[$i]['length'] = $length;
- $fields[$i]['is_nullable'] = $is_nullable;
- }
- return $fields;
- }
+
+ return $fields;
}
// Syntax methods
diff -r 7faf747c7fdc -r 712c58de7e5c web/lib/MRBS/DB_pgsql.php
--- a/web/lib/MRBS/DB_pgsql.php Thu Sep 29 15:19:32 2016 +0100
+++ b/web/lib/MRBS/DB_pgsql.php Thu Sep 29 15:40:32 2016 +0100
@@ -204,43 +204,37 @@
$sql .= "ORDER BY ordinal_position";
$stmt = $this->query($sql, $sql_params);
- if ($stmt === FALSE)
+
+ for ($i = 0; ($row = $stmt->row_keyed($i)); $i++)
{
- trigger_error($this->error(), E_USER_WARNING);
- fatal_error(TRUE, get_vocab("fatal_db_error"));
+ $name = $row['column_name'];
+ $type = $row['data_type'];
+ // map the type onto one of the generic natures, if a mapping exists
+ $nature = (array_key_exists($type, $nature_map)) ? $nature_map[$type] :
$type;
+ // Get a length value; one of these values should be set
+ if (isset($row['numeric_precision']))
+ {
+ $length = (int) floor($row['numeric_precision'] / 8); // precision is
in bits
+ }
+ elseif (isset($row['character_maximum_length']))
+ {
+ $length = $row['character_maximum_length'];
+ }
+ elseif (isset($row['character_octet_length']))
+ {
+ $length = $row['character_octet_length'];
+ }
+ // Convert the is_nullable field to a boolean
+ $is_nullable = (utf8_strtolower($row['is_nullable']) == 'yes') ? TRUE :
FALSE;
+
+ $fields[$i]['name'] = $name;
+ $fields[$i]['type'] = $type;
+ $fields[$i]['nature'] = $nature;
+ $fields[$i]['length'] = $length;
+ $fields[$i]['is_nullable'] = $is_nullable;
}
- else
- {
- for ($i = 0; ($row = $stmt->row_keyed($i)); $i++)
- {
- $name = $row['column_name'];
- $type = $row['data_type'];
- // map the type onto one of the generic natures, if a mapping exists
- $nature = (array_key_exists($type, $nature_map)) ? $nature_map[$type]
: $type;
- // Get a length value; one of these values should be set
- if (isset($row['numeric_precision']))
- {
- $length = (int) floor($row['numeric_precision'] / 8); // precision
is in bits
- }
- elseif (isset($row['character_maximum_length']))
- {
- $length = $row['character_maximum_length'];
- }
- elseif (isset($row['character_octet_length']))
- {
- $length = $row['character_octet_length'];
- }
- // Convert the is_nullable field to a boolean
- $is_nullable = (utf8_strtolower($row['is_nullable']) == 'yes') ? TRUE
: FALSE;
-
- $fields[$i]['name'] = $name;
- $fields[$i]['type'] = $type;
- $fields[$i]['nature'] = $nature;
- $fields[$i]['length'] = $length;
- $fields[$i]['is_nullable'] = $is_nullable;
- }
- return $fields;
- }
+ return $fields;
+
}
// Syntax methods
diff -r 7faf747c7fdc -r 712c58de7e5c web/upgrade.inc
--- a/web/upgrade.inc Thu Sep 29 15:19:32 2016 +0100
+++ b/web/upgrade.inc Thu Sep 29 15:40:32 2016 +0100
@@ -79,13 +79,6 @@
if (preg_match("/\S/", $query))
{
$res = $upgrade_handle->query($query);
- if ($res === FALSE)
- {
- // No need to localise, should hopefully never happen
- upgrade_echo("<br>Tried:<pre>" . htmlspecialchars($query) . "</pre>
and got error:" .
- "<pre>" . $upgrade_handle->error() . "</pre>\n");
- return FALSE;
- }
}
}
------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits