class SQLServerSchemaManager extends AbstractSchemaManager (View source)

SQL Server Schema Manager.

Properties

protected Connection $_conn Holds instance of the Doctrine connection for this schema manager. from AbstractSchemaManager
protected AbstractPlatform $_platform Holds instance of the database platform used for this schema manager. from AbstractSchemaManager

Methods

__construct(Connection $conn, AbstractPlatform|null $platform = null)

Constructor. Accepts the Connection instance to manage the schema for.

getDatabasePlatform()

Returns the associated platform.

mixed
tryMethod()

Tries any method on the schema manager. Normally a method throws an exception when your DBMS doesn't support it or if an error occurs.

string[]
listDatabases()

Lists the available databases for this connection.

string[]
listNamespaceNames()

Returns a list of all namespaces in the current database.

listSequences(string|null $database = null)

Lists the available sequences for this connection.

Column[]
listTableColumns(string $table, string|null $database = null)

Lists the columns for a given table.

Index[]
listTableIndexes(string $table)

Lists the indexes for a given table returning an array of Index instances.

bool
tablesExist(string[] $tableNames)

Returns true if all the given tables exist.

string[]
listTableNames()

Returns a list of all tables in the current database.

mixed[]
filterAssetNames(mixed[] $assetNames)

Filters asset names if they are configured to return only a subset of all the found elements.

string|null
getFilterSchemaAssetsExpression() deprecated

No description

Table[]
listTables()

Lists the tables for this connection.

listTableDetails(string $tableName)

No description

View[]
listViews()

Lists the views this connection has.

listTableForeignKeys(string $table, string|null $database = null)

Lists the foreign keys for the given table.

void
dropDatabase(string $database)

Drops a database.

void
dropTable(string $tableName)

Drops the given table.

void
dropIndex(Index|string $index, Table|string $table)

Drops the index from the given table.

void
dropConstraint(Constraint $constraint, $table)

Drops the constraint from the given table.

void
dropForeignKey(ForeignKeyConstraint|string $foreignKey, Table|string $table)

Drops a foreign key from a table.

void
dropSequence(string $name)

Drops a sequence with a given name.

void
dropView(string $name)

Drops a view.

void
createDatabase(string $database)

Creates a new database.

void
createTable(Table $table)

Creates a new table.

void
createSequence(Sequence $sequence)

Creates a new sequence.

void
createConstraint(Constraint $constraint, $table)

Creates a constraint on a table.

void
createIndex(Index $index, $table)

Creates a new index on a table.

void
createForeignKey(ForeignKeyConstraint $foreignKey, Table|string $table)

Creates a new foreign key.

void
createView(View $view)

Creates a new view.

void
dropAndCreateConstraint(Constraint $constraint, $table)

Drops and creates a constraint.

void
dropAndCreateIndex(Index $index, $table)

Drops and creates a new index on a table.

void
dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, Table|string $table)

Drops and creates a new foreign key.

void
dropAndCreateSequence(Sequence $sequence)

Drops and create a new sequence.

void
dropAndCreateTable(Table $table)

Drops and creates a new table.

void
dropAndCreateDatabase(string $database)

Drops and creates a new database.

void
dropAndCreateView(View $view)

Drops and creates a new view.

void
alterTable(TableDiff $tableDiff)

Alters an existing tables schema.

void
renameTable(string $name, string $newName)

Renames a given table to another name.

string[]
_getPortableDatabasesList(mixed[] $databases)

No description

string[]
getPortableNamespacesList(array $namespaces)

Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition.

mixed
_getPortableDatabaseDefinition(mixed $database)

No description

mixed
getPortableNamespaceDefinition(array $namespace)

Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition.

mixed[][]
_getPortableFunctionsList(mixed[][] $functions)

No description

mixed
_getPortableFunctionDefinition(mixed[] $function)

No description

mixed[][]
_getPortableTriggersList(mixed[][] $triggers)

No description

mixed
_getPortableTriggerDefinition(mixed[] $trigger)

No description

_getPortableSequencesList(mixed[][] $sequences)

No description

_getPortableSequenceDefinition(mixed[] $sequence)

No description

Column[]
_getPortableTableColumnList(string $table, string $database, mixed[][] $tableColumns)

Independent of the database the keys of the column list result are lowercased.

_getPortableTableColumnDefinition(mixed[] $tableColumn)

Gets Table Column Definition.

Index[]
_getPortableTableIndexesList(mixed[][] $tableIndexRows, string|null $tableName = null)

Aggregates and groups the index results according to the required data result.

string[]
_getPortableTablesList(mixed[][] $tables)

No description

string
_getPortableTableDefinition(mixed $table)

No description

string[][]
_getPortableUsersList(mixed[][] $users)

No description

mixed[]
_getPortableUserDefinition(mixed[] $user)

No description

View[]
_getPortableViewsList(mixed[][] $views)

No description

View|false
_getPortableViewDefinition(mixed[] $view)

No description

_getPortableTableForeignKeysList(mixed[][] $tableForeignKeys)

No description

_getPortableTableForeignKeyDefinition(mixed $tableForeignKey)

No description

void
_execSql(string[]|string $sql)

No description

createSchema()

Creates a schema instance for the current database.

createSchemaConfig()

Creates the configuration for this schema.

string[]
getSchemaSearchPaths()

The search path for namespaces in the currently connected database.

string
extractDoctrineTypeFromComment(string $comment, string $currentType)

Given a table comment this method tries to extract a typehint for Doctrine Type, or returns the type given as default.

string
removeDoctrineTypeFromComment(string $comment, string $type)

No description

Details

__construct(Connection $conn, AbstractPlatform|null $platform = null)

Constructor. Accepts the Connection instance to manage the schema for.

Parameters

Connection $conn
AbstractPlatform|null $platform

AbstractPlatform getDatabasePlatform()

Returns the associated platform.

Return Value

AbstractPlatform

mixed tryMethod()

Tries any method on the schema manager. Normally a method throws an exception when your DBMS doesn't support it or if an error occurs.

This method allows you to try and method on your SchemaManager instance and will return false if it does not work or is not supported.

$result = $sm->tryMethod('dropView', 'view_name');

Return Value

mixed

string[] listDatabases()

Lists the available databases for this connection.

Return Value

string[]

string[] listNamespaceNames()

Returns a list of all namespaces in the current database.

Return Value

string[]

Sequence[] listSequences(string|null $database = null)

Lists the available sequences for this connection.

Parameters

string|null $database

Return Value

Sequence[]

Column[] listTableColumns(string $table, string|null $database = null)

Lists the columns for a given table.

In contrast to other libraries and to the old version of Doctrine, this column definition does try to contain the 'primary' field for the reason that it is not portable across different RDBMS. Use {see listTableIndexes($tableName)} to retrieve the primary key of a table. We're a RDBMS specifies more details these are held in the platformDetails array.

Parameters

string $table The name of the table.
string|null $database

Return Value

Column[]

Index[] listTableIndexes(string $table)

Lists the indexes for a given table returning an array of Index instances.

Keys of the portable indexes list are all lower-cased.

Parameters

string $table The name of the table.

Return Value

Index[]

bool tablesExist(string[] $tableNames)

Returns true if all the given tables exist.

Parameters

string[] $tableNames

Return Value

bool

string[] listTableNames()

Returns a list of all tables in the current database.

Return Value

string[]

protected mixed[] filterAssetNames(mixed[] $assetNames)

Filters asset names if they are configured to return only a subset of all the found elements.

Parameters

mixed[] $assetNames

Return Value

mixed[]

protected string|null getFilterSchemaAssetsExpression() deprecated

deprecated Use Configuration::getSchemaAssetsFilter() instead

Return Value

string|null

Table[] listTables()

Lists the tables for this connection.

Return Value

Table[]

Table listTableDetails(string $tableName)

Parameters

string $tableName

Return Value

Table

View[] listViews()

Lists the views this connection has.

Return Value

View[]

ForeignKeyConstraint[] listTableForeignKeys(string $table, string|null $database = null)

Lists the foreign keys for the given table.

Parameters

string $table The name of the table.
string|null $database

Return Value

ForeignKeyConstraint[]

void dropDatabase(string $database)

Drops a database.

NOTE: You can not drop the database this SchemaManager is currently connected to.

Parameters

string $database The name of the database to drop.

Return Value

void

void dropTable(string $tableName)

Drops the given table.

Parameters

string $tableName The name of the table to drop.

Return Value

void

void dropIndex(Index|string $index, Table|string $table)

Drops the index from the given table.

Parameters

Index|string $index The name of the index.
Table|string $table The name of the table.

Return Value

void

void dropConstraint(Constraint $constraint, $table)

Drops the constraint from the given table.

Parameters

Constraint $constraint
$table

Return Value

void

void dropForeignKey(ForeignKeyConstraint|string $foreignKey, Table|string $table)

Drops a foreign key from a table.

Parameters

ForeignKeyConstraint|string $foreignKey The name of the foreign key.
Table|string $table The name of the table with the foreign key.

Return Value

void

void dropSequence(string $name)

Drops a sequence with a given name.

Parameters

string $name The name of the sequence to drop.

Return Value

void

void dropView(string $name)

Drops a view.

Parameters

string $name The name of the view.

Return Value

void

void createDatabase(string $database)

Creates a new database.

Parameters

string $database The name of the database to create.

Return Value

void

void createTable(Table $table)

Creates a new table.

Parameters

Table $table

Return Value

void

void createSequence(Sequence $sequence)

Creates a new sequence.

Parameters

Sequence $sequence

Return Value

void

Exceptions

ConnectionException If something fails at database level.

void createConstraint(Constraint $constraint, $table)

Creates a constraint on a table.

Parameters

Constraint $constraint
$table

Return Value

void

void createIndex(Index $index, $table)

Creates a new index on a table.

Parameters

Index $index
$table

Return Value

void

void createForeignKey(ForeignKeyConstraint $foreignKey, Table|string $table)

Creates a new foreign key.

Parameters

ForeignKeyConstraint $foreignKey The ForeignKey instance.
Table|string $table The name of the table on which the foreign key is to be created.

Return Value

void

void createView(View $view)

Creates a new view.

Parameters

View $view

Return Value

void

void dropAndCreateConstraint(Constraint $constraint, $table)

Drops and creates a constraint.

Parameters

Constraint $constraint
$table

Return Value

void

See also

dropConstraint()
createConstraint()

void dropAndCreateIndex(Index $index, $table)

Drops and creates a new index on a table.

Parameters

Index $index
$table

Return Value

void

void dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, Table|string $table)

Drops and creates a new foreign key.

Parameters

ForeignKeyConstraint $foreignKey An associative array that defines properties of the foreign key to be created.
Table|string $table The name of the table on which the foreign key is to be created.

Return Value

void

void dropAndCreateSequence(Sequence $sequence)

Drops and create a new sequence.

Parameters

Sequence $sequence

Return Value

void

Exceptions

ConnectionException If something fails at database level.

void dropAndCreateTable(Table $table)

Drops and creates a new table.

Parameters

Table $table

Return Value

void

void dropAndCreateDatabase(string $database)

Drops and creates a new database.

Parameters

string $database The name of the database to create.

Return Value

void

void dropAndCreateView(View $view)

Drops and creates a new view.

Parameters

View $view

Return Value

void

void alterTable(TableDiff $tableDiff)

Alters an existing tables schema.

Parameters

TableDiff $tableDiff

Return Value

void

void renameTable(string $name, string $newName)

Renames a given table to another name.

Parameters

string $name The current name of the table.
string $newName The new name of the table.

Return Value

void

protected string[] _getPortableDatabasesList(mixed[] $databases)

Parameters

mixed[] $databases

Return Value

string[]

protected string[] getPortableNamespacesList(array $namespaces)

Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition.

Parameters

array $namespaces The list of namespace names in the native DBMS data definition.

Return Value

string[]

protected mixed _getPortableDatabaseDefinition(mixed $database)

Parameters

mixed $database

Return Value

mixed

protected mixed getPortableNamespaceDefinition(array $namespace)

Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition.

Parameters

array $namespace The native DBMS namespace definition.

Return Value

mixed

protected mixed[][] _getPortableFunctionsList(mixed[][] $functions)

Parameters

mixed[][] $functions

Return Value

mixed[][]

protected mixed _getPortableFunctionDefinition(mixed[] $function)

Parameters

mixed[] $function

Return Value

mixed

protected mixed[][] _getPortableTriggersList(mixed[][] $triggers)

Parameters

mixed[][] $triggers

Return Value

mixed[][]

protected mixed _getPortableTriggerDefinition(mixed[] $trigger)

Parameters

mixed[] $trigger

Return Value

mixed

protected Sequence[] _getPortableSequencesList(mixed[][] $sequences)

Parameters

mixed[][] $sequences

Return Value

Sequence[]

protected Sequence _getPortableSequenceDefinition(mixed[] $sequence)

Parameters

mixed[] $sequence

Return Value

Sequence

Exceptions

DBALException

protected Column[] _getPortableTableColumnList(string $table, string $database, mixed[][] $tableColumns)

Independent of the database the keys of the column list result are lowercased.

The name of the created column instance however is kept in its case.

Parameters

string $table The name of the table.
string $database
mixed[][] $tableColumns

Return Value

Column[]

protected Column _getPortableTableColumnDefinition(mixed[] $tableColumn)

Gets Table Column Definition.

Parameters

mixed[] $tableColumn

Return Value

Column

protected Index[] _getPortableTableIndexesList(mixed[][] $tableIndexRows, string|null $tableName = null)

Aggregates and groups the index results according to the required data result.

Parameters

mixed[][] $tableIndexRows
string|null $tableName

Return Value

Index[]

protected string[] _getPortableTablesList(mixed[][] $tables)

Parameters

mixed[][] $tables

Return Value

string[]

protected string _getPortableTableDefinition(mixed $table)

Parameters

mixed $table

Return Value

string

protected string[][] _getPortableUsersList(mixed[][] $users)

Parameters

mixed[][] $users

Return Value

string[][]

protected mixed[] _getPortableUserDefinition(mixed[] $user)

Parameters

mixed[] $user

Return Value

mixed[]

protected View[] _getPortableViewsList(mixed[][] $views)

Parameters

mixed[][] $views

Return Value

View[]

protected View|false _getPortableViewDefinition(mixed[] $view)

Parameters

mixed[] $view

Return Value

View|false

protected ForeignKeyConstraint[] _getPortableTableForeignKeysList(mixed[][] $tableForeignKeys)

Parameters

mixed[][] $tableForeignKeys

Return Value

ForeignKeyConstraint[]

protected ForeignKeyConstraint _getPortableTableForeignKeyDefinition(mixed $tableForeignKey)

Parameters

mixed $tableForeignKey

Return Value

ForeignKeyConstraint

protected void _execSql(string[]|string $sql)

Parameters

string[]|string $sql

Return Value

void

Schema createSchema()

Creates a schema instance for the current database.

Return Value

Schema

SchemaConfig createSchemaConfig()

Creates the configuration for this schema.

Return Value

SchemaConfig

string[] getSchemaSearchPaths()

The search path for namespaces in the currently connected database.

The first entry is usually the default namespace in the Schema. All further namespaces contain tables/sequences which can also be addressed with a short, not full-qualified name.

For databases that don't support subschema/namespaces this method returns the name of the currently connected database.

Return Value

string[]

string extractDoctrineTypeFromComment(string $comment, string $currentType)

Given a table comment this method tries to extract a typehint for Doctrine Type, or returns the type given as default.

Parameters

string $comment
string $currentType

Return Value

string

string removeDoctrineTypeFromComment(string $comment, string $type)

Parameters

string $comment
string $type

Return Value

string