Problem/Motivation

The philosophy in the core database layer is to encapsulate all field names with brackets, then allow the database to convert those into quotes if needed.

There are core queries that contain sql server reserved words. Either these need to be quoted, or the database driver needs to maintain a list of all reserved words, search every query, and encapsulate any matches.

One example is:
SELECT data FROM {config} WHERE name = :name found in core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php. The word ‘data’ is a MSSQL reserved word.

Child issues

CommentFileSizeAuthor
#6 3136974-4.patch7.73 KBbeakerboy
#4 3136974-4.patch0 bytesbeakerboy

Comments

Beakerboy created an issue. See original summary.

beakerboy’s picture

daffie’s picture

The word ‘data’ is a MSSQL reserved word.

And Drupal loves to to call fields "data".

In #2986452: Database reserved keywords need to be quoted as per the ANSI standard we removed the whole "maintain a list of all reserved words" stuff and fields must be encapsulated with square brackets. Changing the queries from Connection->query() to Connection->select() is not allowed. The problem is that queries run with Connection->select() are a little bit slower then the ones run with Connection->query(). If we are going to do this then all the Connection->query() queries must change to using the quare brackets. This will be a very big change and a 2MB patch is not reviewable! Therefor my suggestion would be to change this isssue to a meta issue and start thinking how we can best divide it up into smaller sub-issues. Best ask one of the core committers for advice for the best way to divide it into sub-issues.

beakerboy’s picture

StatusFileSize
new0 bytes

This patch covers the cases of ‘data’ that are preventing SQL Server from running tests.

beakerboy’s picture

Status: Active » Needs review
beakerboy’s picture

StatusFileSize
new7.73 KB
daffie’s picture

@beakerboy: There are a lot more queries in core with fields that need to be put in between square brackets. What is your plan for that? The change is the current patch look good.

beakerboy’s picture

I posed that question to @alexpott. He suggested moving anything that is “not in the critical path” to dynamic (which I know you’d be happy to hear). Don’t know what the “plan” is though. The topic is on slack right next to the one regarding this issue. I need this to even begin testing sqlsrv on D9.

daffie’s picture

Talked to @alexpott on Slack and we change every static query to dynamic. He shall then review the patch and say which ones are in the critical path. Does we need to change back.

My suggestion would be to change this issue to a "META" issue and create sub-issue's with the actual patches in them. The question who are we going to split it up into smaller pieces. Some of the static queries need to be converted to an entity query. Like \Drupal\node\Plugin\Action\AssignOwnerNode::buildConfigurationForm().

My suggestion for splitting up the sub-issues:
- core/includes
- core/lib/Drupal/Core (without core/lib/Drupal/Core/Database)
- one for the module's: action up to and including comment
- one for the module: dblog
- one for the module's: forum up to and including locale
- one for the module's: migrate up to and including migrate_drupal
- one for the module: node
- one for the module's: path up to and including system
- one for the module's: taxonomy up to and including user
- one for the module: views
- core/tests/Drupal/FunctionalTests
- core/tests/Drupal/KernelTests (without core/tests/Drupal/KernelTests/Database)

@Beakerboy What do you think of my plan. Improvements are welcome.

beakerboy’s picture

My plan was to make this a “single issue” to get my immediate roadblock fixed. I made a separate “plan” issue (linked as related to this one) #3151225: Quote identifiers in core static queries..

Other than that, I like it!

daffie’s picture

daffie’s picture

@alexpott said on Slack:

I don’t think it is really about that. I’d be happy for all the tests in one issue. Yes it’ll be a pain to review but 3 of us can get this done.

and

And then we can tightly scope the rest around concepts… like conversion to node entity query.

What do you prefer @Beakerboy: writing the patch or reviewing the patch?

beakerboy’s picture

@daffie, I do not have the time or resources to write a patch of this scale, but can push things along. I basically use GitHub as my API and do most of my coding on my iPhone...sometimes using ssh/vim into a hobby server to create a patch, which I use safari to upload to Drupal. My focus is to ensure the sqlsrv driver continues to work, because I use it for my job. I can’t dive into major infrastructure refactoring. I will certainly test what I can with the tools I have and provide feedback.

daffie’s picture

Title: Field names in core static queries should be bracket-encapsulated » [META] Field names in core static queries should be bracket-encapsulated
Status: Needs review » Active
daffie’s picture

Issue summary: View changes
daffie’s picture

Issue tags: +Bug Smash Initiative

Version: 9.0.x-dev » 9.1.x-dev

Drupal 9.0.10 was released on December 3, 2020 and is the final full bugfix release for the Drupal 9.0.x series. Drupal 9.0.x will not receive any further development aside from security fixes. Sites should update to Drupal 9.1.0 to continue receiving regular bugfixes.

Drupal-9-only bug reports should be targeted for the 9.1.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.2.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

daffie’s picture

beakerboy’s picture

Status: Active » Fixed

All the child issues are marked as closed. So I believe this is done.

daffie’s picture

We have only #3130579: Make Drupal\Core\Database\Schema work with reserved keywords for naming and then core works with reserved keywords for naming.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.