Doctrine 1.2.4
Doctrine_Import_Pgsql Class Reference

Inherits Doctrine_Import.

Public Member Functions

 databaseExists ($database)
 
 functionExists ($function)
 
 getConnection ()
 
 getModuleName ()
 
 importSchema ($directory, array $connections=array(), array $options=array())
 
 listDatabases ()
 
 listFunctions ()
 
 listSequences ($database=null)
 
 listTableColumns ($table)
 
 listTableConstraints ($table)
 
 listTableIndexes ($table)
 
 listTables ($database=null)
 
 listTableTriggers ($table)
 
 listTableViews ($table)
 
 listTriggers ($database=null)
 
 listUsers ()
 
 listViews ($database=null)
 
 sequenceExists ($sequence, $database=null)
 
 tableColumnExists ($column, $table)
 
 tableConstraintExists ($constraint, $table)
 
 tableExists ($table, $database=null)
 
 tableIndexExists ($index, $table)
 
 tableTriggerExists ($trigger, $table)
 
 tableViewExists ($view, $table)
 
 triggerExists ($trigger, $database=null)
 
 userExists ($user)
 
 viewExists ($view, $database=null)
 

Detailed Description

Definition at line 33 of file Pgsql.php.

Member Function Documentation

Doctrine_Import::databaseExists (   $database)
inherited

checks if a database exists

Parameters
string$database
Returns
boolean

Definition at line 220 of file Import.php.

{
return in_array($database, $this->listDatabases());
}
Doctrine_Import::functionExists (   $function)
inherited

checks if a function exists

Parameters
string$function
Returns
boolean

Definition at line 231 of file Import.php.

{
return in_array($function, $this->listFunctions());
}
Doctrine_Connection_Module::getConnection ( )
inherited

getConnection returns the connection object this module uses

Returns
Doctrine_Connection

Definition at line 68 of file Module.php.

{
return $this->conn;
}
Doctrine_Connection_Module::getModuleName ( )
inherited

getModuleName returns the name of this module

Returns
string the name of this module

Definition at line 79 of file Module.php.

{
return $this->moduleName;
}
Doctrine_Import::importSchema (   $directory,
array  $connections = array(),
array  $options = array() 
)
inherited

importSchema

method for importing existing schema to Doctrine_Record classes

Parameters
string$directory
array$connectionsArray of connection names to generate models for
Returns
array the names of the imported classes

Definition at line 364 of file Import.php.

{
$classes = array();
foreach ($manager as $name => $connection) {
// Limit the databases to the ones specified by $connections.
// Check only happens if array is not empty
if ( ! empty($connections) && ! in_array($name, $connections)) {
continue;
}
$builder = new Doctrine_Import_Builder();
$builder->setTargetPath($directory);
$builder->setOptions($options);
$definitions = array();
foreach ($connection->import->listTables() as $table) {
$definition = array();
$definition['tableName'] = $table;
$definition['className'] = Doctrine_Inflector::classify(Doctrine_Inflector::tableize($table));
$definition['columns'] = $connection->import->listTableColumns($table);
$definition['connection'] = $connection->getName();
$definition['connectionClassName'] = $definition['className'];
try {
$definition['relations'] = array();
$relations = $connection->import->listTableRelations($table);
$relClasses = array();
foreach ($relations as $relation) {
$table = $relation['table'];
if (in_array($class, $relClasses)) {
$alias = $class . '_' . (count($relClasses) + 1);
} else {
$alias = $class;
}
$relClasses[] = $class;
$definition['relations'][$alias] = array(
'alias' => $alias,
'class' => $class,
'local' => $relation['local'],
'foreign' => $relation['foreign']
);
}
} catch (Exception $e) {}
$definitions[strtolower($definition['className'])] = $definition;
$classes[] = $definition['className'];
}
// Build opposite end of relationships
foreach ($definitions as $definition) {
$className = $definition['className'];
$relClasses = array();
foreach ($definition['relations'] as $alias => $relation) {
if (in_array($relation['class'], $relClasses) || isset($definitions[$relation['class']]['relations'][$className])) {
$alias = $className . '_' . (count($relClasses) + 1);
} else {
$alias = $className;
}
$relClasses[] = $relation['class'];
$definitions[strtolower($relation['class'])]['relations'][$alias] = array(
'alias' => $alias,
'class' => $className,
'local' => $relation['foreign'],
'foreign' => $relation['local']
);
}
}
// Build records
foreach ($definitions as $definition) {
$builder->buildRecord($definition);
}
}
return $classes;
}
Doctrine_Import::listDatabases ( )
inherited

lists all databases

Returns
array

Definition at line 46 of file Import.php.

{
if ( ! isset($this->sql['listDatabases'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listDatabases']);
}
Doctrine_Import::listFunctions ( )
inherited

lists all availible database functions

Returns
array

Definition at line 60 of file Import.php.

{
if ( ! isset($this->sql['listFunctions'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listFunctions']);
}
Doctrine_Import::listSequences (   $database = null)
inherited

lists all database sequences

Parameters
string | null$database
Returns
array

Definition at line 86 of file Import.php.

{
if ( ! isset($this->sql['listSequences'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listSequences']);
}
Doctrine_Import_Pgsql::listTableColumns (   $table)

lists table constraints

Parameters
string$tabledatabase table name
Returns
array

Definition at line 160 of file Pgsql.php.

{
$table = $this->conn->quote($table);
$query = sprintf($this->sql['listTableColumns'], $table);
$result = $this->conn->fetchAssoc($query);
$columns = array();
foreach ($result as $key => $val) {
$val = array_change_key_case($val, CASE_LOWER);
if ($val['type'] == 'character varying') {
// get length from varchar definition
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $val['complete_type']);
$val['length'] = $length;
} else if (strpos($val['complete_type'], 'character varying') !== false) {
// get length from varchar definition
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $val['complete_type']);
$val['length'] = $length;
}
$decl = $this->conn->dataDict->getPortableDeclaration($val);
$description = array(
'name' => $val['field'],
'ntype' => $val['type'],
'type' => $decl['type'][0],
'alltypes' => $decl['type'],
'length' => $decl['length'],
'fixed' => (bool) $decl['fixed'],
'unsigned' => (bool) $decl['unsigned'],
'notnull' => ($val['isnotnull'] == 'NO'),
'default' => $val['default'],
'primary' => ($val['pri'] == 't'),
);
// If postgres enum type
if ($val['typtype'] == 'e'){
$description['default'] = isset($decl['default']) ? $decl['default'] : null;
$t_result = $this->conn->fetchAssoc(sprintf('select enum_range(null::%s) as range ', $decl['enum_name']));
if (isset($t_result[0])){
$range = $t_result[0]['range'];
$range = str_replace('{','',$range);
$range = str_replace('}','',$range);
$range = explode(',',$range);
$description['values'] = $range;
}
}
$matches = array();
if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $description['default'], $matches)) {
$description['sequence'] = $this->conn->formatter->fixSequenceName($matches[1]);
$description['default'] = null;
} else if (preg_match("/^'(.*)'::character varying$/", $description['default'], $matches)) {
$description['default'] = $matches[1];
} else if (preg_match("/^(.*)::character varying$/", $description['default'], $matches)) {
$description['default'] = $matches[1];
} else if ($description['type'] == 'boolean') {
if ($description['default'] === 'true') {
$description['default'] = true;
} else if ($description['default'] === 'false') {
$description['default'] = false;
}
}
$columns[$val['field']] = $description;
}
return $columns;
}
Doctrine_Import_Pgsql::listTableConstraints (   $table)

lists table constraints

Parameters
string$tabledatabase table name
Returns
array

Definition at line 146 of file Pgsql.php.

{
$table = $this->conn->quote($table);
$query = sprintf($this->sql['listTableConstraints'], $table);
return $this->conn->fetchColumn($query);
}
Doctrine_Import_Pgsql::listTableIndexes (   $table)

list all indexes in a table

Parameters
string$tabledatabase table name
Returns
array

Definition at line 237 of file Pgsql.php.

{
$table = $this->conn->quote($table);
$query = sprintf($this->sql['listTableIndexes'], $table);
return $this->conn->fetchColumn($query);
}
Doctrine_Import_Pgsql::listTables (   $database = null)

lists tables

Parameters
string | null$database
Returns
array

Definition at line 251 of file Pgsql.php.

{
return $this->conn->fetchColumn($this->sql['listTables']);
}
Doctrine_Import_Pgsql::listTableTriggers (   $table)

lists table triggers

Parameters
string$tabledatabase table name
Returns
array

Definition at line 262 of file Pgsql.php.

{
$query = 'SELECT trg.tgname AS trigger_name
FROM pg_trigger trg,
pg_class tbl
WHERE trg.tgrelid = tbl.oid';
if ($table !== null) {
$table = $this->conn->quote(strtoupper($table), 'string');
$query .= " AND tbl.relname = $table";
}
return $this->conn->fetchColumn($query);
}
Doctrine_Import_Pgsql::listTableViews (   $table)

list the views in the database that reference a given table

Parameters
string$tabledatabase table name
Returns
array

Definition at line 281 of file Pgsql.php.

{
return $this->conn->fetchColumn($table);
}
Doctrine_Import_Pgsql::listTriggers (   $database = null)

lists all database triggers

Parameters
string | null$database
Returns
array

Definition at line 135 of file Pgsql.php.

{
}
Doctrine_Import::listUsers ( )
inherited

lists database users

Returns
array

Definition at line 190 of file Import.php.

{
if ( ! isset($this->sql['listUsers'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listUsers']);
}
Doctrine_Import::listViews (   $database = null)
inherited

lists database views

Parameters
string | null$database
Returns
array

Definition at line 205 of file Import.php.

{
if ( ! isset($this->sql['listViews'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
return $this->conn->fetchColumn($this->sql['listViews']);
}
Doctrine_Import::sequenceExists (   $sequence,
  $database = null 
)
inherited

checks if a sequence exists

Parameters
string$sequence
string | null$database
Returns
boolean

Definition at line 255 of file Import.php.

{
return in_array($sequence, $this->listSequences($database));
}
Doctrine_Import::tableColumnExists (   $column,
  $table 
)
inherited

checks if a table column exists

Parameters
string$column
string$tabledatabase table name
Returns
boolean

Definition at line 279 of file Import.php.

{
return in_array($column, $this->listTableColumns($table));
}
Doctrine_Import::tableConstraintExists (   $constraint,
  $table 
)
inherited

checks if a table constraint exists

Parameters
string$constraint
string$tabledatabase table name
Returns
boolean

Definition at line 267 of file Import.php.

{
return in_array($constraint, $this->listTableConstraints($table));
}
Doctrine_Import::tableExists (   $table,
  $database = null 
)
inherited

checks if a table exists

Parameters
string$table
string | null$database
Returns
boolean

Definition at line 303 of file Import.php.

{
return in_array($table, $this->listTables($database));
}
Doctrine_Import::tableIndexExists (   $index,
  $table 
)
inherited

checks if a table index exists

Parameters
string$index
string$tabledatabase table name
Returns
boolean

Definition at line 291 of file Import.php.

{
return in_array($index, $this->listTableIndexes($table));
}
Doctrine_Import::tableTriggerExists (   $trigger,
  $table 
)
inherited

checks if a table trigger exists

Parameters
string$trigger
string$tabledatabase table name
Returns
boolean

Definition at line 315 of file Import.php.

{
return in_array($trigger, $this->listTableTriggers($table));
}
Doctrine_Import::tableViewExists (   $view,
  $table 
)
inherited

checks if a table view exists

Parameters
string$view
string$tabledatabase table name
Returns
boolean

Definition at line 327 of file Import.php.

{
return in_array($view, $this->listTableViews($table));
}
Doctrine_Import::triggerExists (   $trigger,
  $database = null 
)
inherited

checks if a trigger exists

Parameters
string$trigger
string | null$database
Returns
boolean

Definition at line 243 of file Import.php.

{
return in_array($trigger, $this->listTriggers($database));
}
Doctrine_Import::userExists (   $user)
inherited

checks if a user exists

Parameters
string$user
Returns
boolean

Definition at line 338 of file Import.php.

{
return in_array($user, $this->listUsers());
}
Doctrine_Import::viewExists (   $view,
  $database = null 
)
inherited

checks if a view exists

Parameters
string$view
string | null$database
Returns
boolean

Definition at line 350 of file Import.php.

{
return in_array($view, $this->listViews($database));
}

The documentation for this class was generated from the following file: