Skip to content
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

[WIP] Fix MariaDB reserved keywords issue #70

Closed
wants to merge 1 commit into from

Conversation

ausi
Copy link
Member

@ausi ausi commented Sep 25, 2017

@ausi
Copy link
Member Author

ausi commented Sep 26, 2017

To be honest: I don’t really like this approach. Running replacements via regular expressions on database queries is generally not a good idea.

A better idea may be to replace the Doctrine\DBAL\Platforms\MySqlPlatform and overwriting the getReservedKeywordsClass() method. @contao/developers what do you think?

Anyway, I think we should apply this fix only to version 4.4, and remove it again in 4.5.

@aschempp
Copy link
Member

what if someone already uses PHP 7.1 and therefore DBAL 2.6? Would'nt the name already be escaped?

@ausi
Copy link
Member Author

ausi commented Sep 26, 2017

Yes, it would. But the regular expression wouldn’t match then. I will add unit tests for these cases after we agree which way we want to go.

@aschempp
Copy link
Member

A better idea may be to replace the Doctrine\DBAL\Platforms\MySqlPlatform and overwriting the getReservedKeywordsClass() method. @contao/developers what do you think?

Not really gonna work, the method is final public in AbstractPlatform 😢

@Toflar
Copy link
Member

Toflar commented Sep 26, 2017

I'm still not sure we should fix this issue at all. This issue only happens in the latest MariaDB. So I don't understand why you would want to use the latest MariaDB with an old PHP version? Just update to PHP 7.1 and it will all just work fine?

@aschempp
Copy link
Member

Just update to PHP 7.1 and it will all just work fine?

Yeah, apart from the fact that some users can't control that, and therefore will run into random errors...

@Toflar
Copy link
Member

Toflar commented Sep 26, 2017

That's such an edge case, really. Why in the world would any provider update their DB stack but not their php stack. That makes no sense at all.

@ausi
Copy link
Member Author

ausi commented Sep 26, 2017

I think several people already had this problem as discussed in contao/core-bundle#918. So it’s probably not an edge case...

@stefansl
Copy link

stefansl commented Sep 26, 2017

Why in the world would any provider update their DB stack but not their php

They do update php as well. But they leave the option to choose an older php version. ;) Imagine, someone has chosen php 5.6 and the provider updates the system. The php version is still the old one.

@ausi
Copy link
Member Author

ausi commented Sep 26, 2017

A better idea may be to replace the Doctrine\DBAL\Platforms\MySqlPlatform and overwriting the getReservedKeywordsClass() method. @contao/developers what do you think?

Not really gonna work, the method is final public in AbstractPlatform 😢

It’s protected, not final: https://github.com/doctrine/dbal/blob/v2.5.13/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php#L1034

But I’m not sure how easy it is to replace the platform service in the doctrine configuration and if it is a good idea to do so.

@Toflar
Copy link
Member

Toflar commented Sep 26, 2017

I have a bad gut feeling about that regex escaping to be honest. Feels like this can cause more issues than it solves.

I know that this PR aims to fix the schema update but you can still have that problem if any extension queries like SELECT rows FROM table instead of SELECT `rows` FROM table. So there is no way we can ensure people will "not run into random errors". It's not an issue caused by Contao nor can we control it. It's an issue caused by updates to the database engine and that's why we should ignore that.

@fritzmg
Copy link
Contributor

fritzmg commented Sep 26, 2017

Just update to PHP 7.1 and it will all just work fine?

Some projects might have dependencies, that will prevent composer to update to doctrine/dbal 2.6.x. Or projects might have dependencies, that do not run on PHP 7.1 (yet).

Just saying, not that I care that much about it ;). In general I agree with @Toflar

@Toflar
Copy link
Member

Toflar commented Sep 26, 2017

Again. This PR does not solve the issue at all. It tries to solve it for schema updates which would already be covered if you had php 7.1. Still there might be hundreds of extensions that query on a now reserved word without quoting it and we cannot solve the problem for them. Everyone has to solve it individually. It's not a Contao problem. It does not need to be "fixed" by Contao.

@aschempp
Copy link
Member

It’s protected, not final: https://github.com/doctrine/dbal/blob/v2.5.13/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php#L1034

You're right, I was looking at getReserverdKeywordsList: https://github.com/doctrine/dbal/blob/v2.5.13/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L3479

But I’m not sure how easy it is to replace the platform service in the doctrine configuration and if it is a good idea to do so.

Replacing the platform is easy and a supported use-case as far as I know, but it would obviously affect the whole Symfony setup and not just Contao. Not sure if we want to do that (same discussion as with all the other Symfony services).

Another option would be replace just the keywords class, but that would require reflections. Not that it would matter, as everything in Doctrine (ORM) uses reflections already 😂

I have a bad gut feeling about that regex escaping to be honest. Feels like this can cause more issues than it solves.

Be aware that the database installer already uses tons of regex to convert the Doctrine Schema to our readable instructions. No real issue for me honestly.

@ausi
Copy link
Member Author

ausi commented Sep 26, 2017

Still there might be hundreds of extensions that query on a now reserved word without quoting it and we cannot solve the problem for them. Everyone has to solve it individually. It's not a Contao problem. It does not need to be "fixed" by Contao.

Contao itself uses column names unquoted in many many places, so it has to be fixed by Contao IMO. Either by not using reserved words as column names, or by escaping column names everywhere.

@aschempp
Copy link
Member

Either by not using reserved words as column names, or by escaping column names everywhere.

Correct. And the only update-safe implementation is escaping. Because either we might need to rename over and over again, or just add a new reserved keyword to an existing escaping method.

@leofeyer leofeyer changed the base branch from master to 4.4 December 14, 2017 19:37
@leofeyer leofeyer added this to the 4.4.10 milestone Dec 15, 2017
@ausi
Copy link
Member Author

ausi commented Dec 20, 2017

With contao/core-bundle#1262 we now escape the column names in Contao properly. As discussed, we don’t want to hack in support for using MariaDB 10.2.4 with PHP 5, so I’m closing this PR.

For the record, the following setups should work from now on:

  • Contao 4.4 with PHP 7 and any MariaDB-Version
  • Contao 4.4 with PHP 5 and MariaDB 10.2.3 and lower
  • Contao 3.5 with any PHP- and any MariaDB-Version

The only setup that is not supported is:

  • Contao 4.4 with PHP 5 and MariaDB 10.2.4 or higher

@ausi ausi closed this Dec 20, 2017
leofeyer pushed a commit to contao/core-bundle that referenced this pull request Dec 27, 2017
Description
-----------

This is the port of contao/core#8813.

Also see #1106 and contao/installation-bundle#70

Commits
-------

84c4746 Quote reserved words in database queries
7bf64b1 Use static instead of \Database as self-reference.
@leofeyer leofeyer modified the milestones: 4.4.10, 4.4 May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants