diff --git a/sys/db/db_pdo.php b/sys/db/db_pdo.php index 73eca4f..39eeee8 100644 --- a/sys/db/db_pdo.php +++ b/sys/db/db_pdo.php @@ -134,9 +134,6 @@ abstract class DB_PDO extends PDO { $this->statement = $statement; } - // Execute the query - //$this->statement->execute(); - // Return number of rows affected return $this->statement->rowCount(); } @@ -210,74 +207,125 @@ abstract class DB_PDO extends PDO { * Method to simplify retreiving db results for meta-data queries * * @param string $sql - * @param string $filtered_index + * @param bool $filtered_index + * @return mixed */ - protected function driver_query($sql, $filtered_index="") + protected function driver_query($sql, $filtered_index=TRUE) { - $res = $this->query($sql); - $all = $res->fetchAll(PDO::FETCH_ASSOC); - - if ( ! empty($filtered_index)) + if ($sql === FALSE) { - return db_filter($all, $filtered_index); + return FALSE; } - - return $all; + + $res = $this->query($sql); + + $flag = ($filtered_index) ? PDO::FETCH_NUM : PDO::FETCH_ASSOC; + $all = $res->fetchAll($flag); + + return ($filtered_index) ? db_filter($all, 0) : $all; } - - + // ------------------------------------------------------------------------- - // ! Abstract public functions to override in child classes - // ------------------------------------------------------------------------- - + /** * Return list of tables for the current database * * @return array */ - abstract public function get_tables(); + public function get_tables() + { + return $this->driver_query($this->sql->table_list()); + } + + // ------------------------------------------------------------------------- /** * Return list of dbs for the current connection, if possible * * @return array */ - abstract public function get_dbs(); + public function get_dbs() + { + return $this->driver_query($this->sql->db_list()); + } + + // ------------------------------------------------------------------------- /** * Return list of views for the current database * * @return array */ - abstract public function get_views(); + public function get_views() + { + return $this->driver_query($this->sql->view_list()); + } + + // ------------------------------------------------------------------------- /** * Return list of sequences for the current database, if they exist * * @return array */ - abstract public function get_sequences(); + public function get_sequences() + { + return $this->driver_query($this->sql->sequence_list()); + } + + // ------------------------------------------------------------------------- /** * Return list of function for the current database * * @return array */ - abstract public function get_functions(); + public function get_functions() + { + return $this->driver_query($this->sql->function_list(), FALSE); + } + + // ------------------------------------------------------------------------- /** * Return list of stored procedures for the current database * * @return array */ - abstract public function get_procedures(); + public function get_procedures() + { + return $this->driver_query($this->sql->procedure_list(), FALSE); + } + + // ------------------------------------------------------------------------- /** * Return list of triggers for the current database * * @return array */ - abstract public function get_triggers(); + public function get_triggers() + { + return $this->driver_query($this->sql->trigger_list(), FALSE); + } + + // ------------------------------------------------------------------------- + + /** + * Retreives an array of non-user-created tables for + * the connection/database + * + * @return array + */ + public function get_system_tables() + { + return $this->driver_query($this->sql->system_table_list()); + } + + + // ------------------------------------------------------------------------- + // ! Abstract public functions to override in child classes + // ------------------------------------------------------------------------- /** * Empty the passed table @@ -295,14 +343,6 @@ abstract class DB_PDO extends PDO { */ abstract public function num_rows(); - /** - * Retreives an array of non-user-created tables for - * the connection/database - * - * @return array - */ - abstract public function get_system_tables(); - /** * Connect to a different database * diff --git a/sys/db/db_sql.php b/sys/db/db_sql.php index 106404b..43d95cf 100644 --- a/sys/db/db_sql.php +++ b/sys/db/db_sql.php @@ -60,6 +60,7 @@ abstract class DB_SQL { /** * Return an SQL file with the database table structure * + * @abstract * @return string */ abstract public function backup_structure(); @@ -67,6 +68,7 @@ abstract class DB_SQL { /** * Return an SQL file with the database data as insert statements * + * @abstract * @return string */ abstract public function backup_data(); diff --git a/sys/db/drivers/firebird/firebird_driver.php b/sys/db/drivers/firebird/firebird_driver.php index b6f5e56..7a61546 100644 --- a/sys/db/drivers/firebird/firebird_driver.php +++ b/sys/db/drivers/firebird/firebird_driver.php @@ -128,166 +128,6 @@ class firebird extends DB_PDO { // -------------------------------------------------------------------------- - /** - * List tables for the current database - * - * @return array - */ - public function get_tables() - { - $sql = <<statement = $this->query($sql); - - $tables = array(); - - while($row = $this->statement->fetch(PDO::FETCH_ASSOC)) - { - $tables[] = $row['RDB$RELATION_NAME']; - } - - return $tables; - } - - // -------------------------------------------------------------------------- - - /** - * Get list of views for the current database - * - * @return array - */ - public function get_views() - { - $sql = <<query($sql); - - return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'RDB$RELATION_NAME'); - } - - // -------------------------------------------------------------------------- - - /** - * Get list of sequences for the current database - * - * @return array - */ - public function get_sequences() - { - $sql = <<query($sql); - - return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'RDB$GENERATOR_NAME'); - } - - // -------------------------------------------------------------------------- - - /** - * Return list of custom functions for the current database - * - * @return array - */ - public function get_functions() - { - $sql = <<query($sql); - - return $res->fetchAll(PDO::FETCH_ASSOC); - } - - // -------------------------------------------------------------------------- - - /** - * 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 - * - * @return array - */ - public function get_triggers() - { - $sql = <<query($sql); - - return $res->fetchAll(PDO::FETCH_ASSOC); - } - - // -------------------------------------------------------------------------- - - - /** - * Not applicable to firebird - * - * @return FALSE - */ - public function get_dbs() - { - return FALSE; - } - - // -------------------------------------------------------------------------- - - /** - * List system tables for the current database - * - * @return array - */ - public function get_system_tables() - { - $sql = <<statement = $this->query($sql); - - $tables = array(); - - while($row = $this->statement->fetch(PDO::FETCH_ASSOC)) - { - $tables[] = $row['RDB$RELATION_NAME']; - } - - return $tables; - } - - // -------------------------------------------------------------------------- - /** * Return the number of rows returned for a SELECT query * diff --git a/sys/db/drivers/firebird/firebird_sql.php b/sys/db/drivers/firebird/firebird_sql.php index e7502b6..bea8a03 100644 --- a/sys/db/drivers/firebird/firebird_sql.php +++ b/sys/db/drivers/firebird/firebird_sql.php @@ -209,5 +209,126 @@ class Firebird_SQL extends DB_SQL { return $output_sql; } + + // -------------------------------------------------------------------------- + + /** + * Returns sql to list other databases + * + * @return FALSE + */ + public function db_list() + { + return FALSE; + } + + // -------------------------------------------------------------------------- + + /** + * Returns sql to list tables + * + * @return string + */ + public function table_list() + { + return <<