Skip to content

Conversation

@MasterOdin
Copy link
Member

@MasterOdin MasterOdin commented Jun 4, 2024

PR fixes a bug introduced in #2286 that broke dropping databases in sqlserver. I've fixed the syntax so that it actually works for database names that need escaping, discovering as well that the escaping of column names was also broken. Per https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms176027(v=sql.105)?redirectedfrom=MSDN, to escape an identifier that has brackets, need to double up the brackets, not use \.

@MasterOdin MasterOdin marked this pull request as ready for review June 5, 2024 02:42
Comment on lines +1210 to +1211
ALTER DATABASE %1$s SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE %1$s;',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By using %1$s, I'm able to replace both instances with a single value. Downside is that cannot use " around the string like do in other places. Could use a heredoc, and then run the $sql through sprintf on a separate line, but that didn't feel in line with other places sprintf is used.

$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']));
Copy link
Member Author

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.

@MasterOdin MasterOdin merged commit ef38e41 into 0.x Jun 5, 2024
@MasterOdin MasterOdin deleted the fix-database-escaped-characters branch June 5, 2024 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants