Problem/Motivation
Drupal 9 recently added the Connection::identifierQuote(). SQL Server does not use a single character to enclose reserved words. It uses square brackets. We need to be able to handle situations where the opening and closing character are different.
Proposed resolution
Instead of having a method to return a string use a class property which is an array with two string values - the start and end quote character.
Remaining tasks
None
User interface changes
None
API changes
Remove \Drupal\Core\Database\Connection::identifierQuote() and replace with \Drupal\Core\Database\Connection::$identifierQuotes
Data model changes
None
Release notes snippet
Custom or contrib database drivers updated for the recent identifier quote change will need to remove \Drupal\Core\Database\Connection::identifierQuote() and replace with \Drupal\Core\Database\Connection::$identifierQuotes. Read https://www.drupal.org/node/2986894 for more information about both changes.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3126658-alt-10.patch | 20.44 KB | alexpott |
| #10 | 3126658-alt-9.0.x-10.patch | 20.24 KB | alexpott |
| #10 | 6-10-interdiff.txt | 641 bytes | alexpott |
Comments
Comment #2
alexpott@Beakerboy thanks for testing Drupal 9 prior to release. It's great to get real world testing of #2986452: Database reserved keywords need to be quoted as per the ANSI standard prior to it landing. Especially real world testing that reveals a flaw in the design where this was supposed to make things much easier for contrib drivers like sqlsrv. I'll work on this this weekend if no-one beats me to it.
Comment #3
catchComment #4
alexpottHere are two ways to fix this. One is less of an API change than the other. Personally I prefer the -alt patch which changes the protected function \Drupal\Core\Database\Connection::identifierQuote() return value to be an array. This function only exists within 9.0.x and is in a very low level part of the system and is protected.
Comment #5
alexpottAfter sleeping on this I've realised that using a method to contain the identifier quotes is more than a little bit awkward. You should do something functional is that method - so we can make it a property but still keep the deprecation and means no one is wondering about
\Drupal\Core\Database\Connection::quoteIdentifiers()vs\Drupal\Core\Database\Connection::identifierQuote()/\Drupal\Core\Database\Connection::identifierQuotes().Comment #6
alexpottMore assert() magic for enforcing the contract.
Comment #7
daffie commentedStraight reroll no changes.
Comment #8
daffie commentedPatch looks good. My preference is the alternative solution.
My review for the patch from comment #6.
$identifierQuotes, can we do 2 variables:$identifierStartingQuoteand$identifierEndingQuote. Less confusion. We do not have to, just an idea.So for SQL Server, they will be replacing the blockquotes with blockquotes. :)
providerEscapeAlias().Comment #9
daffie commentedWhat ever solution it will be we shall have to update the CR in https://www.drupal.org/node/3123251.
Comment #10
alexpott@daffie good call on the additional test. Personally I prefer a single class property for this.
re $identifierStartingQuote and $identifierEndingQuote I think 1 class property is better in this instance than two. Easier to keep consistent.
I've pondered several times whether we should allow a single element array if the quotes are the same or whether a string of 1 or 2 characters for the same thing.
Seems like we need 9.1.x and 9.0.x patches. Oh yay.
Comment #11
daffie commentedAll the code changes look good to me.
Removed the method
Drupal\Core\Database\Connection::identifierQuote().Added the class variable
Drupal\Core\Database\Connection::$identifierQuotes.The change record must be changed for this. The problem is that this can only be done after this issue has landed, because the CR is already published.
For me the patch is RTBC.
Comment #14
catchAgreed we should just get this in since it's not been in for long in its current state.
Committed/pushed to 9.1.x and 9.0.x, thanks!
edit: CR still needs updating.
Comment #15
catchArghh also needs a release notes snippet.
Comment #16
daffie commentedUpdated the CR https://www.drupal.org/node/2986894 for this issue.
Comment #17
alexpott@daffie the changes to the CR look good.
Added a release note and filled out the issue summary.