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

Don't use double quotes in MySQL queries #8391

Merged
merged 1 commit into from
Feb 16, 2018

Conversation

coder-hugo
Copy link
Contributor

MySQL databases with the ANSI_QUOTES mode enabled treat " as an identifier quote. So for such databases the 'occ upgrade' fails with an error message like this:
... unknown column 'oc_*' in where clause.

This fix replaces the doulbe quotes with single quotes that should be always used in MySQL queries to quote literal strings.

@MorrisJobke MorrisJobke added this to the Nextcloud 14 milestone Feb 16, 2018
@@ -70,6 +70,7 @@ protected function setUp() {

$dbPrefix = $this->config->getSystemValue("dbtableprefix");
$this->tableName = $this->getUniqueID($dbPrefix . "_collation_test");
$this->connection->exec("SET SESSION sql_mode = CONCAT(@@SESSION.sql_mode, ',ANSI_QUOTES')");
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only way to ensure that the MySQL server has enabled the ANSI_QUOTES mode for the test that I've found. If there is a better solution to configure the MySQL server for the tests just let me know.

Copy link
Member

Choose a reason for hiding this comment

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

But is it necessary to make the tests pass? If not, I would leave it out, to make sure it works even without it.
Because now you force it on the unit tests, but in production we work without the option, so we can not be sure they behave the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test will pass also without this line. I just added the line after reading the contribution guide. This guide "forces" tests for changed code. If it's OK for you that there isn't a test for this change I'll remove this line. Can I do this with a force push or will this break the history of the PR?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah remove it and do a force push

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could have both cases covered as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could clone the method testCollationConvert and enable the ANSI_QUOTES mode just for the new method to cover both cases. But I think the better way of testing this would be either to run all MySQL tests for a MySQL server that has enabled the ANSI_QUOTES mode and for one that hasn't or to enable the mode at all. This would prevent any further issues in the future where double quotes are used within MySQL queries. An extra test for the collation convert would just prevent that someone will add again double quotes within this which should be very unlikely.

Copy link
Member

Choose a reason for hiding this comment

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

True point. Would you mind to create this in a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd definitively do this in a separate PR. But at the moment I haven't got the time for doing this. So I'll remove this line for the moment. Maybe there is some time next week to have a deeper look into the testing stuff.

@codecov
Copy link

codecov bot commented Feb 16, 2018

Codecov Report

Merging #8391 into master will increase coverage by 0.06%.
The diff coverage is 0%.

@@             Coverage Diff              @@
##             master    #8391      +/-   ##
============================================
+ Coverage     51.71%   51.77%   +0.06%     
  Complexity    25404    25404              
============================================
  Files          1600     1600              
  Lines         95135    95135              
  Branches       1377     1377              
============================================
+ Hits          49199    49258      +59     
+ Misses        45936    45877      -59
Impacted Files Coverage Δ Complexity Δ
lib/private/Repair/Collation.php 0% <0%> (ø) 16 <0> (ø) ⬇️
core/js/js.js 65.74% <0%> (-0.56%) 0% <0%> (ø)
apps/files_trashbin/lib/Trashbin.php 72.46% <0%> (-0.25%) 136% <0%> (ø)
lib/private/Files/ObjectStore/Swift.php 49.61% <0%> (+49.61%) 45% <0%> (ø) ⬇️

MySQL databases with the ANSI_QUOTES mode enabled treat " as an identifier
quote (see https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_ansi_quotes).
So for such databases the 'occ upgrade' fails with an error message like this:
... unknown column 'oc_*' in where clause.

This fix replaces the doulbe quotes with single quotes that should be always
used in MySQL queries to quote literal strings.

Signed-off-by: Robin Müller <robin.mueller@1und1.de>
@coder-hugo coder-hugo force-pushed the feature/mysql_ansi_quotes branch from 5c4aa17 to 6aa8169 Compare February 16, 2018 14:04
@MorrisJobke MorrisJobke merged commit 45e7bb7 into nextcloud:master Feb 16, 2018
@coder-hugo coder-hugo deleted the feature/mysql_ansi_quotes branch February 19, 2018 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants