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

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

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