From 59e167c0643024e991bc51ad7f23e1c938c55ad0 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 2 Apr 2012 09:47:13 -0400 Subject: [PATCH] Start of connecting! --- sys/db/dbreg.php | 2 +- sys/db/query_builder.php | 7 ++--- sys/windows/widgets/connection_sidebar.php | 32 ++++++++++++++++++++++ sys/windows/widgets/db_tabs.php | 12 ++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/sys/db/dbreg.php b/sys/db/dbreg.php index 5b761d4..9c2f429 100644 --- a/sys/db/dbreg.php +++ b/sys/db/dbreg.php @@ -33,7 +33,7 @@ class DB_Reg { if ( ! isset(self::$instance[$key])) { // The constructor sets the instance - new DBReg($key); + new DB_Reg($key); } return self::$instance[$key]; diff --git a/sys/db/query_builder.php b/sys/db/query_builder.php index f1d3da3..b1a8af2 100644 --- a/sys/db/query_builder.php +++ b/sys/db/query_builder.php @@ -948,12 +948,9 @@ class Query_Builder { */ public function __call($name, $params) { - if ( ! empty($this->db->$name)) + if (method_exists($this->db, $name)) { - if (is_callable($this->db->$name)) - { - return call_user_func_array(array($this->db, $name), $params); - } + return call_user_func_array(array($this->db, $name), $params); } return NULL; diff --git a/sys/windows/widgets/connection_sidebar.php b/sys/windows/widgets/connection_sidebar.php index f5e4b15..8827726 100644 --- a/sys/windows/widgets/connection_sidebar.php +++ b/sys/windows/widgets/connection_sidebar.php @@ -225,6 +225,12 @@ class Connection_Sidebar extends GtkVBox { // Set up menu items { + $connect = new GtkImageMenuItem('Connect'); + $connect->set_image(GtkImage::new_from_stock(GTK::STOCK_CONNECT, GTK::ICON_SIZE_MENU)); + $connect->connect_simple('activate', array($this, 'db_connect')); + + $this->menu->append($connect); + $edit = new GtkImageMenuItem('Edit Connection'); $edit->set_image(GtkImage::new_from_stock(GTK::STOCK_EDIT, GTK::ICON_SIZE_MENU)); $edit->connect_simple('activate', array($this, 'edit_connection')); @@ -287,5 +293,31 @@ class Connection_Sidebar extends GtkVBox { // Refresh the sidebar $this->refresh(); } + + // -------------------------------------------------------------------------- + + /** + * Create connection to a database + * + * @param string $name + * @return void + */ + public function db_connect() + { + $data = $this->treeview->get(0); + + // Make sure to catch connection exceptions + try + { + $conn =& DB_Reg::get_db($data->name); + } + catch(PDOException $e) + { + error("Could not connect to database:\n". $e->getMessage()); + return; + } + + DB_Tabs::get_instance()->get_db_tabs($conn); + } } // End of connection_sidebar.php diff --git a/sys/windows/widgets/db_tabs.php b/sys/windows/widgets/db_tabs.php index 04d18ca..897fd2c 100644 --- a/sys/windows/widgets/db_tabs.php +++ b/sys/windows/widgets/db_tabs.php @@ -80,5 +80,17 @@ class DB_tabs extends GTKNotebook { return self::get_instance(); } + // -------------------------------------------------------------------------- + + /** + * Create tabs for database aspects + * + * @param Query_Builder $conn + * @return void + */ + public function get_db_tabs(&$conn) + { + print_r($conn->get_tables()); + } } // End of db_tabs.php