Moar tabs!

And better schema retreiving method for Postgres
This commit is contained in:
Timothy Warren 2012-04-06 16:36:50 -04:00
parent 7c25981fcb
commit 13b3f36d02
3 changed files with 26 additions and 15 deletions

View File

@ -195,8 +195,18 @@ abstract class DB_PDO extends PDO {
// -------------------------------------------------------------------------
/**
* Abstract public functions to override in child classes
* Return schemas for databases that list them
*
* @return array
*/
public function get_schemas()
{
return FALSE;
}
// -------------------------------------------------------------------------
// ! Abstract public functions to override in child classes
// -------------------------------------------------------------------------
/**
* Return list of tables for the current database

View File

@ -117,29 +117,20 @@ SQL;
* Get a list of schemas, either for the current connection, or
* for the current datbase, if specified.
*
* @param string $database=""
* @return array
*/
public function get_schemas($database="")
{
if($database === "")
public function get_schemas()
{
$sql = <<<SQL
SELECT DISTINCT "schemaname" FROM "pg_tables"
WHERE "schemaname" NOT LIKE 'pg\_%'
SQL;
}
$sql = <<<SQL
SELECT "nspname" FROM pg_namespace
WHERE "nspname" NOT LIKE 'pg\_%'
AND "schemaname" != 'information_schema'
SQL;
$res = $this->query($sql);
$schemas = $res->fetchAll(PDO::FETCH_ASSOC);
return $schemas;
return db_filter($schemas, 'schemaname');
}
// --------------------------------------------------------------------------

View File

@ -88,6 +88,11 @@ class DB_tabs extends GTKNotebook {
self::_add_tab($conn, 'Databases', 'Db Name', 'get_dbs');
}
// 'Schemas' Tab
{
self::_add_tab($conn, 'Schemas', 'Schema Name', 'get_schemas');
}
// 'Tables' Tab
{
self::_add_tab($conn, 'Tables', 'Table Name', 'get_tables');
@ -98,6 +103,11 @@ class DB_tabs extends GTKNotebook {
self::_add_tab($conn, 'Views', 'View Name', 'get_views');
}
// 'Sequences' Tab
{
self::_add_tab($conn, 'Sequences', 'Sequence Name', 'get_sequences');
}
self::$instance->show_all();
@ -152,12 +162,12 @@ class DB_tabs extends GTKNotebook {
* @param string $method
* @return void
*/
private static function _add_tab(&$conn, $tab_name, $col_name, $method)
private static function _add_tab(&$conn, $tab_name, $col_name, $method, $params=array())
{
$tab = new Data_Grid();
$tab_model = $tab->get_model();
$tab_data = call_user_func_array(array($conn, $method), array());
$tab_data = call_user_func_array(array($conn, $method), $params);
if($tab_data !== FALSE)
{