1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Refactored pgsql import driver

This commit is contained in:
zYne 2006-12-28 21:04:57 +00:00
parent dbad26258b
commit 491b156022

View File

@ -31,25 +31,10 @@ Doctrine::autoload('Doctrine_Import');
* @since 1.0
*/
class Doctrine_Import_Pgsql extends Doctrine_Import {
/**
* listDatabases
* lists all databases
*
* @return array
*/
public function listDatabases() {
$query = 'SELECT datname FROM pg_database';
return $this->conn->fetchColumn($query);
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
$query = "
SELECT
protected $sql = array(
'listDatabases' => 'SELECT datname FROM pg_database',
'listFunctions' => "SELECT
proname
FROM
pg_proc pr,
@ -59,9 +44,50 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
AND pr.proisagg = FALSE
AND tp.typname <> 'trigger'
AND pr.pronamespace IN
(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
(SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'",
'listSequences' => "SELECT
relname
FROM
pg_class
WHERE relkind = 'S' AND relnamespace IN
(SELECT oid FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')",
'listTables' => "SELECT
c.relname AS table_name
FROM pg_class c, pg_user u
WHERE c.relowner = u.usesysid
AND c.relkind = 'r'
AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname)
AND c.relname !~ '^(pg_|sql_)'
UNION
SELECT c.relname AS table_name
FROM pg_class c
WHERE c.relkind = 'r'
AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname)
AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner)
AND c.relname !~ '^pg_'",
'listViews' => 'SELECT viewname FROM pg_views',
'listUsers' => 'SELECT usename FROM pg_user'
return $this->conn->fetchColumn($query);
);
/**
* listDatabases
* lists all databases
*
* @return array
*/
public function listDatabases() {
return $this->conn->fetchColumn($this->sql['listDatabases']);
}
/**
* lists all availible database functions
*
* @return array
*/
public function listFunctions() {
return $this->conn->fetchColumn($this->sql['listFunctions']);
}
/**
* lists all database triggers
@ -79,10 +105,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public function listSequences($database = null) {
$query = "SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN";
$query.= "(SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema')";
return $this->conn->fetchColumn($query);
return $this->conn->fetchColumn($this->sql['listSequences']);
}
/**
* lists table constraints
@ -163,20 +186,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public function listTables($database = null) {
$sql = "SELECT c.relname AS table_name "
. "FROM pg_class c, pg_user u "
. "WHERE c.relowner = u.usesysid AND c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
. "AND c.relname !~ '^(pg_|sql_)' "
. "UNION "
. "SELECT c.relname AS table_name "
. "FROM pg_class c "
. "WHERE c.relkind = 'r' "
. "AND NOT EXISTS (SELECT 1 FROM pg_views WHERE viewname = c.relname) "
. "AND NOT EXISTS (SELECT 1 FROM pg_user WHERE usesysid = c.relowner) "
. "AND c.relname !~ '^pg_'";
return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
return $this->dbh->query($this->sql['listTables'])->fetchAll(PDO::FETCH_ASSOC);
}
/**
* lists table triggers
@ -194,8 +204,6 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public function listTableViews($table) {
$query = 'SELECT viewname FROM pg_views';
return $this->conn->fetchColumn($query);
}
/**
@ -204,9 +212,7 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public function listUsers() {
$query = 'SELECT usename FROM pg_user';
return $this->conn->fetchColumn($query);
return $this->conn->fetchColumn($this->sql['listUsers']);
}
/**
* lists database views
@ -215,8 +221,6 @@ class Doctrine_Import_Pgsql extends Doctrine_Import {
* @return array
*/
public function listViews($database = null) {
$query = 'SELECT viewname FROM pg_views';
return $this->conn->fetchColumn($query);
return $this->conn->fetchColumn($this->sql['listViews']);
}
}