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(); 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 * 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 * List system tables for the current database
* *

View File

@ -57,7 +57,16 @@ class MySQL extends DB_PDO {
public function get_dbs() public function get_dbs()
{ {
$res = $this->query("SHOW DATABASES"); $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 * 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 * List system tables for the current database
* *

View File

@ -376,6 +376,7 @@ class Connection_Sidebar extends GtkVBox {
$data = $this->treeview->get(0); $data = $this->treeview->get(0);
DB_Reg::remove_db($data->name); DB_Reg::remove_db($data->name);
DB_Tabs::reset();
$this->refresh(); $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 * Create tabs for database aspects
* *
@ -94,20 +80,51 @@ class DB_tabs extends GTKNotebook {
*/ */
public static function get_db_tabs(&$conn) public static function get_db_tabs(&$conn)
{ {
$tables = new Data_Grid(); // Empty the tabs
$table_model = $tables->get_model(); self::reset();
$table_data = $conn->get_tables();
foreach($table_data as $t) // 'Tables' Tab
{ {
$table_model->append(null, array($t)); $tables = new Data_Grid();
//$table_model->set($iter, 0, $t); $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(); // 'Databases' Tab
$tables->insert_column_with_data_func(0, 'Table Name', $cell_renderer, array(self::$instance, 'add_data_col')); {
$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(); self::$instance->show_all();
@ -131,5 +148,18 @@ class DB_tabs extends GTKNotebook {
$data = $model->get_value($iter, $i); $data = $model->get_value($iter, $i);
$cell->set_property('text', $data); $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 // End of db_tabs.php