From f2bd843edd7e1989ef65b4517d4fbfdd1e403700 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 6 Apr 2012 21:07:49 -0400 Subject: [PATCH] Implement more meta-data methods --- sys/db/db_pdo.php | 7 ++++++ sys/db/drivers/firebird.php | 16 ++++++++++++ sys/db/drivers/mysql.php | 21 +++++++++++++--- sys/db/drivers/odbc.php | 12 +++++++++ sys/db/drivers/pgsql.php | 30 +++++++++++++++++++++-- sys/db/drivers/sqlite.php | 13 ++++++++++ sys/windows/widgets/db_tabs.php | 43 ++++++++++++++++++++++++++++++++- 7 files changed, 135 insertions(+), 7 deletions(-) diff --git a/sys/db/db_pdo.php b/sys/db/db_pdo.php index 9c44ef3..fc38176 100644 --- a/sys/db/db_pdo.php +++ b/sys/db/db_pdo.php @@ -243,6 +243,13 @@ abstract class DB_PDO extends PDO { */ abstract public function get_functions(); + /** + * Return list of stored procedures for the current database + * + * @return array + */ + abstract public function get_procedures(); + /** * Return list of triggers for the current database * diff --git a/sys/db/drivers/firebird.php b/sys/db/drivers/firebird.php index 72703c0..322e30b 100644 --- a/sys/db/drivers/firebird.php +++ b/sys/db/drivers/firebird.php @@ -209,6 +209,22 @@ SQL; // -------------------------------------------------------------------------- + /** + * Retrun list of stored procedures for the current database + * + * @return array + */ + public function get_procedures() + { + $sql = 'SELECT * FROM "RDB$PROCEDURES"'; + + $res = $this->query($sql); + + return $res->fetchAll(PDO::FETCH_ASSOC); + } + + // -------------------------------------------------------------------------- + /** * Return list of triggers for the current database * diff --git a/sys/db/drivers/mysql.php b/sys/db/drivers/mysql.php index 12a4ac5..1e25b07 100644 --- a/sys/db/drivers/mysql.php +++ b/sys/db/drivers/mysql.php @@ -107,8 +107,21 @@ class MySQL extends DB_PDO { */ public function get_functions() { - // @todo Implement - return FALSE; + $res = $this->query('SHOW FUNCTION STATUS'); + return $res->fetchAll(PDO::FETCH_ASSOC); + } + + // -------------------------------------------------------------------------- + + /** + * Retrun list of stored procedures for the current database + * + * @return array + */ + public function get_procedures() + { + $res = $this->query('SHOW PROCEDURE STATUS'); + return $res->fetchAll(PDO::FETCH_ASSOC); } // -------------------------------------------------------------------------- @@ -120,8 +133,8 @@ class MySQL extends DB_PDO { */ public function get_triggers() { - // @todo Implement - return FALSE; + $res = $this->query('SHOW TRIGGERS'); + return $res->fetchAll(PDO::FETCH_ASSOC); } // -------------------------------------------------------------------------- diff --git a/sys/db/drivers/odbc.php b/sys/db/drivers/odbc.php index 81e6c4a..0484e2c 100644 --- a/sys/db/drivers/odbc.php +++ b/sys/db/drivers/odbc.php @@ -92,6 +92,18 @@ class ODBC extends DB_PDO { // -------------------------------------------------------------------------- + /** + * Not applicable to ODBC + * + * @return FALSE + */ + public function get_procedures() + { + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * Not applicable to ODBC * diff --git a/sys/db/drivers/pgsql.php b/sys/db/drivers/pgsql.php index 89cf96e..da80583 100644 --- a/sys/db/drivers/pgsql.php +++ b/sys/db/drivers/pgsql.php @@ -191,6 +191,26 @@ SQL; // -------------------------------------------------------------------------- + /** + * Retrun list of stored procedures for the current database + * + * @return array + */ + public function get_procedures() + { + $sql = <<query($sql); + return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'routine_name'); + } + + // -------------------------------------------------------------------------- + /** * Return list of triggers for the current database * @@ -198,8 +218,14 @@ SQL; */ public function get_triggers() { - // @todo Implement - return FALSE; + $sql = <<query($sql); + return $res->fetchAll(PDO::FETCH_ASSOC); } // -------------------------------------------------------------------------- diff --git a/sys/db/drivers/sqlite.php b/sys/db/drivers/sqlite.php index 9a58a37..45d2251 100644 --- a/sys/db/drivers/sqlite.php +++ b/sys/db/drivers/sqlite.php @@ -129,6 +129,19 @@ SQL; // -------------------------------------------------------------------------- + /** + * Retrun list of stored procedures for the current database + * + * @return array + */ + public function get_procedures() + { + // @todo Implement + return FALSE; + } + + // -------------------------------------------------------------------------- + /** * Return list of triggers for the current database * diff --git a/sys/windows/widgets/db_tabs.php b/sys/windows/widgets/db_tabs.php index 814bb96..dd283e2 100644 --- a/sys/windows/widgets/db_tabs.php +++ b/sys/windows/widgets/db_tabs.php @@ -108,6 +108,16 @@ class DB_tabs extends GTKNotebook { self::_add_tab($conn, 'Sequences', 'Sequence Name', 'get_sequences'); } + // 'Triggers' Tab + { + //self::_add_tab($conn, 'Triggers', 'Trigger Name', 'get_triggers'); + } + + // 'Procedures' Tab + { + //self::_add_tab($conn, 'Procedures', 'Procedure Name', 'get_procedures'); + } + self::$instance->show_all(); @@ -169,7 +179,7 @@ class DB_tabs extends GTKNotebook { $tab_data = call_user_func_array(array($conn, $method), $params); - if($tab_data !== FALSE) + if ($tab_data !== FALSE) { foreach($tab_data as $d) { @@ -183,5 +193,36 @@ class DB_tabs extends GTKNotebook { } } + + // -------------------------------------------------------------------------- + + /** + * Simplify adding multi-level array to the Notebook object + * + * @param object $conn + * @param string $tab_name + * @param string $col_name + * @param string $method + * @return void + */ + /*private static function _add_multi_level_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), $params); + + if ($tab_data !== FALSE) + { + for($i=0, $c=count($tab_data); $i < $c; $i++) + { + $j = 0; + foreach($tab_data[$i] as $key => $val) + { + + } + } + } + }*/ } // End of db_tabs.php