-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix escaping database name for SqlServerAdapter::dropDatabase #2287
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,7 +211,7 @@ public function quoteTableName(string $tableName): string | |
*/ | ||
public function quoteColumnName(string $columnName): string | ||
{ | ||
return '[' . str_replace(']', '\]', $columnName) . ']'; | ||
return '[' . str_replace(']', ']]', $columnName) . ']'; | ||
} | ||
|
||
/** | ||
|
@@ -1176,7 +1176,7 @@ public function createDatabase(string $name, array $options = []): void | |
{ | ||
$databaseName = $this->quoteColumnName($name); | ||
if (isset($options['collation'])) { | ||
$this->execute(sprintf('CREATE DATABASE %s COLLATE [%s]', $databaseName, $options['collation'])); | ||
$this->execute(sprintf('CREATE DATABASE %s COLLATE %s', $databaseName, $options['collation'])); | ||
} else { | ||
$this->execute(sprintf('CREATE DATABASE %s', $databaseName)); | ||
} | ||
|
@@ -1204,12 +1204,13 @@ public function hasDatabase(string $name): bool | |
*/ | ||
public function dropDatabase(string $name): void | ||
{ | ||
$sql = <<<SQL | ||
USE master; | ||
IF EXISTS(select * from sys.databases where name=N'$name') | ||
ALTER DATABASE [$name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; | ||
DROP DATABASE [$name]; | ||
SQL; | ||
$sql = sprintf( | ||
'USE master; | ||
IF EXISTS(select * from sys.databases where name=N\'' . $name . '\') | ||
ALTER DATABASE %1$s SET SINGLE_USER WITH ROLLBACK IMMEDIATE; | ||
DROP DATABASE %1$s;', | ||
Comment on lines
+1210
to
+1211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By using |
||
$this->quoteColumnName($name), | ||
); | ||
$this->execute($sql); | ||
$this->createdTables = []; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why the collate argument had brackets around it as it's not an identifier and shouldn't be created as such. I also tried
'
and"
and it didn't work either.This has probably been broken for a long time, and I guess no one is creating databases with specific collations.