Doctrine 1.2.4
Doctrine_Export_Oracle Class Reference

Inherits Doctrine_Export.

Public Member Functions

 _createColumnCommentSql ($table, $column, $comment)
 
 _createTableCommentSql ($table, $comment)
 
 _makeAutoincrement ($name, $table, $start=1)
 
 alterTable ($name, array $changes, $check=false)
 
 alterTableSql ($name, array $changes, $check=false)
 
 createConstraint ($table, $name, $definition)
 
 createConstraintSql ($table, $name, $definition)
 
 createDatabase ($name)
 
 createDatabaseSql ($database)
 
 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 ($seqName, $start=1, array $options=array())
 
 createTable ($name, array $fields, array $options=array())
 
 createTableSql ($name, array $fields, array $options=array())
 
 dropAutoincrement ($table)
 
 dropConstraint ($table, $name, $primary=false)
 
 dropDatabase ($name)
 
 dropDatabaseSql ($database)
 
 dropForeignKey ($table, $name)
 
 dropIndex ($table, $name)
 
 dropIndexSql ($table, $name)
 
 dropSequence ($sequenceName)
 
 dropSequenceSql ($seqName)
 
 dropTable ($name)
 
 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 Oracle.php.

Member Function Documentation

Doctrine_Export_Oracle::_createColumnCommentSql (   $table,
  $column,
  $comment 
)

create a comment on a column

Parameters
string$tableName of the table
string$columnName of the column we are commenting
string$commentThe comment for the table
Returns
string

Definition at line 368 of file Oracle.php.

{
return 'COMMENT ON COLUMN '. $this->conn->quoteIdentifier($table, true). '.'. $this->conn->quoteIdentifier($column, true). ' IS '.$this->conn->quote($comment, 'text').'';
}
Doctrine_Export_Oracle::_createTableCommentSql (   $table,
  $comment 
)

create a comment on a table

Parameters
string$tableName of the table we are commenting
string$commentThe comment for the table
Returns
string

Definition at line 354 of file Oracle.php.

{
return 'COMMENT ON TABLE '. $this->conn->quoteIdentifier($table, true). ' IS '.$this->conn->quote($comment, 'text').'';
}
Doctrine_Export_Oracle::_makeAutoincrement (   $name,
  $table,
  $start = 1 
)

add an autoincrement sequence + trigger

Parameters
string$namename of the PK field
string$tablename of the table
string$startstart value for the sequence
Returns
string Sql code private

Definition at line 108 of file Oracle.php.

{
$sql = array();
if ( ! $this->conn->getAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER)) {
$table = strtoupper($table);
}
$indexName = $table . '_AI_PK';
$definition = array(
'primary' => true,
'fields' => array($name => true),
);
$sql[] = 'DECLARE
constraints_Count NUMBER;
BEGIN
SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = \''.$table.'\' AND CONSTRAINT_TYPE = \'P\';
IF constraints_Count = 0 THEN
EXECUTE IMMEDIATE \''.$this->createConstraintSql($table, $indexName, $definition).'\';
END IF;
END;';
if (is_null($start)) {
$query = 'SELECT MAX(' . $this->conn->quoteIdentifier($name, true) . ') FROM ' . $this->conn->quoteIdentifier($table, true);
$start = $this->conn->fetchOne($query);
++$start;
}
$sql[] = $this->createSequenceSql($table, $start);
$sequenceName = $this->conn->formatter->getSequenceName($table);
$triggerName = $this->conn->quoteIdentifier($table . '_AI_PK', true);
$table = $this->conn->quoteIdentifier($table, true);
$name = $this->conn->quoteIdentifier($name, true);
$sql[] = 'CREATE TRIGGER ' . $triggerName . '
BEFORE INSERT
ON ' . $table . '
FOR EACH ROW
DECLARE
last_Sequence NUMBER;
last_InsertID NUMBER;
BEGIN
IF (:NEW.' . $name . ' IS NULL OR :NEW.'.$name.' = 0) THEN
SELECT ' . $this->conn->quoteIdentifier($sequenceName) . '.NEXTVAL INTO :NEW.' . $name . ' FROM DUAL;
ELSE
SELECT NVL(Last_Number, 0) INTO last_Sequence
FROM User_Sequences
WHERE UPPER(Sequence_Name) = UPPER(\'' . $sequenceName . '\');
SELECT :NEW.' . $name . ' INTO last_InsertID FROM DUAL;
WHILE (last_InsertID > last_Sequence) LOOP
SELECT ' . $this->conn->quoteIdentifier($sequenceName) . '.NEXTVAL INTO last_Sequence FROM DUAL;
END LOOP;
END IF;
END;';
return $sql;
}
Doctrine_Export_Oracle::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 MDB2 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 MDB2 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.
Returns
void

Definition at line 476 of file Oracle.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 false;
}
$name = $this->conn->quoteIdentifier($name, true);
if ( ! empty($changes['add']) && is_array($changes['add'])) {
$fields = array();
foreach ($changes['add'] as $fieldName => $field) {
$fields[] = $this->getDeclaration($fieldName, $field);
}
$result = $this->conn->exec('ALTER TABLE ' . $name . ' ADD (' . implode(', ', $fields) . ')');
}
if ( ! empty($changes['change']) && is_array($changes['change'])) {
$fields = array();
foreach ($changes['change'] as $fieldName => $field) {
$fields[] = $fieldName. ' ' . $this->getDeclaration('', $field['definition']);
}
$result = $this->conn->exec('ALTER TABLE ' . $name . ' MODIFY (' . implode(', ', $fields) . ')');
}
if ( ! empty($changes['rename']) && is_array($changes['rename'])) {
foreach ($changes['rename'] as $fieldName => $field) {
$query = 'ALTER TABLE ' . $name . ' RENAME COLUMN ' . $this->conn->quoteIdentifier($fieldName, true)
. ' TO ' . $this->conn->quoteIdentifier($field['name']);
$result = $this->conn->exec($query);
}
}
if ( ! empty($changes['remove']) && is_array($changes['remove'])) {
$fields = array();
foreach ($changes['remove'] as $fieldName => $field) {
$fields[] = $this->conn->quoteIdentifier($fieldName, true);
}
$result = $this->conn->exec('ALTER TABLE ' . $name . ' DROP COLUMN ' . implode(', ', $fields));
}
if ( ! empty($changes['name'])) {
$changeName = $this->conn->quoteIdentifier($changes['name'], true);
$result = $this->conn->exec('ALTER TABLE ' . $name . ' RENAME TO ' . $changeName);
}
}
Doctrine_Export::alterTableSql (   $name,
array  $changes,
  $check = false 
)
inherited

generates the sql for altering an existing table (this method is implemented by the drivers)

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
string

Definition at line 637 of file Export.php.

{
throw new Doctrine_Export_Exception('Alter table not supported by this driver.');
}
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_Oracle::createDatabase (   $name)

create a new database

Parameters
object$dbdatabase object that is extended by this class
string$namename of the database that should be created
Returns
boolean success of operation

Definition at line 43 of file Oracle.php.

{
if ($this->conn->getAttribute(Doctrine_Core::ATTR_EMULATE_DATABASE)) {
$username = $name;
$password = $this->conn->dsn['password'] ? $this->conn->dsn['password'] : $name;
$tablespace = $this->conn->options['default_tablespace']
? ' DEFAULT TABLESPACE '.$this->conn->options['default_tablespace'] : '';
$query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password . $tablespace;
$result = $this->conn->exec($query);
try {
$query = 'GRANT CREATE SESSION, CREATE TABLE, UNLIMITED TABLESPACE, CREATE SEQUENCE, CREATE TRIGGER TO ' . $username;
$result = $this->conn->exec($query);
} catch (Exception $e) {
$this->dropDatabase($username);
}
}
return true;
}
Doctrine_Export::createDatabaseSql (   $database)
inherited

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

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

Definition at line 200 of file Export.php.

{
throw new Doctrine_Export_Exception('Create database not supported by this driver.');
}
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::createIndexSql (   $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.
See Also
Doctrine_Export::createIndex()
Returns
string

Definition at line 470 of file Export.php.

{
$table = $this->conn->quoteIdentifier($table);
$name = $this->conn->quoteIdentifier($name);
$type = '';
if (isset($definition['type'])) {
switch (strtolower($definition['type'])) {
case 'unique':
$type = strtoupper($definition['type']) . ' ';
break;
default:
'Unknown type ' . $definition['type'] . ' for index ' . $name . ' in table ' . $table
);
}
}
$query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table;
$fields = array();
foreach ($definition['fields'] as $field) {
$fields[] = $this->conn->quoteIdentifier($field);
}
$query .= ' (' . implode(', ', $fields) . ')';
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_Oracle::createSequenceSql (   $seqName,
  $start = 1,
array  $options = array() 
)

create sequence

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 550 of file Oracle.php.

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

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 The indexes of the array entries are the names of the fields of the table an the array entry values are associative arrays like those that are meant to be passed with the field definitions to get[Type]Declaration() functions.

Example array(

'id' => array(
    'type' => 'integer',
    'unsigned' => 1
    'notnull' => 1
    'default' => 0
),
'name' => array(
    'type' => 'text',
    'length' => 12
),
'password' => array(
    'type' => 'text',
    'length' => 12
)

);

Parameters
array$optionsAn associative array of table options:
Returns
void

Definition at line 268 of file Oracle.php.

{
$this->conn->beginTransaction();
foreach ($this->createTableSql($name, $fields, $options) as $sql) {
$this->conn->exec($sql);
}
$this->conn->commit();
}
Doctrine_Export_Oracle::createTableSql (   $name,
array  $fields,
array  $options = array() 
)

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 The indexes of the array entries are the names of the fields of the table an the array entry values are associative arrays like those that are meant to be passed with the field definitions to get[Type]Declaration() functions.

Example array(

'id' => array(
    'type' => 'integer',
    'unsigned' => 1
    'notnull' => 1
    'default' => 0
),
'name' => array(
    'type' => 'text',
    'length' => 12
),
'password' => array(
    'type' => 'text',
    'length' => 12
)

);

Parameters
array$optionsAn associative array of table options:
Returns
void

Definition at line 310 of file Oracle.php.

{
$sql = parent::createTableSql($name, $fields, $options);
if (isset($options['comment']) && ! empty($options['comment'])) {
$sql[] = $this->_createTableCommentSql($name, $options['comment']);
}
foreach ($fields as $fieldName => $field) {
if (isset($field['sequence'])) {
$sql[] = $this->createSequenceSql($field['sequence'], 1);
}
if (isset($field['autoincrement']) && $field['autoincrement'] ||
(isset($field['autoinc']) && $fields['autoinc'])) {
$sql = array_merge($sql, $this->_makeAutoincrement($fieldName, $name));
}
if (isset($field['comment']) && ! empty($field['comment'])){
$sql[] = $this->_createColumnCommentSql($name,$fieldName,$field['comment']);
}
}
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach ($options['indexes'] as $indexName => $definition) {
// create nonunique indexes, as they are a part od CREATE TABLE DDL
if ( ! isset($definition['type']) ||
(isset($definition['type']) && strtolower($definition['type']) != 'unique')) {
$sql[] = $this->createIndexSql($name, $indexName, $definition);
}
}
}
return $sql;
}
Doctrine_Export_Oracle::dropAutoincrement (   $table)

drop an existing autoincrement sequence + trigger

Parameters
string$tablename of the table
Returns
void

Definition at line 172 of file Oracle.php.

{
$table = strtoupper($table);
$triggerName = $table . '_AI_PK';
$trigger_name_quoted = $this->conn->quote($triggerName);
$query = 'SELECT trigger_name FROM user_triggers';
$query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted);
$trigger = $this->conn->fetchOne($query);
if ($trigger) {
$trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true);
$trigger_sql = 'DROP TRIGGER ' . $trigger_name;
// if throws exception, trigger for autoincrement PK could not be dropped
$this->conn->exec($trigger_sql);
// if throws exception, sequence for autoincrement PK could not be dropped
$this->dropSequence($table);
$indexName = $table . '_AI_PK';
// if throws exception, primary key for autoincrement PK could not be dropped
$this->dropConstraint($table, $indexName);
}
}
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_Oracle::dropDatabase (   $name)

drop an existing database

Parameters
object$this-,>conndatabase object that is extended by this class
string$namename of the database that should be dropped
Returns
boolean success of operation public

Definition at line 73 of file Oracle.php.

{
$sql = <<<SQL
BEGIN
-- user_tables contains also materialized views
FOR I IN (SELECT table_name FROM user_tables WHERE table_name NOT IN (SELECT mview_name FROM user_mviews))
LOOP
EXECUTE IMMEDIATE 'DROP TABLE "'||I.table_name||'" CASCADE CONSTRAINTS';
END LOOP;
FOR I IN (SELECT SEQUENCE_NAME FROM USER_SEQUENCES)
LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE "'||I.SEQUENCE_NAME||'"';
END LOOP;
END;
SQL;
$this->conn->exec($sql);
if ($this->conn->getAttribute(Doctrine_Core::ATTR_EMULATE_DATABASE)) {
$username = $name;
$this->conn->exec('DROP USER ' . $username . ' CASCADE');
}
}
Doctrine_Export::dropDatabaseSql (   $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 71 of file Export.php.

{
throw new Doctrine_Export_Exception('Drop database not supported by this driver.');
}
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_Oracle::dropSequenceSql (   $seqName)

drop existing sequence

Parameters
object$this-,>conndatabase object that is extended by this class
string$seqNamename of the sequence to be dropped
Returns
string

Definition at line 565 of file Oracle.php.

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

drop an existing table

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

Definition at line 379 of file Oracle.php.

{
//$this->conn->beginNestedTransaction();
$result = $this->dropAutoincrement($name);
$result = parent::dropTable($name);
//$this->conn->completeNestedTransaction();
return $result;
}
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_Oracle::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 218 of file Oracle.php.

{
$query = '';
if (isset($definition['onDelete']) && strtoupper(trim($definition['onDelete'])) != 'NO ACTION') {
$query .= ' ON DELETE ' . $definition['onDelete'];
}
if (isset($definition['deferrable'])) {
$query .= ' DEFERRABLE';
} else {
$query .= ' NOT DEFERRABLE';
}
if (isset($definition['feferred'])) {
$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_Oracle::getIndexDeclaration (   $name,
array  $definition 
)

return Oracle's SQL code portion needed to set an index declaration to be unsed in statements like CREATE TABLE.

Parameters
string$namename of the index
array$definitionindex definition
Returns
string Oracle's SQL code portion needed to set an index

Definition at line 579 of file Oracle.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
);
}
} else {
// only unique indexes should be defined in create table statement
return null;
}
if ( !isset($definition['fields']) || !is_array($definition['fields'])) {
throw new Doctrine_Export_Exception('No columns given for index '.$name);
}
$query = 'CONSTRAINT '.$name.' '.$type.' ('.$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_Oracle::getTemporaryTableQuery ( )

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

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

Definition at line 204 of file Oracle.php.

{
return 'GLOBAL 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: