Re-arrange ODBC and Pgsql drivers

This commit is contained in:
Timothy Warren 2012-04-09 16:54:16 -04:00
parent 5b39bdc179
commit 7b95348cd7
4 changed files with 227 additions and 279 deletions

View File

@ -41,104 +41,6 @@ class ODBC extends DB_PDO {
// --------------------------------------------------------------------------
/**
* List tables for the current database
*
* @return mixed
*/
public function get_tables()
{
//Not possible reliably with this driver
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Not applicable to ODBC
*
* @return FALSE
*/
public function get_dbs()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Not applicable to ODBC
*
* @return FALSE
*/
public function get_views()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Not applicable to ODBC
*
* @return FALSE
*/
public function get_sequences()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Not applicable to ODBC
*
* @return FALSE
*/
public function get_functions()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Not applicable to ODBC
*
* @return FALSE
*/
public function get_procedures()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Not applicable to ODBC
*
* @return FALSE
*/
public function get_triggers()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* List system tables for the current database/connection
*
* @return array
*/
public function get_system_tables()
{
//No way of determining for ODBC
return array();
}
// --------------------------------------------------------------------------
/**
* Empty the current database
*

View File

@ -88,5 +88,101 @@ class ODBC_SQL extends DB_SQL {
// Not applicable to ODBC
return '';
}
// --------------------------------------------------------------------------
/**
* Returns sql to list other databases
*
* @return FALSE
*/
public function db_list()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list tables
*
* @return FALSE
*/
public function table_list()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list system tables
*
* @return FALSE
*/
public function system_table_list()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list views
*
* @return FALSE
*/
public function view_list()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list triggers
*
* @return FALSE
*/
public function trigger_list()
{
return FALSE;
}
// --------------------------------------------------------------------------
/**
* 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 odbc_sql.php

View File

@ -64,187 +64,6 @@ class pgSQL extends DB_PDO {
// --------------------------------------------------------------------------
/**
* Get list of databases for the current connection
*
* @return array
*/
public function get_dbs()
{
$sql = <<<SQL
SELECT "datname" FROM "pg_database"
WHERE "datname" NOT IN ('template0','template1')
ORDER BY "datname" ASC
SQL;
$res = $this->query($sql);
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'datname');
}
// --------------------------------------------------------------------------
/**
* Get the list of tables for the current db
*
* @return array
*/
public function get_tables()
{
$sql = <<<SQL
SELECT "tablename" FROM "pg_tables"
WHERE "tablename" NOT LIKE 'pg_%'
AND "tablename" NOT LIKE 'sql_%'
ORDER BY "tablename" ASC
SQL;
$res = $this->query($sql);
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'tablename');
}
// --------------------------------------------------------------------------
/**
* Get the list of system tables
*
* @return array
*/
public function get_system_tables()
{
$sql = <<<SQL
SELECT "tablename" FROM "pg_tables"
WHERE "tablename" LIKE 'pg\_%'
OR "tablename" LIKE 'sql\%'
SQL;
$res = $this->query($sql);
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'tablename');
}
// --------------------------------------------------------------------------
/**
* Get a list of schemas, either for the current connection, or
* for the current datbase, if specified.
*
* @return array
*/
public function get_schemas()
{
$sql = <<<SQL
SELECT DISTINCT "schemaname" FROM "pg_tables"
WHERE "schemaname" NOT LIKE 'pg\_%'
AND "schemaname" != 'information_schema'
SQL;
$res = $this->query($sql);
$schemas = $res->fetchAll(PDO::FETCH_ASSOC);
return db_filter($schemas, 'schemaname');
}
// --------------------------------------------------------------------------
/**
* Get a list of views for the current db
*
* @return array
*/
public function get_views()
{
$sql = <<<SQL
SELECT "viewname" FROM "pg_views"
WHERE "schemaname" NOT IN
('pg_catalog', 'information_schema')
AND "viewname" !~ '^pg_'
ORDER BY "viewname" ASC
SQL;
$res = $this->query($sql);
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'viewname');
}
// --------------------------------------------------------------------------
/**
* Get a list of sequences for the current db
*
* @return array
*/
public function get_sequences()
{
$sql = <<<SQL
SELECT "c"."relname"
FROM "pg_class" "c"
WHERE "c"."relkind" = 'S'
ORDER BY "relname" ASC
SQL;
$res = $this->query($sql);
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'relname');
}
// --------------------------------------------------------------------------
/**
* Return list of custom functions for the current database
*
* @return array
*/
public function get_functions()
{
// @todo Implement
return FALSE;
}
// --------------------------------------------------------------------------
/**
* Retrun list of stored procedures for the current database
*
* @return array
*/
public function get_procedures()
{
$sql = <<<SQL
SELECT "routine_name"
FROM "information_schema"."routines"
WHERE "specific_schema" NOT IN
('pg_catalog', 'information_schema')
AND "type_udt_name" != 'trigger';
SQL;
$res = $this->query($sql);
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'routine_name');
}
// --------------------------------------------------------------------------
/**
* Return list of triggers for the current database
*
* @return array
*/
public function get_triggers()
{
$sql = <<<SQL
SELECT DISTINCT trigger_name
FROM "information_schema"."triggers"
WHERE "trigger_schema" NOT IN
('pg_catalog', 'information_schema')
SQL;
$res = $this->query($sql);
return $res->fetchAll(PDO::FETCH_ASSOC);
}
// --------------------------------------------------------------------------
/**
* Return the number of rows returned for a SELECT query
*

View File

@ -132,5 +132,136 @@ class pgSQL_SQL extends DB_SQL {
return '';
}
// --------------------------------------------------------------------------
/**
* Returns sql to list other databases
*
* @return string
*/
public function db_list()
{
return <<<SQL
SELECT "datname" FROM "pg_database"
WHERE "datname" NOT IN ('template0','template1')
ORDER BY "datname" ASC
SQL;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list tables
*
* @return string
*/
public function table_list()
{
return <<<SQL
SELECT "tablename" FROM "pg_tables"
WHERE "tablename" NOT LIKE 'pg_%'
AND "tablename" NOT LIKE 'sql_%'
ORDER BY "tablename" ASC
SQL;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list system tables
*
* @return string
*/
public function system_table_list()
{
return <<<SQL
SELECT "tablename" FROM "pg_tables"
WHERE "tablename" LIKE 'pg\_%'
OR "tablename" LIKE 'sql\%'
SQL;
}
// --------------------------------------------------------------------------
/**
* Returns sql to list views
*
* @return string
*/
public function view_list()
{
return <<<SQL
SELECT "viewname" FROM "pg_views"
WHERE "schemaname" NOT IN
('pg_catalog', 'information_schema')
AND "viewname" !~ '^pg_'
ORDER BY "viewname" ASC
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 string
*/
public function procedure_list()
{
return <<<SQL
SELECT "routine_name"
FROM "information_schema"."routines"
WHERE "specific_schema" NOT IN
('pg_catalog', 'information_schema')
AND "type_udt_name" != 'trigger';
SQL;
}
// --------------------------------------------------------------------------
/**
* Return sql to list sequences
*
* @return string
*/
public function sequence_list()
{
return <<<SQL
SELECT "c"."relname"
FROM "pg_class" "c"
WHERE "c"."relkind" = 'S'
ORDER BY "relname" ASC
SQL;
}
}
//End of pgsql_manip.php