Rearrang mysql and sqlite drivers

This commit is contained in:
Timothy Warren 2012-04-10 07:54:38 -04:00
parent 7b95348cd7
commit 851ff0b916
4 changed files with 211 additions and 96 deletions

View File

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

View File

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

View File

@ -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 <<<SQL
SELECT "name"
FROM "sqlite_master"
WHERE "type"='table'
ORDER BY "name" DESC
SQL;
}
// --------------------------------------------------------------------------
/**
* Overridden in SQLite class
*
* @return string
*/
public function system_table_list()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list views
*
* @return string
*/
public function view_list()
{
return <<<SQL
SELECT "name" FROM "sqlite_master" WHERE "type" = 'view'
SQL;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list triggers
*
* @return string
*/
public function trigger_list()
{
return <<<SQL
SELECT *
FROM "information_schema"."triggers"
WHERE "trigger_schema" NOT IN
('pg_catalog', 'information_schema')
SQL;
}
// --------------------------------------------------------------------------
/**
* Return sql to list functions
*
* @return FALSE
*/
public function function_list()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Return sql to list stored procedures
*
* @return FALSE
*/
public function procedure_list()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Return sql to list sequences
*
* @return FALSE
*/
public function sequence_list()
{
return FALSE;
}
}
//End of sqlite_sql.php