class Doctrine_Export_Mssql extends Doctrine_Export (View source)

Doctrine_Export_Mssql

Properties

protected Doctrine_Connection $conn from Doctrine_Connection_Module
protected string $moduleName from Doctrine_Connection_Module
protected $valid_default_values from Doctrine_Export

Methods

__construct(Doctrine_Connection $conn = null)

No description

getConnection()

getConnection returns the connection object this module uses

string
getModuleName()

getModuleName returns the name of this module

void
dropDatabase(string $name)

drop an existing database

void
dropDatabaseSql($database)

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

string
dropTableSql(string $table)

dropTableSql drop an existing table

void
dropTable(string $table)

dropTable drop an existing table

void
dropIndex(string $table, string $name)

drop existing index

string
dropIndexSql(string $table, string $name)

dropIndexSql

void
dropConstraint(string $table, string $name, string $primary = false)

drop existing constraint

void
dropForeignKey(string $table, string $name)

drop existing foreign key

void
dropSequence(string $sequenceName)

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

void
dropSequenceSql(string $seqName)

This function drops an existing sequence

void
createDatabase(string $name)

create a new database

string
createDatabaseSql($database)

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

string
createTableSql(string $name, array $fields, array $options = array())

create a new table

void
createTable(string $name, array $fields, array $options = array())

create a new table

void
createSequence(string $seqName, string $start = 1, array $options = array())

create sequence

string
createSequenceSql(string $seqName, string $start = 1, array $options = array())

return RDBMS specific create sequence statement (this method is implemented by the drivers)

void
createConstraint(string $table, string $name, array $definition)

create a constraint on a table

void
createConstraintSql(string $table, string $name, array $definition)

create a constraint on a table

void
createIndex(string $table, string $name, array $definition)

Get the stucture of a field into an array

string
createIndexSql(string $table, string $name, array $definition)

Get the stucture of a field into an array

string
createForeignKeySql(string $table, array $definition)

createForeignKeySql

string
createForeignKey(string $table, array $definition)

createForeignKey

void
alterTable(string $name, array $changes, boolean $check = false)

alter an existing table

string
alterTableSql(string $name, array $changes, boolean $check = false)

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

string
getFieldDeclarationList(array $fields)

Get declaration of a number of field in bulk

string
getDeclaration(string $name, array $field)

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

string
getDefaultFieldDeclaration(array $field)

No description

string
getNotNullFieldDeclaration(array $definition)

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

string
getCheckDeclaration(array $definition)

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

string
getIndexDeclaration(string $name, array $definition)

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

string
getIndexFieldDeclarationList(array $fields)

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

string
getTemporaryTableQuery()

Override the parent method.

string
getForeignKeyDeclaration(array $definition)

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.

string
getAdvancedForeignKeyOptions(array $definition)

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

getForeignKeyReferentialAction($action)

getForeignKeyReferentialAction

string
getForeignKeyBaseDeclaration(array $definition)

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.

string
getUniqueFieldDeclaration()

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

string
getCharsetFieldDeclaration(string $charset)

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

string
getCollationFieldDeclaration(string $collation)

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

void
exportSchema(string $directory = null)

exportSchema method for exporting Doctrine_Record classes to a schema

exportSortedClassesSql($classes, $groupByConnection = true)

No description

void
exportClasses(array $classes)

exportClasses method for exporting Doctrine_Record classes to a schema

void
exportClassesSql(array $classes)

exportClassesSql method for exporting Doctrine_Record classes to a schema

array
getAllGenerators(Doctrine_Table $table)

fetches all generators recursively for given table

array
exportGeneratorsSql(Doctrine_Table $table)

exportGeneratorsSql exports plugin tables for given table

void
exportSql(string $directory = null)

exportSql returns the sql for exporting Doctrine_Record classes to a schema

boolean
exportTable(Doctrine_Table $table)

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

Details

__construct(Doctrine_Connection $conn = null)

Parameters

Doctrine_Connection $conn Doctrine_Connection object, every connection module holds an instance of Doctrine_Connection

Doctrine_Connection getConnection()

getConnection returns the connection object this module uses

Return Value

Doctrine_Connection

string getModuleName()

getModuleName returns the name of this module

Return Value

string the name of this module

void dropDatabase(string $name)

drop an existing database

Parameters

string $name name of the database that should be dropped

Return Value

void

void dropDatabaseSql($database)

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

Parameters

$database

Return Value

void

string dropTableSql(string $table)

dropTableSql drop an existing table

Parameters

string $table name of table that should be dropped from the database

Return Value

string

void dropTable(string $table)

dropTable drop an existing table

Parameters

string $table name of table that should be dropped from the database

Return Value

void

void dropIndex(string $table, string $name)

drop existing index

Parameters

string $table name of table that should be used in method
string $name name of the index to be dropped

Return Value

void

string dropIndexSql(string $table, string $name)

dropIndexSql

Parameters

string $table name of table that should be used in method
string $name name of the index to be dropped

Return Value

string SQL that is used for dropping an index

void dropConstraint(string $table, string $name, string $primary = false)

drop existing constraint

Parameters

string $table name of table that should be used in method
string $name name of the constraint to be dropped
string $primary hint if the constraint is primary

Return Value

void

void dropForeignKey(string $table, string $name)

drop existing foreign key

Parameters

string $table name of table that should be used in method
string $name name of the foreign key to be dropped

Return Value

void

void dropSequence(string $sequenceName)

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

Parameters

string $sequenceName name of the sequence to be dropped

Return Value

void

Exceptions

Doctrine_Connection_Exception if something fails at database level

void dropSequenceSql(string $seqName)

This function drops an existing sequence

Parameters

string $seqName name of the sequence to be dropped

Return Value

void

void createDatabase(string $name)

create a new database

Parameters

string $name name of the database that should be created

Return Value

void

string createDatabaseSql($database)

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

Parameters

$database

Return Value

string

string createTableSql(string $name, array $fields, array $options = array())

create a new table

Parameters

string $name Name of the database that should be created
array $fields Associative 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. array( 'id' => array( 'type' => 'integer', 'unsigned' => 1 'notnull' => 1 'default' => 0 ), 'name' => array( 'type' => 'text', 'length' => 12 ), 'password' => array( 'type' => 'text', 'length' => 12 ) );
array $options An associative array of table options:

Return Value

string

void createTable(string $name, array $fields, array $options = array())

create a new table

Parameters

string $name Name of the database that should be created
array $fields Associative array that contains the definition of each field of the new table
array $options An associative array of table options:

Return Value

void

See also

Doctrine_Export::createTableSql

void createSequence(string $seqName, string $start = 1, array $options = array())

create sequence

Parameters

string $seqName name of the sequence to be created
string $start start value of the sequence; default is 1
array $options An associative array of table options: array( 'comment' => 'Foo', 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci', );

Return Value

void

string createSequenceSql(string $seqName, string $start = 1, array $options = array())

return RDBMS specific create sequence statement (this method is implemented by the drivers)

Parameters

string $seqName name of the sequence to be created
string $start start value of the sequence; default is 1
array $options An associative array of table options: array( 'comment' => 'Foo', 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci', );

Return Value

string

Exceptions

Doctrine_Connection_Exception if something fails at database level

void createConstraint(string $table, string $name, array $definition)

create a constraint on a table

Parameters

string $table name of the table on which the constraint is to be created
string $name name of the constraint to be created
array $definition associative 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()
                                   )
                               )

Return Value

void

void createConstraintSql(string $table, string $name, array $definition)

create a constraint on a table

Parameters

string $table name of the table on which the constraint is to be created
string $name name of the constraint to be created
array $definition associative 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()
                                   )
                               )

Return Value

void

void createIndex(string $table, string $name, array $definition)

Get the stucture of a field into an array

Parameters

string $table name of the table on which the index is to be created
string $name name of the index to be created
array $definition associative 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()
                                   )
                               )

Return Value

void

string createIndexSql(string $table, string $name, array $definition)

Get the stucture of a field into an array

Parameters

string $table name of the table on which the index is to be created
string $name name of the index to be created
array $definition associative array that defines properties of the index to be created.

Return Value

string

See also

Doctrine_Export::createIndex

string createForeignKeySql(string $table, array $definition)

createForeignKeySql

Parameters

string $table name of the table on which the foreign key is to be created
array $definition associative array that defines properties of the foreign key to be created.

Return Value

string

string createForeignKey(string $table, array $definition)

createForeignKey

Parameters

string $table name of the table on which the foreign key is to be created
array $definition associative array that defines properties of the foreign key to be created.

Return Value

string

void alterTable(string $name, array $changes, boolean $check = false)

alter an existing table

Parameters

string $name name of the table that is intended to be changed.
array $changes associative 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',
                                       ),
                                   )
                               )
                           )
boolean $check indicates 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.

Return Value

void

string alterTableSql(string $name, array $changes, boolean $check = false)

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

Parameters

string $name name of the table that is intended to be changed.
array $changes associative array that contains the details of each type *
boolean $check indicates 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.

Return Value

string

See also

Doctrine_Export::alterTable

string getFieldDeclarationList(array $fields)

Get declaration of a number of field in bulk

Parameters

array $fields a 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

Return Value

string

string getDeclaration(string $name, array $field)

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

Parameters

string $name name the field to be declared.
array $field associative 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

Return Value

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

string getDefaultFieldDeclaration(array $field)

Parameters

array $field field definition array

Return Value

string DBMS specific SQL code portion needed to set a default value

See also

Doctrine_Export::getDefaultFieldDeclaration

string getNotNullFieldDeclaration(array $definition)

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

Parameters

array $definition

Return Value

string DBMS specific SQL code portion needed to set a default value

string getCheckDeclaration(array $definition)

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

Parameters

array $definition check definition

Return Value

string DBMS specific SQL code portion needed to set a CHECK constraint

string getIndexDeclaration(string $name, array $definition)

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

Parameters

string $name name of the index
array $definition index definition

Return Value

string DBMS specific SQL code portion needed to set an index

string getIndexFieldDeclarationList(array $fields)

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

Parameters

array $fields

Return Value

string

string getTemporaryTableQuery()

Override the parent method.

Return Value

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

string getForeignKeyDeclaration(array $definition)

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 $definition an 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

Return Value

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

string getAdvancedForeignKeyOptions(array $definition)

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

..

Parameters

array $definition foreign key definition

Return Value

string

getForeignKeyReferentialAction($action)

getForeignKeyReferentialAction

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

Parameters

$action

Exceptions

Doctrine_Exception_Exception if unknown referential action given

string getForeignKeyBaseDeclaration(array $definition)

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

Return Value

string

string getUniqueFieldDeclaration()

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

Return Value

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

string getCharsetFieldDeclaration(string $charset)

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 $charset name of the charset

Return Value

string DBMS specific SQL code portion needed to set the CHARACTER SET of a field declaration.

string getCollationFieldDeclaration(string $collation)

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 $collation name of the collation

Return Value

string DBMS specific SQL code portion needed to set the COLLATION of a field declaration.

void exportSchema(string $directory = null)

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

Parameters

string $directory optional directory parameter

Return Value

void

Exceptions

Doctrine_Connection_Exception if some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation

exportSortedClassesSql($classes, $groupByConnection = true)

Parameters

$classes
$groupByConnection

void exportClasses(array $classes)

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.

Parameters

array $classes

Return Value

void

Exceptions

Doctrine_Connection_Exception if some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation

void exportClassesSql(array $classes)

exportClassesSql method for exporting Doctrine_Record classes to a schema

Parameters

array $classes

Return Value

void

Exceptions

Doctrine_Connection_Exception if some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation

array getAllGenerators(Doctrine_Table $table)

fetches all generators recursively for given table

Parameters

Doctrine_Table $table table object to retrieve the generators from

Return Value

array an array of Doctrine_Record_Generator objects

array exportGeneratorsSql(Doctrine_Table $table)

exportGeneratorsSql exports plugin tables for given table

Parameters

Doctrine_Table $table the table in which the generators belong to

Return Value

array an array of sql strings

void exportSql(string $directory = null)

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

Parameters

string $directory optional directory parameter

Return Value

void

Exceptions

Doctrine_Connection_Exception if some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation

boolean exportTable(Doctrine_Table $table)

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

Parameters

Doctrine_Table $table

Return Value

boolean whether or not the export operation was successful false if table already existed in the database

Exceptions

Doctrine_Connection_Exception if some error other than Doctrine_Core::ERR_ALREADY_EXISTS occurred during the create table operation