Doctrine 1.2.4
Doctrine_Export_Pgsql Class Reference

Inherits Doctrine_Export.

Public Member Functions

 alterTable ($name, array $changes, $check=false)
 
 alterTableSql ($name, array $changes, $check=false)
 
 createConstraint ($table, $name, $definition)
 
 createConstraintSql ($table, $name, $definition)
 
 createDatabase ($database)
 
 createDatabaseSql ($name)
 
 createForeignKey ($table, array $definition)
 
 createForeignKeySql ($table, array $definition)
 
 createIndex ($table, $name, array $definition)
 
 createIndexSql ($table, $name, array $definition)
 
 createSequence ($seqName, $start=1, array $options=array())
 
 createSequenceSql ($sequenceName, $start=1, array $options=array())
 
 createTable ($name, array $fields, array $options=array())
 
 createTableSql ($name, array $fields, array $options=array())
 
 dropConstraint ($table, $name, $primary=false)
 
 dropDatabase ($database)
 
 dropDatabaseSql ($name)
 
 dropForeignKey ($table, $name)
 
 dropIndex ($table, $name)
 
 dropIndexSql ($table, $name)
 
 dropSequence ($sequenceName)
 
 dropSequenceSql ($sequenceName)
 
 dropTable ($table)
 
 dropTableSql ($table)
 
 exportClasses (array $classes)
 
 exportClassesSql (array $classes)
 
 exportGeneratorsSql (Doctrine_Table $table)
 
 exportSchema ($directory=null)
 
 exportSql ($directory=null)
 
 exportTable (Doctrine_Table $table)
 
 getAdvancedForeignKeyOptions (array $definition)
 
 getAllGenerators (Doctrine_Table $table)
 
 getCharsetFieldDeclaration ($charset)
 
 getCheckDeclaration (array $definition)
 
 getCollationFieldDeclaration ($collation)
 
 getConnection ()
 
 getDeclaration ($name, array $field)
 
 getDefaultFieldDeclaration ($field)
 
 getFieldDeclarationList (array $fields)
 
 getForeignKeyBaseDeclaration (array $definition)
 
 getForeignKeyDeclaration (array $definition)
 
 getForeignKeyReferentialAction ($action)
 
 getIndexDeclaration ($name, array $definition)
 
 getIndexFieldDeclarationList (array $fields)
 
 getModuleName ()
 
 getNotNullFieldDeclaration (array $definition)
 
 getTemporaryTableQuery ()
 
 getUniqueFieldDeclaration ()
 

Detailed Description

Definition at line 34 of file Pgsql.php.

Member Function Documentation

Doctrine_Export_Pgsql::alterTable (   $name,
array  $changes,
  $check = false 
)

alter an existing table

Parameters
string$namename of the table that is intended to be changed.
array$changesassociative array that contains the details of each type of change that is intended to be performed. The types of changes that are currently supported are defined as follows:

name

New name for the table.

add

Associative array with the names of fields to be added as
 indexes of the array. The value of each entry of the array
 should be set to another associative array with the properties
 of the fields to be added. The properties of the fields should
 be the same as defined by the Metabase parser.

remove

Associative array with the names of fields to be removed as indexes
 of the array. Currently the values assigned to each entry are ignored.
 An empty array should be used for future compatibility.

rename

Associative array with the names of fields to be renamed as indexes
 of the array. The value of each entry of the array should be set to
 another associative array with the entry named name with the new
 field name and the entry named Declaration that is expected to contain
 the portion of the field declaration already in DBMS specific SQL code
 as it is used in the CREATE TABLE statement.

change

Associative array with the names of the fields to be changed as indexes
 of the array. Keep in mind that if it is intended to change either the
 name of a field and any other properties, the change array entries
 should have the new names of the fields as array indexes.

The value of each entry of the array should be set to another associative
 array with the properties of the fields to that are meant to be changed as
 array entries. These entries should be assigned to the new values of the
 respective properties. The properties of the fields should be the same
 as defined by the Metabase parser.

Example array( 'name' => 'userlist', 'add' => array( 'quota' => array( 'type' => 'integer', 'unsigned' => 1 ) ), 'remove' => array( 'file_limit' => array(), 'time_limit' => array() ), 'change' => array( 'name' => array( 'length' => '20', 'definition' => array( 'type' => 'text', 'length' => 20, ), ) ), 'rename' => array( 'sex' => array( 'name' => 'gender', 'definition' => array( 'type' => 'text', 'length' => 1, 'default' => 'M', ), ) ) )

Parameters
boolean$checkindicates whether the function should just check if the DBMS driver can perform the requested table alterations if the value is true or actually perform them otherwise.
Exceptions
Doctrine_Connection_Exception
Returns
boolean

Definition at line 274 of file Pgsql.php.

{
$sql = $this->alterTableSql($name, $changes, $check);
foreach ($sql as $query) {
$this->conn->exec($query);
}
return true;
}
Doctrine_Export_Pgsql::alterTableSql (   $name,
array  $changes,
  $check = false 
)

generates the sql for altering an existing table on postgresql

Parameters
string$namename of the table that is intended to be changed.
array$changesassociative array that contains the details of each type *
boolean$checkindicates whether the function should just check if the DBMS driver can perform the requested table alterations if the value is true or actually perform them otherwise.
See Also
Doctrine_Export::alterTable()
Returns
array

Definition at line 110 of file Pgsql.php.

{
foreach ($changes as $changeName => $change) {
switch ($changeName) {
case 'add':
case 'remove':
case 'change':
case 'name':
case 'rename':
break;
default:
throw new Doctrine_Export_Exception('change type "' . $changeName . '\" not yet supported');
}
}
if ($check) {
return true;
}
$sql = array();
if (isset($changes['add']) && is_array($changes['add'])) {
foreach ($changes['add'] as $fieldName => $field) {
$query = 'ADD ' . $this->getDeclaration($fieldName, $field);
$sql[] = 'ALTER TABLE ' . $this->conn->quoteIdentifier($name, true) . ' ' . $query;
}
}
if (isset($changes['remove']) && is_array($changes['remove'])) {
foreach ($changes['remove'] as $fieldName => $field) {
$fieldName = $this->conn->quoteIdentifier($fieldName, true);
$query = 'DROP ' . $fieldName;
$sql[] = 'ALTER TABLE ' . $this->conn->quoteIdentifier($name, true) . ' ' . $query;
}
}
if (isset($changes['change']) && is_array($changes['change'])) {
foreach ($changes['change'] as $fieldName => $field) {
$fieldName = $this->conn->quoteIdentifier($fieldName, true);
if (isset($field['definition']['type'])) {
$serverInfo = $this->conn->getServerVersion();
if (is_array($serverInfo) && $serverInfo['major'] < 8) {
throw new Doctrine_Export_Exception('changing column type for "'.$field['type'].'\" requires PostgreSQL 8.0 or above');
}
$query = 'ALTER ' . $fieldName . ' TYPE ' . $this->conn->dataDict->getNativeDeclaration($field['definition']);
$sql[] = 'ALTER TABLE ' . $this->conn->quoteIdentifier($name, true) . ' ' . $query;
}
if (array_key_exists('default', $field['definition'])) {
$query = 'ALTER ' . $fieldName . ' SET DEFAULT ' . $this->conn->quote($field['definition']['default'], $field['definition']['type']);
$sql[] = 'ALTER TABLE ' . $this->conn->quoteIdentifier($name, true) . ' ' . $query;
}
if ( ! empty($field['definition']['notnull'])) {
$query = 'ALTER ' . $fieldName . ' ' . ($field['definition']['notnull'] ? 'SET' : 'DROP') . ' NOT NULL';
$sql[] = 'ALTER TABLE ' . $this->conn->quoteIdentifier($name, true) . ' ' . $query;
}
}
}
if (isset($changes['rename']) && is_array($changes['rename'])) {
foreach ($changes['rename'] as $fieldName => $field) {
$fieldName = $this->conn->quoteIdentifier($fieldName, true);
$sql[] = 'ALTER TABLE ' . $this->conn->quoteIdentifier($name, true) . ' RENAME COLUMN ' . $fieldName . ' TO ' . $this->conn->quoteIdentifier($field['name'], true);
}
}
$name = $this->conn->quoteIdentifier($name, true);
if (isset($changes['name'])) {
$changeName = $this->conn->quoteIdentifier($changes['name'], true);
$sql[] = 'ALTER TABLE ' . $this->conn->quoteIdentifier($name, true) . ' RENAME TO ' . $changeName;
}
return $sql;
}
Doctrine_Export::createConstraint (   $table,
  $name,
  $definition 
)
inherited

create a constraint on a table

Parameters
string$tablename of the table on which the constraint is to be created
string$namename of the constraint to be created
array$definitionassociative array that defines properties of the constraint to be created. Currently, only one property named FIELDS is supported. This property is also an associative with the names of the constraint fields as array constraints. Each entry of this array is set to another type of associative array that specifies properties of the constraint that are specific to each field.

Example array( 'fields' => array( 'user_name' => array(), 'last_login' => array() ) )

Returns
void

Definition at line 376 of file Export.php.

{
$sql = $this->createConstraintSql($table, $name, $definition);
return $this->conn->exec($sql);
}
Doctrine_Export::createConstraintSql (   $table,
  $name,
  $definition 
)
inherited

create a constraint on a table

Parameters
string$tablename of the table on which the constraint is to be created
string$namename of the constraint to be created
array$definitionassociative array that defines properties of the constraint to be created. Currently, only one property named FIELDS is supported. This property is also an associative with the names of the constraint fields as array constraints. Each entry of this array is set to another type of associative array that specifies properties of the constraint that are specific to each field.

Example array( 'fields' => array( 'user_name' => array(), 'last_login' => array() ) )

Returns
void

Definition at line 404 of file Export.php.

{
$table = $this->conn->quoteIdentifier($table);
$name = $this->conn->quoteIdentifier($this->conn->formatter->getIndexName($name));
$query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $name;
if (isset($definition['primary']) && $definition['primary']) {
$query .= ' PRIMARY KEY';
} elseif (isset($definition['unique']) && $definition['unique']) {
$query .= ' UNIQUE';
}
$fields = array();
foreach (array_keys($definition['fields']) as $field) {
$fields[] = $this->conn->quoteIdentifier($field, true);
}
$query .= ' ('. implode(', ', $fields) . ')';
return $query;
}
Doctrine_Export::createDatabase (   $database)
inherited

create a new database (this method is implemented by the drivers)

Parameters
string$namename of the database that should be created
Returns
void

Definition at line 188 of file Export.php.

{
$this->conn->execute($this->createDatabaseSql($database));
}
Doctrine_Export_Pgsql::createDatabaseSql (   $name)

createDatabaseSql

Parameters
string$name
Returns
void

Definition at line 44 of file Pgsql.php.

{
$query = 'CREATE DATABASE ' . $this->conn->quoteIdentifier($name);
return $query;
}
Doctrine_Export::createForeignKey (   $table,
array  $definition 
)
inherited

createForeignKey

Parameters
string$tablename of the table on which the foreign key is to be created
array$definitionassociative array that defines properties of the foreign key to be created.
Returns
string

Definition at line 520 of file Export.php.

{
$sql = $this->createForeignKeySql($table, $definition);
return $this->conn->execute($sql);
}
Doctrine_Export::createForeignKeySql (   $table,
array  $definition 
)
inherited

createForeignKeySql

Parameters
string$tablename of the table on which the foreign key is to be created
array$definitionassociative array that defines properties of the foreign key to be created.
Returns
string

Definition at line 505 of file Export.php.

{
$table = $this->conn->quoteIdentifier($table);
$query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclaration($definition);
return $query;
}
Doctrine_Export::createIndex (   $table,
  $name,
array  $definition 
)
inherited

Get the stucture of a field into an array

Parameters
string$tablename of the table on which the index is to be created
string$namename of the index to be created
array$definitionassociative array that defines properties of the index to be created. Currently, only one property named FIELDS is supported. This property is also an associative with the names of the index fields as array indexes. Each entry of this array is set to another type of associative array that specifies properties of the index that are specific to each field.

Currently, only the sorting property is supported. It should be used to define the sorting direction of the index. It may be set to either ascending or descending.

Not all DBMS support index sorting direction configuration. The DBMS drivers of those that do not support it ignore this property. Use the function supports() to determine whether the DBMS driver can manage indexes.

Example array( 'fields' => array( 'user_name' => array( 'sorting' => 'ascending' ), 'last_login' => array() ) )

Returns
void

Definition at line 456 of file Export.php.

{
return $this->conn->execute($this->createIndexSql($table, $name, $definition));
}
Doctrine_Export_Pgsql::createIndexSql (   $table,
  $name,
array  $definition 
)

Get the stucture of a field into an array.

Parameters
string$tablename of the table on which the index is to be created
string$namename of the index to be created
array$definitionassociative array that defines properties of the index to be created.
See Also
Doctrine_Export::createIndex()
Returns
string

Definition at line 385 of file Pgsql.php.

{
$query = parent::createIndexSql($table, $name, $definition);
if (isset($definition['where'])) {
return $query . ' WHERE ' . $definition['where'];
}
return $query;
}
Doctrine_Export::createSequence (   $seqName,
  $start = 1,
array  $options = array() 
)
inherited

create sequence

Exceptions
Doctrine_Connection_Exceptionif something fails at database level
Parameters
string$seqNamename of the sequence to be created
string$startstart value of the sequence; default is 1
array$optionsAn associative array of table options: array( 'comment' => 'Foo', 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci', );
Returns
void

Definition at line 330 of file Export.php.

{
return $this->conn->execute($this->createSequenceSql($seqName, $start = 1, $options));
}
Doctrine_Export_Pgsql::createSequenceSql (   $sequenceName,
  $start = 1,
array  $options = array() 
)

return RDBMS specific create sequence statement

Exceptions
Doctrine_Connection_Exceptionif something fails at database level
Parameters
string$seqNamename of the sequence to be created
string$startstart value of the sequence; default is 1
array$optionsAn associative array of table options: array( 'comment' => 'Foo', 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci', );
Returns
string

Definition at line 297 of file Pgsql.php.

{
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($sequenceName), true);
return 'CREATE SEQUENCE ' . $sequenceName . ' INCREMENT 1' .
($start < 1 ? ' MINVALUE ' . $start : '') . ' START ' . $start;
}
Doctrine_Export::createTable (   $name,
array  $fields,
array  $options = array() 
)
inherited

create a new table

Parameters
string$nameName of the database that should be created
array$fieldsAssociative array that contains the definition of each field of the new table
array$optionsAn associative array of table options:
See Also
Doctrine_Export::createTableSql()
Returns
void

Definition at line 294 of file Export.php.

{
// Build array of the primary keys if any of the individual field definitions
// specify primary => true
$count = 0;
foreach ($fields as $fieldName => $field) {
if (isset($field['primary']) && $field['primary']) {
if ($count == 0) {
$options['primary'] = array();
}
$count++;
$options['primary'][] = $fieldName;
}
}
$sql = (array) $this->createTableSql($name, $fields, $options);
foreach ($sql as $query) {
$this->conn->execute($query);
}
}
Doctrine_Export_Pgsql::createTableSql (   $name,
array  $fields,
array  $options = array() 
)

Creates a table.

Parameters
unknown_type$name
array$fields
array$options
Returns
unknown

Definition at line 323 of file Pgsql.php.

{
if ( ! $name) {
throw new Doctrine_Export_Exception('no valid table name specified');
}
if (empty($fields)) {
throw new Doctrine_Export_Exception('no fields specified for table ' . $name);
}
$queryFields = $this->getFieldDeclarationList($fields);
if (isset($options['primary']) && ! empty($options['primary'])) {
$keyColumns = array_values($options['primary']);
$keyColumns = array_map(array($this->conn, 'quoteIdentifier'), $keyColumns);
$queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
}
$query = 'CREATE TABLE ' . $this->conn->quoteIdentifier($name, true) . ' (' . $queryFields;
if ($check = $this->getCheckDeclaration($fields)) {
$query .= ', ' . $check;
}
if (isset($options['checks']) && $check = $this->getCheckDeclaration($options['checks'])) {
$query .= ', ' . $check;
}
$query .= ')';
$sql[] = $query;
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach($options['indexes'] as $index => $definition) {
$sql[] = $this->createIndexSql($name, $index, $definition);
}
}
if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $k => $definition) {
if (is_array($definition)) {
$sql[] = $this->createForeignKeySql($name, $definition);
}
}
}
if (isset($options['sequenceName'])) {
$sql[] = $this->createSequenceSql($options['sequenceName']);
}
return $sql;
}
Doctrine_Export::dropConstraint (   $table,
  $name,
  $primary = false 
)
inherited

drop existing constraint

Parameters
string$tablename of table that should be used in method
string$namename of the constraint to be dropped
string$primaryhint if the constraint is primary
Returns
void

Definition at line 134 of file Export.php.

{
$table = $this->conn->quoteIdentifier($table);
$name = $this->conn->quoteIdentifier($name);
return $this->conn->exec('ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $name);
}
Doctrine_Export::dropDatabase (   $database)
inherited

drop an existing database (this method is implemented by the drivers)

Parameters
string$namename of the database that should be dropped
Returns
void

Definition at line 57 of file Export.php.

{
foreach ((array) $this->dropDatabaseSql($database) as $query) {
$this->conn->execute($query);
}
}
Doctrine_Export_Pgsql::dropDatabaseSql (   $name)

drop an existing database

Parameters
string$namename of the database that should be dropped
Exceptions
PDOExceptionpublic

Definition at line 58 of file Pgsql.php.

{
$query = 'DROP DATABASE ' . $this->conn->quoteIdentifier($name);
return $query;
}
Doctrine_Export::dropForeignKey (   $table,
  $name 
)
inherited

drop existing foreign key

Parameters
string$tablename of table that should be used in method
string$namename of the foreign key to be dropped
Returns
void

Definition at line 149 of file Export.php.

{
return $this->dropConstraint($table, $this->conn->formatter->getForeignKeyName($name));
}
Doctrine_Export::dropIndex (   $table,
  $name 
)
inherited

drop existing index

Parameters
string$tablename of table that should be used in method
string$namename of the index to be dropped
Returns
void

Definition at line 107 of file Export.php.

{
return $this->conn->exec($this->dropIndexSql($table, $name));
}
Doctrine_Export::dropIndexSql (   $table,
  $name 
)
inherited

dropIndexSql

Parameters
string$tablename of table that should be used in method
string$namename of the index to be dropped
Returns
string SQL that is used for dropping an index

Definition at line 119 of file Export.php.

{
$name = $this->conn->quoteIdentifier($this->conn->formatter->getIndexName($name));
return 'DROP INDEX ' . $name;
}
Doctrine_Export::dropSequence (   $sequenceName)
inherited

dropSequenceSql drop existing sequence (this method is implemented by the drivers)

Exceptions
Doctrine_Connection_Exceptionif something fails at database level
Parameters
string$sequenceNamename of the sequence to be dropped
Returns
void

Definition at line 163 of file Export.php.

{
$this->conn->exec($this->dropSequenceSql($sequenceName));
}
Doctrine_Export_Pgsql::dropSequenceSql (   $sequenceName)

drop existing sequence

Parameters
string$sequenceNamename of the sequence to be dropped

Definition at line 309 of file Pgsql.php.

{
$sequenceName = $this->conn->quoteIdentifier($this->conn->formatter->getSequenceName($sequenceName), true);
return 'DROP SEQUENCE ' . $sequenceName;
}
Doctrine_Export::dropTable (   $table)
inherited

dropTable drop an existing table

Parameters
string$tablename of table that should be dropped from the database
Returns
void

Definition at line 95 of file Export.php.

{
$this->conn->execute($this->dropTableSql($table));
}
Doctrine_Export::dropTableSql (   $table)
inherited

dropTableSql drop an existing table

Parameters
string$tablename of table that should be dropped from the database
Returns
string

Definition at line 83 of file Export.php.

{
return 'DROP TABLE ' . $this->conn->quoteIdentifier($table);
}
Doctrine_Export::exportClasses ( array  $classes)
inherited

exportClasses method for exporting Doctrine_Record classes to a schema

FIXME: This function has ugly hacks in it to make sure sql is inserted in the correct order.

Exceptions
Doctrine_Connection_Exceptionif some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation
Parameters
array$classes
Returns
void

Definition at line 1203 of file Export.php.

{
$queries = $this->exportSortedClassesSql($classes);
foreach ($queries as $connectionName => $sql) {
$connection = Doctrine_Manager::getInstance()->getConnection($connectionName);
$connection->beginTransaction();
foreach ($sql as $query) {
try {
$connection->exec($query);
// we only want to silence table already exists errors
if ($e->getPortableCode() !== Doctrine_Core::ERR_ALREADY_EXISTS) {
$connection->rollback();
throw new Doctrine_Export_Exception($e->getMessage() . '. Failing Query: ' . $query);
}
}
}
$connection->commit();
}
}
Doctrine_Export::exportClassesSql ( array  $classes)
inherited

exportClassesSql method for exporting Doctrine_Record classes to a schema

Exceptions
Doctrine_Connection_Exceptionif some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation
Parameters
array$classes
Returns
void

Definition at line 1237 of file Export.php.

{
$sql = array();
foreach ($models as $name) {
$record = new $name();
$table = $record->getTable();
$parents = $table->getOption('joinedParents');
foreach ($parents as $parent) {
$data = $table->getConnection()->getTable($parent)->getExportableFormat();
$query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']);
$sql = array_merge($sql, (array) $query);
}
// Don't export the tables with attribute EXPORT_NONE'
if ($table->getAttribute(Doctrine_Core::ATTR_EXPORT) === Doctrine_Core::EXPORT_NONE) {
continue;
}
$data = $table->getExportableFormat();
$query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']);
if (is_array($query)) {
$sql = array_merge($sql, $query);
} else {
$sql[] = $query;
}
if ($table->getAttribute(Doctrine_Core::ATTR_EXPORT) & Doctrine_Core::EXPORT_PLUGINS) {
$sql = array_merge($sql, $this->exportGeneratorsSql($table));
}
// DC-474: Remove dummy $record from repository to not pollute it during export
$table->getRepository()->evict($record->getOid());
unset($record);
}
$sql = array_unique($sql);
rsort($sql);
return $sql;
}
Doctrine_Export::exportGeneratorsSql ( Doctrine_Table  $table)
inherited

exportGeneratorsSql exports plugin tables for given table

Parameters
Doctrine_Table$tablethe table in which the generators belong to
Returns
array an array of sql strings

Definition at line 1321 of file Export.php.

{
$sql = array();
foreach ($this->getAllGenerators($table) as $name => $generator) {
$table = $generator->getTable();
// Make sure plugin has a valid table
if ($table instanceof Doctrine_Table) {
$data = $table->getExportableFormat();
$query = $this->conn->export->createTableSql($data['tableName'], $data['columns'], $data['options']);
$sql = array_merge($sql, (array) $query);
}
}
return $sql;
}
Doctrine_Export::exportSchema (   $directory = null)
inherited

exportSchema method for exporting Doctrine_Record classes to a schema

if the directory parameter is given this method first iterates recursively trhough the given directory in order to find any model classes

Then it iterates through all declared classes and creates tables for the ones that extend Doctrine_Record and are not abstract classes

Exceptions
Doctrine_Connection_Exceptionif some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation
Parameters
string$directoryoptional directory parameter
Returns
void

Definition at line 1092 of file Export.php.

{
if ($directory !== null) {
} else {
}
$this->exportClasses($models);
}
Doctrine_Export::exportSql (   $directory = null)
inherited

exportSql returns the sql for exporting Doctrine_Record classes to a schema

if the directory parameter is given this method first iterates recursively trhough the given directory in order to find any model classes

Then it iterates through all declared classes and creates tables for the ones that extend Doctrine_Record and are not abstract classes

Exceptions
Doctrine_Connection_Exceptionif some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation
Parameters
string$directoryoptional directory parameter
Returns
void

Definition at line 1356 of file Export.php.

{
if ($directory !== null) {
} else {
}
return $this->exportSortedClassesSql($models, false);
}
Doctrine_Export::exportTable ( Doctrine_Table  $table)
inherited

exportTable exports given table into database based on column and option definitions

Exceptions
Doctrine_Connection_Exceptionif some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation
Returns
boolean whether or not the export operation was successful false if table already existed in the database

Definition at line 1376 of file Export.php.

{
try {
$data = $table->getExportableFormat();
$this->conn->export->createTable($data['tableName'], $data['columns'], $data['options']);
// we only want to silence table already exists errors
if ($e->getPortableCode() !== Doctrine_Core::ERR_ALREADY_EXISTS) {
throw $e;
}
}
}
Doctrine_Export_Pgsql::getAdvancedForeignKeyOptions ( array  $definition)

getAdvancedForeignKeyOptions Return the FOREIGN KEY query section dealing with non-standard options as MATCH, INITIALLY DEFERRED, ON UPDATE, ...

Parameters
array$definitionforeign key definition
Returns
string protected

Definition at line 74 of file Pgsql.php.

{
$query = '';
if (isset($definition['match'])) {
$query .= ' MATCH ' . $definition['match'];
}
if (isset($definition['onUpdate'])) {
$query .= ' ON UPDATE ' . $definition['onUpdate'];
}
if (isset($definition['onDelete'])) {
$query .= ' ON DELETE ' . $definition['onDelete'];
}
if (isset($definition['deferrable'])) {
$query .= ' DEFERRABLE';
} else {
$query .= ' NOT DEFERRABLE';
}
if (isset($definition['deferred'])) {
$query .= ' INITIALLY DEFERRED';
} else {
$query .= ' INITIALLY IMMEDIATE';
}
return $query;
}
Doctrine_Export::getAllGenerators ( Doctrine_Table  $table)
inherited

fetches all generators recursively for given table

Parameters
Doctrine_Table$tabletable object to retrieve the generators from
Returns
array an array of Doctrine_Record_Generator objects

Definition at line 1293 of file Export.php.

{
$generators = array();
foreach ($table->getGenerators() as $name => $generator) {
if ($generator === null) {
continue;
}
$generators[] = $generator;
$generatorTable = $generator->getTable();
if ($generatorTable instanceof Doctrine_Table) {
$generators = array_merge($generators, $this->getAllGenerators($generatorTable));
}
}
return $generators;
}
Doctrine_Export::getCharsetFieldDeclaration (   $charset)
inherited

Obtain DBMS specific SQL code portion needed to set the CHARACTER SET of a field declaration to be used in statements like CREATE TABLE.

Parameters
string$charsetname of the charset
Returns
string DBMS specific SQL code portion needed to set the CHARACTER SET of a field declaration.

Definition at line 1059 of file Export.php.

{
return '';
}
Doctrine_Export::getCheckDeclaration ( array  $definition)
inherited

Obtain DBMS specific SQL code portion needed to set a CHECK constraint declaration to be used in statements like CREATE TABLE.

Parameters
array$definitioncheck definition
Returns
string DBMS specific SQL code portion needed to set a CHECK constraint

Definition at line 809 of file Export.php.

{
$constraints = array();
foreach ($definition as $field => $def) {
if (is_string($def)) {
$constraints[] = 'CHECK (' . $def . ')';
} else {
if (isset($def['min'])) {
$constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')';
}
if (isset($def['max'])) {
$constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')';
}
}
}
return implode(', ', $constraints);
}
Doctrine_Export::getCollationFieldDeclaration (   $collation)
inherited

Obtain DBMS specific SQL code portion needed to set the COLLATION of a field declaration to be used in statements like CREATE TABLE.

Parameters
string$collationname of the collation
Returns
string DBMS specific SQL code portion needed to set the COLLATION of a field declaration.

Definition at line 1072 of file Export.php.

{
return '';
}
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_Export::getDeclaration (   $name,
array  $field 
)
inherited

Obtain DBMS specific SQL code portion needed to declare a generic type field to be used in statements like CREATE TABLE.

Parameters
string$namename the field to be declared.
array$fieldassociative array with the name of the properties of the field being declared as array indexes. Currently, the types of supported field properties are as follows:

length Integer value that determines the maximum length of the text field. If this argument is missing the field should be declared to have the longest length allowed by the DBMS.

default Text value to be used as default for this field.

notnull Boolean flag that indicates whether this field is constrained to not be set to null.

charset Text value with the default CHARACTER SET for this field.

collation Text value with the default COLLATION for this field.

unique unique constraint

check column check constraint

Returns
string DBMS specific SQL code portion that should be used to declare the specified field.

Definition at line 717 of file Export.php.

{
$default = $this->getDefaultFieldDeclaration($field);
$charset = (isset($field['charset']) && $field['charset']) ?
' ' . $this->getCharsetFieldDeclaration($field['charset']) : '';
$collation = (isset($field['collation']) && $field['collation']) ?
' ' . $this->getCollationFieldDeclaration($field['collation']) : '';
$notnull = $this->getNotNullFieldDeclaration($field);
$unique = (isset($field['unique']) && $field['unique']) ?
' ' . $this->getUniqueFieldDeclaration() : '';
$check = (isset($field['check']) && $field['check']) ?
' ' . $field['check'] : '';
$method = 'get' . $field['type'] . 'Declaration';
try {
if (method_exists($this->conn->dataDict, $method)) {
return $this->conn->dataDict->$method($name, $field);
} else {
$dec = $this->conn->dataDict->getNativeDeclaration($field);
}
return $this->conn->quoteIdentifier($name, true)
. ' ' . $dec . $charset . $default . $notnull . $unique . $check . $collation;
} catch (Exception $e) {
throw new Doctrine_Exception('Around field ' . $name . ': ' . $e->getMessage());
}
}
Doctrine_Export::getDefaultFieldDeclaration (   $field)
inherited

getDefaultDeclaration Obtain DBMS specific SQL code portion needed to set a default value declaration to be used in statements like CREATE TABLE.

Parameters
array$fieldfield definition array
Returns
string DBMS specific SQL code portion needed to set a default value

Definition at line 761 of file Export.php.

{
$default = '';
if (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']];
if ($field['default'] === '' &&
($this->conn->getAttribute(Doctrine_Core::ATTR_PORTABILITY) & Doctrine_Core::PORTABILITY_EMPTY_TO_NULL)) {
$field['default'] = null;
}
}
if ($field['type'] === 'boolean') {
$field['default'] = $this->conn->convertBooleans($field['default']);
}
$default = ' DEFAULT ' . (is_null($field['default'])
? 'NULL'
: $this->conn->quote($field['default'], $field['type']));
}
return $default;
}
Doctrine_Export::getFieldDeclarationList ( array  $fields)
inherited

Get declaration of a number of field in bulk

Parameters
array$fieldsa multidimensional associative array. The first dimension determines the field name, while the second dimension is keyed with the name of the properties of the field being declared as array indexes. Currently, the types of supported field properties are as follows:

length Integer value that determines the maximum length of the text field. If this argument is missing the field should be declared to have the longest length allowed by the DBMS.

default Text value to be used as default for this field.

notnull Boolean flag that indicates whether this field is constrained to not be set to null. charset Text value with the default CHARACTER SET for this field. collation Text value with the default COLLATION for this field. unique unique constraint

Returns
string

Definition at line 671 of file Export.php.

{
foreach ($fields as $fieldName => $field) {
$query = $this->getDeclaration($fieldName, $field);
$queryFields[] = $query;
}
return implode(', ', $queryFields);
}
Doctrine_Export::getForeignKeyBaseDeclaration ( array  $definition)
inherited

getForeignKeyBaseDeclaration Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration to be used in statements like CREATE TABLE.

Parameters
array$definition
Returns
string

Definition at line 1006 of file Export.php.

{
$sql = '';
if (isset($definition['name'])) {
$sql .= 'CONSTRAINT ' . $this->conn->quoteIdentifier($this->conn->formatter->getForeignKeyName($definition['name'])) . ' ';
}
$sql .= 'FOREIGN KEY (';
if ( ! isset($definition['local'])) {
throw new Doctrine_Export_Exception('Local reference field missing from definition.');
}
if ( ! isset($definition['foreign'])) {
throw new Doctrine_Export_Exception('Foreign reference field missing from definition.');
}
if ( ! isset($definition['foreignTable'])) {
throw new Doctrine_Export_Exception('Foreign reference table missing from definition.');
}
if ( ! is_array($definition['local'])) {
$definition['local'] = array($definition['local']);
}
if ( ! is_array($definition['foreign'])) {
$definition['foreign'] = array($definition['foreign']);
}
$sql .= implode(', ', array_map(array($this->conn, 'quoteIdentifier'), $definition['local']))
. ') REFERENCES '
. $this->conn->quoteIdentifier($definition['foreignTable']) . '('
. implode(', ', array_map(array($this->conn, 'quoteIdentifier'), $definition['foreign'])) . ')';
return $sql;
}
Doctrine_Export::getForeignKeyDeclaration ( array  $definition)
inherited

getForeignKeyDeclaration Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration to be used in statements like CREATE TABLE.

Parameters
array$definitionan associative array with the following structure: name optional constraint name

local the local field(s)

foreign the foreign reference field(s)

foreignTable the name of the foreign table

onDelete referential delete action

onUpdate referential update action

deferred deferred constraint checking

The onDelete and onUpdate keys accept the following values:

CASCADE: Delete or update the row from the parent table and automatically delete or update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column in the parent table or in the child table.

SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.

NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary key value is not allowed to proceed if there is a related foreign key value in the referenced table.

RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as omitting the ON DELETE or ON UPDATE clause.

SET DEFAULT

Returns
string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint of a field declaration.

Definition at line 944 of file Export.php.

{
$sql = $this->getForeignKeyBaseDeclaration($definition);
$sql .= $this->getAdvancedForeignKeyOptions($definition);
return $sql;
}
Doctrine_Export::getForeignKeyReferentialAction (   $action)
inherited

getForeignKeyReferentialAction

returns given referential action in uppercase if valid, otherwise throws an exception

Exceptions
Doctrine_Exception_Exceptionif unknown referential action given
Parameters
string$actionforeign key referential action
stringforeign key referential action in uppercase

Definition at line 982 of file Export.php.

{
$upper = strtoupper($action);
switch ($upper) {
case 'CASCADE':
case 'SET NULL':
case 'NO ACTION':
case 'RESTRICT':
case 'SET DEFAULT':
return $upper;
break;
default:
throw new Doctrine_Export_Exception('Unknown foreign key referential action \'' . $upper . '\' given.');
}
}
Doctrine_Export::getIndexDeclaration (   $name,
array  $definition 
)
inherited

Obtain DBMS specific SQL code portion needed to set an index declaration to be used in statements like CREATE TABLE.

Parameters
string$namename of the index
array$definitionindex definition
Returns
string DBMS specific SQL code portion needed to set an index

Definition at line 837 of file Export.php.

{
$name = $this->conn->quoteIdentifier($name);
$type = '';
if (isset($definition['type'])) {
if (strtolower($definition['type']) == 'unique') {
$type = strtoupper($definition['type']) . ' ';
} else {
'Unknown type ' . $definition['type'] . ' for index ' . $name
);
}
}
if ( ! isset($definition['fields']) || ! is_array($definition['fields'])) {
throw new Doctrine_Export_Exception('No columns given for index ' . $name);
}
$query = $type . 'INDEX ' . $name;
$query .= ' (' . $this->getIndexFieldDeclarationList($definition['fields']) . ')';
return $query;
}
Doctrine_Export::getIndexFieldDeclarationList ( array  $fields)
inherited

getIndexFieldDeclarationList Obtain DBMS specific SQL code portion needed to set an index declaration to be used in statements like CREATE TABLE.

Returns
string

Definition at line 870 of file Export.php.

{
$ret = array();
foreach ($fields as $field => $definition) {
if (is_array($definition)) {
$ret[] = $this->conn->quoteIdentifier($field);
} else {
$ret[] = $this->conn->quoteIdentifier($definition);
}
}
return implode(', ', $ret);
}
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_Export::getNotNullFieldDeclaration ( array  $definition)
inherited

getNotNullFieldDeclaration Obtain DBMS specific SQL code portion needed to set a NOT NULL declaration to be used in statements like CREATE TABLE.

Parameters
array$fieldfield definition array
Returns
string DBMS specific SQL code portion needed to set a default value

Definition at line 796 of file Export.php.

{
return (isset($definition['notnull']) && $definition['notnull']) ? ' NOT NULL' : '';
}
Doctrine_Export::getTemporaryTableQuery ( )
inherited

A method to return the required SQL string that fits between CREATE ... TABLE to create the table as a temporary table.

Should be overridden in driver classes to return the correct string for the specific database type.

The default is to return the string "TEMPORARY" - this will result in a SQL error for any database that does not support temporary tables, or that requires a different SQL command from "CREATE TEMPORARY TABLE".

Returns
string The string required to be placed between "CREATE" and "TABLE" to generate a temporary table, if possible.

Definition at line 897 of file Export.php.

{
return 'TEMPORARY';
}
Doctrine_Export::getUniqueFieldDeclaration ( )
inherited

Obtain DBMS specific SQL code portion needed to set the UNIQUE constraint of a field declaration to be used in statements like CREATE TABLE.

Returns
string DBMS specific SQL code portion needed to set the UNIQUE constraint of a field declaration.

Definition at line 1046 of file Export.php.

{
return 'UNIQUE';
}

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