Databases tab

This commit is contained in:
Timothy Warren 2012-04-03 11:23:53 -04:00
parent 9dd0a3c17f
commit 9b49d655d2
7 changed files with 126 additions and 43 deletions

View File

@ -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
*

View File

@ -151,6 +151,18 @@ SQL;
// --------------------------------------------------------------------------
/**
* Not applicable to firebird
*
* @return FALSE
*/
public function get_dbs()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* List system tables for the current database
*

View File

@ -57,7 +57,16 @@ class MySQL extends DB_PDO {
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;
}
// --------------------------------------------------------------------------

View File

@ -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
*

View File

@ -82,6 +82,18 @@ SQL;
// --------------------------------------------------------------------------
/**
* Not applicable to firebird
*
* @return FALSE
*/
public function get_dbs()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* List system tables for the current database
*

View File

@ -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();
}

View File

@ -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
*
@ -93,6 +79,11 @@ class DB_tabs extends GTKNotebook {
* @return void
*/
public static function get_db_tabs(&$conn)
{
// Empty the tabs
self::reset();
// 'Tables' Tab
{
$tables = new Data_Grid();
$table_model = $tables->get_model();
@ -107,7 +98,33 @@ class DB_tabs extends GTKNotebook {
$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);
}
// '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->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