From 851ff0b916b35d499f8219aa4c3c22a9fd62f262 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 10 Apr 2012 07:54:38 -0400 Subject: [PATCH] Rearrang mysql and sqlite drivers --- sys/db/drivers/mysql/mysql_driver.php | 90 --------------------- sys/db/drivers/mysql/mysql_sql.php | 106 +++++++++++++++++++++++-- sys/db/drivers/sqlite/sqlite_sql.php | 109 ++++++++++++++++++++++++++ tests/databases/sqlite.php | 2 +- 4 files changed, 211 insertions(+), 96 deletions(-) diff --git a/sys/db/drivers/mysql/mysql_driver.php b/sys/db/drivers/mysql/mysql_driver.php index 38d8ede..d76e319 100644 --- a/sys/db/drivers/mysql/mysql_driver.php +++ b/sys/db/drivers/mysql/mysql_driver.php @@ -62,96 +62,6 @@ class MySQL extends DB_PDO { // -------------------------------------------------------------------------- - /** - * Get databases for the current connection - * - * @return array - */ - public function get_dbs() - { - $res = $this->query("SHOW DATABASES WHERE `Database` !='information_schema'"); - return db_filter(array_values($res->fetchAll(PDO::FETCH_ASSOC)), 'Database'); - } - - // -------------------------------------------------------------------------- - - /** - * Returns the tables available in the current database - * - * @return array - */ - public function get_tables() - { - $res = $this->query('SHOW TABLES'); - return db_filter($res->fetchAll(PDO::FETCH_NUM), 0); - } - - // -------------------------------------------------------------------------- - - /** - * Get list of views for the current database - * - * @return array - */ - public function get_views() - { - $res = $this->query('SELECT `table_name` FROM `information_schema`.`views`'); - return db_filter($res->fetchAll(PDO::FETCH_NUM), 'table_name'); - } - - // -------------------------------------------------------------------------- - - /** - * Not applicable to MySQL - * - * @return FALSE - */ - public function get_sequences() - { - return FALSE; - } - - // -------------------------------------------------------------------------- - - /** - * Return list of custom functions for the current database - * - * @return array - */ - public function get_functions() - { - $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); - } - - // -------------------------------------------------------------------------- - - /** - * Return list of triggers for the current database - * - * @return array - */ - public function get_triggers() - { - $res = $this->query('SHOW TRIGGERS'); - return $res->fetchAll(PDO::FETCH_ASSOC); - } - - // -------------------------------------------------------------------------- - /** * Returns system tables for the current database * diff --git a/sys/db/drivers/mysql/mysql_sql.php b/sys/db/drivers/mysql/mysql_sql.php index 20195e6..0465845 100644 --- a/sys/db/drivers/mysql/mysql_sql.php +++ b/sys/db/drivers/mysql/mysql_sql.php @@ -20,12 +20,12 @@ class MySQL_SQL extends DB_SQL{ /** * Convienience public function for creating a new MySQL table * - * @param [type] $name [description] - * @param [type] $columns [description] - * @param array $constraints=array() [description] - * @param array $indexes=array() [description] + * @param string $name + * @param array $columns + * @param array $constraints=array() + * @param array $indexes=array() * - * @return [type] + * @return string */ public function create_table($name, $columns, array $constraints=array(), array $indexes=array()) { @@ -155,5 +155,101 @@ class MySQL_SQL extends DB_SQL{ // @todo Implement Backup function return ''; } + + // -------------------------------------------------------------------------- + + /** + * Returns sql to list other databases + * + * @return string + */ + public function db_list() + { + return "SHOW DATABASES WHERE `Database` !='information_schema'"; + } + + // -------------------------------------------------------------------------- + + /** + * Returns sql to list tables + * + * @return string + */ + public function table_list() + { + return 'SHOW TABLES'; + } + + // -------------------------------------------------------------------------- + + /** + * Overridden in MySQL class + * + * @return string + */ + public function system_table_list() + { + return FALSE; + } + + // -------------------------------------------------------------------------- + + /** + * Returns sql to list views + * + * @return string + */ + public function view_list() + { + return 'SELECT `table_name` FROM `information_schema`.`views`'; + } + + // -------------------------------------------------------------------------- + + /** + * Returns sql to list triggers + * + * @return string + */ + public function trigger_list() + { + return 'SHOW TRIGGERS'; + } + + // -------------------------------------------------------------------------- + + /** + * Return sql to list functions + * + * @return string + */ + public function function_list() + { + return 'SHOW FUNCTION STATUS'; + } + + // -------------------------------------------------------------------------- + + /** + * Return sql to list stored procedures + * + * @return string + */ + public function procedure_list() + { + return 'SHOW PROCEDURE STATUS'; + } + + // -------------------------------------------------------------------------- + + /** + * Return sql to list sequences + * + * @return FALSE + */ + public function sequence_list() + { + return FALSE; + } } //End of mysql_sql.php \ No newline at end of file diff --git a/sys/db/drivers/sqlite/sqlite_sql.php b/sys/db/drivers/sqlite/sqlite_sql.php index 290f7fb..a814632 100644 --- a/sys/db/drivers/sqlite/sqlite_sql.php +++ b/sys/db/drivers/sqlite/sqlite_sql.php @@ -209,5 +209,114 @@ class SQLite_SQL extends DB_SQL { return $sql_structure; } + + // -------------------------------------------------------------------------- + + /** + * 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 <<assertFalse($this->db->get_dbs()); } - + function TestGetSchemas() { $this->assertFalse($this->db->get_schemas());