Commit 2815335e authored by Benjamin Eberlei's avatar Benjamin Eberlei

[DBAL-555] replace a bunch of occurances of $diff->name and $diff->newName...

[DBAL-555] replace a bunch of occurances of $diff->name and $diff->newName with quoted identifier version.
parent 75d35f58
...@@ -1717,7 +1717,7 @@ abstract class AbstractPlatform ...@@ -1717,7 +1717,7 @@ abstract class AbstractPlatform
*/ */
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{ {
$tableName = $diff->name; $tableName = $diff->getName()->getQuotedName($this);
$sql = array(); $sql = array();
if ($this->supportsForeignKeyConstraints()) { if ($this->supportsForeignKeyConstraints()) {
...@@ -1746,7 +1746,9 @@ abstract class AbstractPlatform ...@@ -1746,7 +1746,9 @@ abstract class AbstractPlatform
*/ */
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
{ {
$tableName = false !== $diff->newName ? $diff->newName : $diff->name; $tableName = (false !== $diff->newName)
? $diff->getNewName()->getQuotedName($this)
: $diff->getName()->getQuotedName($this);
$sql = array(); $sql = array();
if ($this->supportsForeignKeyConstraints()) { if ($this->supportsForeignKeyConstraints()) {
......
...@@ -493,12 +493,12 @@ class DB2Platform extends AbstractPlatform ...@@ -493,12 +493,12 @@ class DB2Platform extends AbstractPlatform
if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { if ( ! $this->onSchemaAlterTable($diff, $tableSql)) {
if (count($queryParts) > 0) { if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(" ", $queryParts); $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . implode(" ", $queryParts);
} }
// Some table alteration operations require a table reorganization. // Some table alteration operations require a table reorganization.
if ( ! empty($diff->removedColumns) || ! empty($diff->changedColumns)) { if ( ! empty($diff->removedColumns) || ! empty($diff->changedColumns)) {
$sql[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE " . $diff->name . "')"; $sql[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE " . $diff->getName()->getQuotedName($this) . "')";
} }
$sql = array_merge( $sql = array_merge(
...@@ -508,7 +508,7 @@ class DB2Platform extends AbstractPlatform ...@@ -508,7 +508,7 @@ class DB2Platform extends AbstractPlatform
); );
if ($diff->newName !== false) { if ($diff->newName !== false) {
$sql[] = 'RENAME TABLE ' . $diff->name . ' TO ' . $diff->newName; $sql[] = 'RENAME TABLE ' . $diff->getName()->getQuotedName($this) . ' TO ' . $diff->getNewName()->getQuotedName($this);
} }
} }
...@@ -521,7 +521,7 @@ class DB2Platform extends AbstractPlatform ...@@ -521,7 +521,7 @@ class DB2Platform extends AbstractPlatform
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{ {
$sql = array(); $sql = array();
$table = $diff->name; $table = $diff->getName()->getQuotedName($this);
foreach ($diff->removedIndexes as $remKey => $remIndex) { foreach ($diff->removedIndexes as $remKey => $remIndex) {
foreach ($diff->addedIndexes as $addKey => $addIndex) { foreach ($diff->addedIndexes as $addKey => $addIndex) {
......
...@@ -396,7 +396,7 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -396,7 +396,7 @@ class DrizzlePlatform extends AbstractPlatform
$queryParts = array(); $queryParts = array();
if ($diff->newName !== false) { if ($diff->newName !== false) {
$queryParts[] = 'RENAME TO ' . $diff->newName; $queryParts[] = 'RENAME TO ' . $diff->getNewName()->getQuotedName($this);
} }
foreach ($diff->addedColumns as $column) { foreach ($diff->addedColumns as $column) {
...@@ -446,7 +446,7 @@ class DrizzlePlatform extends AbstractPlatform ...@@ -446,7 +446,7 @@ class DrizzlePlatform extends AbstractPlatform
if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { if ( ! $this->onSchemaAlterTable($diff, $tableSql)) {
if (count($queryParts) > 0) { if (count($queryParts) > 0) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . implode(", ", $queryParts); $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . implode(", ", $queryParts);
} }
$sql = array_merge( $sql = array_merge(
$this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPreAlterTableIndexForeignKeySQL($diff),
......
...@@ -615,7 +615,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -615,7 +615,7 @@ LEFT JOIN user_cons_columns r_cols
} }
if (count($fields)) { if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ADD (' . implode(', ', $fields) . ')'; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ADD (' . implode(', ', $fields) . ')';
} }
$fields = array(); $fields = array();
...@@ -650,7 +650,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -650,7 +650,7 @@ LEFT JOIN user_cons_columns r_cols
} }
if (count($fields)) { if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' MODIFY (' . implode(', ', $fields) . ')'; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' MODIFY (' . implode(', ', $fields) . ')';
} }
foreach ($diff->renamedColumns as $oldColumnName => $column) { foreach ($diff->renamedColumns as $oldColumnName => $column) {
...@@ -658,7 +658,7 @@ LEFT JOIN user_cons_columns r_cols ...@@ -658,7 +658,7 @@ LEFT JOIN user_cons_columns r_cols
continue; continue;
} }
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME COLUMN ' . $oldColumnName .' TO ' . $column->getQuotedName($this); $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' RENAME COLUMN ' . $oldColumnName .' TO ' . $column->getQuotedName($this);
} }
$fields = array(); $fields = array();
...@@ -671,14 +671,14 @@ LEFT JOIN user_cons_columns r_cols ...@@ -671,14 +671,14 @@ LEFT JOIN user_cons_columns r_cols
} }
if (count($fields)) { if (count($fields)) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' DROP (' . implode(', ', $fields).')'; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' DROP (' . implode(', ', $fields).')';
} }
$tableSql = array(); $tableSql = array();
if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { if ( ! $this->onSchemaAlterTable($diff, $tableSql)) {
if ($diff->newName !== false) { if ($diff->newName !== false) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' RENAME TO ' . $diff->getNewName()->getQuotedName($this);
} }
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL); $sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
......
...@@ -421,7 +421,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -421,7 +421,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
$query = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); $query = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . $query;
if ($comment = $this->getColumnComment($column)) { if ($comment = $this->getColumnComment($column)) {
$commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment); $commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment);
} }
...@@ -433,7 +433,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -433,7 +433,7 @@ class PostgreSqlPlatform extends AbstractPlatform
} }
$query = 'DROP ' . $column->getQuotedName($this); $query = 'DROP ' . $column->getQuotedName($this);
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . $query;
} }
foreach ($diff->changedColumns as $columnDiff) { foreach ($diff->changedColumns as $columnDiff) {
...@@ -450,17 +450,17 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -450,17 +450,17 @@ class PostgreSqlPlatform extends AbstractPlatform
// here was a server version check before, but DBAL API does not support this anymore. // here was a server version check before, but DBAL API does not support this anymore.
$query = 'ALTER ' . $oldColumnName . ' TYPE ' . $type->getSqlDeclaration($column->toArray(), $this); $query = 'ALTER ' . $oldColumnName . ' TYPE ' . $type->getSqlDeclaration($column->toArray(), $this);
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . $query;
} }
if ($columnDiff->hasChanged('default')) { if ($columnDiff->hasChanged('default')) {
$query = 'ALTER ' . $oldColumnName . ' SET ' . $this->getDefaultValueDeclarationSQL($column->toArray()); $query = 'ALTER ' . $oldColumnName . ' SET ' . $this->getDefaultValueDeclarationSQL($column->toArray());
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . $query;
} }
if ($columnDiff->hasChanged('notnull')) { if ($columnDiff->hasChanged('notnull')) {
$query = 'ALTER ' . $oldColumnName . ' ' . ($column->getNotNull() ? 'SET' : 'DROP') . ' NOT NULL'; $query = 'ALTER ' . $oldColumnName . ' ' . ($column->getNotNull() ? 'SET' : 'DROP') . ' NOT NULL';
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . $query;
} }
if ($columnDiff->hasChanged('autoincrement')) { if ($columnDiff->hasChanged('autoincrement')) {
...@@ -469,13 +469,13 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -469,13 +469,13 @@ class PostgreSqlPlatform extends AbstractPlatform
$seqName = $diff->name . '_' . $oldColumnName . '_seq'; $seqName = $diff->name . '_' . $oldColumnName . '_seq';
$sql[] = "CREATE SEQUENCE " . $seqName; $sql[] = "CREATE SEQUENCE " . $seqName;
$sql[] = "SELECT setval('" . $seqName . "', (SELECT MAX(" . $oldColumnName . ") FROM " . $diff->name . "))"; $sql[] = "SELECT setval('" . $seqName . "', (SELECT MAX(" . $oldColumnName . ") FROM " . $diff->getName()->getQuotedName($this) . "))";
$query = "ALTER " . $oldColumnName . " SET DEFAULT nextval('" . $seqName . "')"; $query = "ALTER " . $oldColumnName . " SET DEFAULT nextval('" . $seqName . "')";
$sql[] = "ALTER TABLE " . $diff->name . " " . $query; $sql[] = "ALTER TABLE " . $diff->getName()->getQuotedName($this) . " " . $query;
} else { } else {
// Drop autoincrement, but do NOT drop the sequence. It might be re-used by other tables or have // Drop autoincrement, but do NOT drop the sequence. It might be re-used by other tables or have
$query = "ALTER " . $oldColumnName . " " . "DROP DEFAULT"; $query = "ALTER " . $oldColumnName . " " . "DROP DEFAULT";
$sql[] = "ALTER TABLE " . $diff->name . " " . $query; $sql[] = "ALTER TABLE " . $diff->getName()->getQuotedName($this) . " " . $query;
} }
} }
...@@ -489,7 +489,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -489,7 +489,7 @@ class PostgreSqlPlatform extends AbstractPlatform
if ($columnDiff->hasChanged('length')) { if ($columnDiff->hasChanged('length')) {
$query = 'ALTER ' . $column->getName() . ' TYPE ' . $column->getType()->getSqlDeclaration($column->toArray(), $this); $query = 'ALTER ' . $column->getName() . ' TYPE ' . $column->getType()->getSqlDeclaration($column->toArray(), $this);
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . $query;
} }
} }
...@@ -498,14 +498,14 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -498,14 +498,14 @@ class PostgreSqlPlatform extends AbstractPlatform
continue; continue;
} }
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME COLUMN ' . $oldColumnName . ' TO ' . $column->getQuotedName($this); $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' RENAME COLUMN ' . $oldColumnName . ' TO ' . $column->getQuotedName($this);
} }
$tableSql = array(); $tableSql = array();
if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { if ( ! $this->onSchemaAlterTable($diff, $tableSql)) {
if ($diff->newName !== false) { if ($diff->newName !== false) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' RENAME TO ' . $diff->newName; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' RENAME TO ' . $diff->getNewName()->getQuotedName($this);
} }
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL); $sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL);
......
...@@ -570,13 +570,13 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -570,13 +570,13 @@ class SQLServerPlatform extends AbstractPlatform
} }
foreach ($queryParts as $query) { foreach ($queryParts as $query) {
$sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; $sql[] = 'ALTER TABLE ' . $diff->getName()->getQuotedName($this) . ' ' . $query;
} }
$sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSql); $sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSql);
if ($diff->newName !== false) { if ($diff->newName !== false) {
$sql[] = "sp_RENAME '" . $diff->name . "', '" . $diff->newName . "'"; $sql[] = "sp_RENAME '" . $diff->getName()->getQuotedName($this) . "', '" . $diff->getNewName()->getQuotedName($this) . "'";
/** /**
* Rename table's default constraints names * Rename table's default constraints names
...@@ -592,7 +592,7 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -592,7 +592,7 @@ class SQLServerPlatform extends AbstractPlatform
"'" . $this->generateIdentifierName($diff->newName) . "') + ''', ''OBJECT'';' " . "'" . $this->generateIdentifierName($diff->newName) . "') + ''', ''OBJECT'';' " .
"FROM sys.default_constraints dc " . "FROM sys.default_constraints dc " .
"JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id " . "JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id " .
"WHERE tbl.name = '" . $diff->newName . "';" . "WHERE tbl.name = '" . $diff->getNewName()->getQuotedName($this) . "';" .
"EXEC sp_executesql @sql"; "EXEC sp_executesql @sql";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment