diff --git a/sys/db/db_pdo.php b/sys/db/db_pdo.php index 2afe424..cd0b408 100644 --- a/sys/db/db_pdo.php +++ b/sys/db/db_pdo.php @@ -205,6 +205,13 @@ abstract class DB_PDO extends PDO { */ abstract public function get_tables(); + /** + * Return list of dbs for the current connection, if possible + * + * @return array + */ + abstract public function get_dbs(); + /** * Empty the passed table * diff --git a/sys/db/drivers/firebird.php b/sys/db/drivers/firebird.php index 981e1d3..3c40583 100644 --- a/sys/db/drivers/firebird.php +++ b/sys/db/drivers/firebird.php @@ -151,6 +151,18 @@ SQL; // -------------------------------------------------------------------------- + /** + * Not applicable to firebird + * + * @return FALSE + */ + public function get_dbs() + { + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * List system tables for the current database * diff --git a/sys/db/drivers/mysql.php b/sys/db/drivers/mysql.php index 0196e75..9b58009 100644 --- a/sys/db/drivers/mysql.php +++ b/sys/db/drivers/mysql.php @@ -7,7 +7,7 @@ * @author Timothy J. Warren * @copyright Copyright (c) 2012 * @link https://github.com/aviat4ion/OpenSQLManager - * @license http://philsturgeon.co.uk/code/dbad-license + * @license http://philsturgeon.co.uk/code/dbad-license */ // -------------------------------------------------------------------------- @@ -21,7 +21,7 @@ class MySQL extends DB_PDO { /** * Connect to MySQL Database - * + * * @param string $dsn * @param string $username=null * @param string $password=null @@ -34,7 +34,7 @@ class MySQL extends DB_PDO { $class = __CLASS__.'_sql'; $this->sql = new $class; } - + // -------------------------------------------------------------------------- /** @@ -51,42 +51,51 @@ class MySQL extends DB_PDO { /** * Get databases for the current connection - * + * * @return array */ public function get_dbs() { $res = $this->query("SHOW DATABASES"); - return array_values($this->fetchAll(PDO::FETCH_ASSOC)); + $vals = array_values($res->fetchAll(PDO::FETCH_ASSOC)); + + $return = array(); + + foreach($vals as $v) + { + $return[] = $v['Database']; + } + + return $return; } - + // -------------------------------------------------------------------------- /** * Returns the tables available in the current database - * + * * @return array */ public function get_tables() { $res = $this->query("SHOW TABLES"); - + $tables = array(); $rows = $res->fetchAll(PDO::FETCH_NUM); - + foreach($rows as $r) { $tables[] = $r[0]; } - + return $tables; } - + // -------------------------------------------------------------------------- /** * Returns system tables for the current database - * + * * @return array */ public function get_system_tables() @@ -94,21 +103,21 @@ class MySQL extends DB_PDO { //MySQL doesn't have system tables return array(); } - + // -------------------------------------------------------------------------- /** * Return the number of rows returned for a SELECT query - * + * * @return int */ public function num_rows() { return isset($this->statement) ? $this->statement->rowCount() : FALSE; } - + // -------------------------------------------------------------------------- - + /** * Create an SQL backup file for the current database's structure * @@ -117,11 +126,11 @@ class MySQL extends DB_PDO { public function backup_structure() { // @todo Implement Backup function - return ''; + return ''; } - + // -------------------------------------------------------------------------- - + /** * Create an SQL backup file for the current database's data * @@ -147,7 +156,7 @@ class MySQL extends DB_PDO { { return array_map(array($this, 'quote_ident'), $ident); } - + // Split each identifier by the period $hiers = explode('.', $ident); diff --git a/sys/db/drivers/odbc.php b/sys/db/drivers/odbc.php index 644f4ca..6b1cfb2 100644 --- a/sys/db/drivers/odbc.php +++ b/sys/db/drivers/odbc.php @@ -44,6 +44,18 @@ class ODBC extends DB_PDO { // -------------------------------------------------------------------------- + /** + * Not applicable to firebird + * + * @return FALSE + */ + public function get_dbs() + { + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * List system tables for the current database/connection * diff --git a/sys/db/drivers/sqlite.php b/sys/db/drivers/sqlite.php index 298e636..92c60de 100644 --- a/sys/db/drivers/sqlite.php +++ b/sys/db/drivers/sqlite.php @@ -82,6 +82,18 @@ SQL; // -------------------------------------------------------------------------- + /** + * Not applicable to firebird + * + * @return FALSE + */ + public function get_dbs() + { + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * List system tables for the current database * diff --git a/sys/windows/widgets/connection_sidebar.php b/sys/windows/widgets/connection_sidebar.php index 5e49821..8f89d08 100644 --- a/sys/windows/widgets/connection_sidebar.php +++ b/sys/windows/widgets/connection_sidebar.php @@ -376,6 +376,7 @@ class Connection_Sidebar extends GtkVBox { $data = $this->treeview->get(0); DB_Reg::remove_db($data->name); + DB_Tabs::reset(); $this->refresh(); } diff --git a/sys/windows/widgets/db_tabs.php b/sys/windows/widgets/db_tabs.php index ccf2afd..9c52cb9 100644 --- a/sys/windows/widgets/db_tabs.php +++ b/sys/windows/widgets/db_tabs.php @@ -72,20 +72,6 @@ class DB_tabs extends GTKNotebook { // -------------------------------------------------------------------------- - /** - * Creates a new instance of this class, and destroys the existing - * instance - * - * @return DB_tabs - */ - public static function reset() - { - self::$instance = new DB_tabs(); - return self::get_instance(); - } - - // -------------------------------------------------------------------------- - /** * Create tabs for database aspects * @@ -94,20 +80,51 @@ class DB_tabs extends GTKNotebook { */ public static function get_db_tabs(&$conn) { - $tables = new Data_Grid(); - $table_model = $tables->get_model(); - $table_data = $conn->get_tables(); + // Empty the tabs + self::reset(); - foreach($table_data as $t) + // 'Tables' Tab { - $table_model->append(null, array($t)); - //$table_model->set($iter, 0, $t); + $tables = new Data_Grid(); + $table_model = $tables->get_model(); + $table_data = $conn->get_tables(); + + foreach($table_data as $t) + { + $table_model->append(null, array($t)); + //$table_model->set($iter, 0, $t); + } + + $cell_renderer = new GtkCellRendererText(); + $tables->insert_column_with_data_func(0, 'Table Name', $cell_renderer, array(self::$instance, 'add_data_col')); + + + self::$instance->add_tab('Tables', $tables); } - $cell_renderer = new GtkCellRendererText(); - $tables->insert_column_with_data_func(0, 'Table Name', $cell_renderer, array(self::$instance, 'add_data_col')); + // 'Databases' Tab + { + $dbs = new Data_Grid(); + $db_model = $dbs->get_model(); + $db_data = $conn->get_dbs(); + + if($db_data) + { + foreach($db_data as $d) + { + $db_model->append(null, array($d)); + } + + $cell_renderer = new GtkCellRendererText(); + $dbs->insert_column_with_data_func(0, 'DB Name', $cell_renderer, array(self::$instance, 'add_data_col')); + + self::$instance->add_tab('Databases', $dbs); + + } + + + } - self::$instance->add_tab('Tables', $tables); self::$instance->show_all(); @@ -131,5 +148,18 @@ class DB_tabs extends GTKNotebook { $data = $model->get_value($iter, $i); $cell->set_property('text', $data); } + + // -------------------------------------------------------------------------- + + /** + * Remove current tabs + */ + public static function reset() + { + for($i=0, $max=self::$instance->get_n_pages(); $i <= $max; $i++) + { + self::$instance->remove_page($i); + } + } } // End of db_tabs.php