From 3643d3066f0101732623b8a2de379fe39d78b955 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 10 Apr 2012 10:47:37 -0400 Subject: [PATCH] Miscellaneous Bug Fixes --- index.php | 4 ++-- sys/common/settings.php | 12 ++++++++++ sys/db/db_pdo.php | 28 ++++++++++++---------- sys/db/drivers/pgsql/pgsql_driver.php | 4 ++-- sys/db/drivers/sqlite/sqlite_sql.php | 9 ++----- sys/windows/widgets/connection_sidebar.php | 7 ++++++ sys/windows/widgets/data_grid.php | 6 +++++ sys/windows/widgets/db_info_widget.php | 22 +++++++++++++---- 8 files changed, 63 insertions(+), 29 deletions(-) diff --git a/index.php b/index.php index 306eb07..f4cca98 100644 --- a/index.php +++ b/index.php @@ -77,11 +77,11 @@ if( ! class_exists('pdo')) // Convert Errors to Exceptions // Do this after the two compatibility checks for cleaner output -function exception_error_handler($errno, $errstr, $errfile, $errline) +function exception_error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } -set_error_handler("exception_error_handler", -1); +set_error_handler("exception_error_handler"); // -------------------------------------------------------------------------- diff --git a/sys/common/settings.php b/sys/common/settings.php index 2636c43..caecafe 100644 --- a/sys/common/settings.php +++ b/sys/common/settings.php @@ -123,6 +123,12 @@ class Settings { */ public function add_db($name, $params) { + // Return on bad data + if (empty($name) || empty($params)) + { + return FALSE; + } + if( ! isset($this->current->dbs->{$name})) { $params['name'] = $name; @@ -148,6 +154,12 @@ class Settings { */ public function edit_db($name, $params) { + // Return on bad data + if (empty($name) || empty($params)) + { + return FALSE; + } + if (isset($this->current->dbs->{$name}) && ($name === $params['name'])) { $this->current->dbs->{$name} = $params; diff --git a/sys/db/db_pdo.php b/sys/db/db_pdo.php index 39eeee8..b14cd1a 100644 --- a/sys/db/db_pdo.php +++ b/sys/db/db_pdo.php @@ -30,6 +30,8 @@ abstract class DB_PDO extends PDO { public function __construct($dsn, $username=NULL, $password=NULL, $driver_options=array()) { parent::__construct($dsn, $username, $password, $driver_options); + + $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } // ------------------------------------------------------------------------- @@ -216,17 +218,17 @@ abstract class DB_PDO extends PDO { { return FALSE; } - + $res = $this->query($sql); - + $flag = ($filtered_index) ? PDO::FETCH_NUM : PDO::FETCH_ASSOC; $all = $res->fetchAll($flag); - + return ($filtered_index) ? db_filter($all, 0) : $all; } - + // ------------------------------------------------------------------------- - + /** * Return list of tables for the current database * @@ -236,7 +238,7 @@ abstract class DB_PDO extends PDO { { return $this->driver_query($this->sql->table_list()); } - + // ------------------------------------------------------------------------- /** @@ -248,7 +250,7 @@ abstract class DB_PDO extends PDO { { return $this->driver_query($this->sql->db_list()); } - + // ------------------------------------------------------------------------- /** @@ -260,7 +262,7 @@ abstract class DB_PDO extends PDO { { return $this->driver_query($this->sql->view_list()); } - + // ------------------------------------------------------------------------- /** @@ -272,7 +274,7 @@ abstract class DB_PDO extends PDO { { return $this->driver_query($this->sql->sequence_list()); } - + // ------------------------------------------------------------------------- /** @@ -284,7 +286,7 @@ abstract class DB_PDO extends PDO { { return $this->driver_query($this->sql->function_list(), FALSE); } - + // ------------------------------------------------------------------------- /** @@ -296,7 +298,7 @@ abstract class DB_PDO extends PDO { { return $this->driver_query($this->sql->procedure_list(), FALSE); } - + // ------------------------------------------------------------------------- /** @@ -308,9 +310,9 @@ abstract class DB_PDO extends PDO { { return $this->driver_query($this->sql->trigger_list(), FALSE); } - + // ------------------------------------------------------------------------- - + /** * Retreives an array of non-user-created tables for * the connection/database diff --git a/sys/db/drivers/pgsql/pgsql_driver.php b/sys/db/drivers/pgsql/pgsql_driver.php index cc125fb..e380867 100644 --- a/sys/db/drivers/pgsql/pgsql_driver.php +++ b/sys/db/drivers/pgsql/pgsql_driver.php @@ -73,9 +73,9 @@ class pgSQL extends DB_PDO { { return (isset($this->statement)) ? $this->statement->rowCount : FALSE; } - + // -------------------------------------------------------------------------- - + /** * Get a list of schemas for the current connection * diff --git a/sys/db/drivers/sqlite/sqlite_sql.php b/sys/db/drivers/sqlite/sqlite_sql.php index a814632..2d853c8 100644 --- a/sys/db/drivers/sqlite/sqlite_sql.php +++ b/sys/db/drivers/sqlite/sqlite_sql.php @@ -270,16 +270,11 @@ SQL; /** * Returns sql to list triggers * - * @return string + * @return FALSE */ public function trigger_list() { - return <<treeview->get(0); $conns = DB_Reg::get_connections(); + // Don't try to set up popup menu + // on ambiguous areas + if ( ! is_object($data)) + { + return; + } + // Set up menu items { // Show disconnect diff --git a/sys/windows/widgets/data_grid.php b/sys/windows/widgets/data_grid.php index fa1cdeb..8368120 100644 --- a/sys/windows/widgets/data_grid.php +++ b/sys/windows/widgets/data_grid.php @@ -49,6 +49,12 @@ class Data_Grid extends GtkTreeView { // Get the model and iterator for the selected row list($model, $iter) = $sel->get_selected(); + // Return on lack of $iter + if (is_null($iter)) + { + return; + } + // Get the data from the model return $model->get_value($iter, $pos); } diff --git a/sys/windows/widgets/db_info_widget.php b/sys/windows/widgets/db_info_widget.php index 2bbcaf3..a6e1aca 100644 --- a/sys/windows/widgets/db_info_widget.php +++ b/sys/windows/widgets/db_info_widget.php @@ -121,8 +121,16 @@ class DB_Info_Widget extends GtkTable { $this->db_file->set_filename($db->file); } + // Re-populate the text fields with their actual values + // This seems to work around a PHP-GTK bug...it SHOULD work + // to set them the first time... + $this->conn->set_text($db->name); + $this->host->set_text($db->host); + $this->user->set_text($db->user); $this->pass->set_text($db->pass); $this->conn_db->set_text($db->conn_db); + $this->port->set_text($db->port); + } } @@ -356,14 +364,18 @@ class DB_Info_Widget extends GtkTable { 'name' => $this->conn->get_text(), ); - $this->settings->add_db($data['name'], $data); + $res = $this->settings->add_db($data['name'], $data); + + if ( ! $res) + { + error("Failed to add database - Connection information invalid"); + } // Pass to connection sidebar to update Connection_Sidebar::get_instance()->refresh(); // Destroy the parent window - $parent_window =& $this->get_parent_window(); - + $parent_window = $this->get_parent_window(); $parent_window->destroy(); } @@ -399,8 +411,7 @@ class DB_Info_Widget extends GtkTable { Connection_Sidebar::get_instance()->refresh(); // Destroy the parent window - $parent_window =& $this->get_parent_window(); - + $parent_window = $this->get_parent_window(); $parent_window->destroy(); } @@ -426,6 +437,7 @@ class DB_Info_Widget extends GtkTable { // silly user input. if( empty($params->type)) { + error("Failed to connect - Invalid connection settings"); return; }