d6lts / drupal

Fork of Drupal core for Drupal 6 LTS support.
https://www.drupal.org
GNU General Public License v2.0
130 stars 45 forks source link

MySQL 8 compatibility #35

Closed f1mishutka closed 5 years ago

f1mishutka commented 5 years ago

'system' is reserved keyword in MySQL since version 8.0.0 so need to escape it to be able to select from system table.

There is a list of all reserved keywords, so escaping them all to make it more universal.

Changes are based on Drupal 7 and 8 patches for MySQL 8 support.

f1mishutka commented 5 years ago

I've managed to run complicated Drupal 6 site on MySQL 8.0.15 and PHP 7.3 using this patch.

So it seems to be ready to be merged for everyone.

P.S.: I'm new to GitHub workflows so I'll be thankful if someone will review my changes. There are not to much of them. Thanks.

dsnopek commented 5 years ago

Thanks for the PR! I've put some comments on the changes.

dsnopek commented 5 years ago

Thinking about this a little more: adding backticks is MySQL specific, so we'll need to make sure we're somehow adding the right marker for identifiers. In ANSI SQL, it's a double quote, and I actually have no idea what it is for Postgres, only that it's different than MySQL. :-)

Looking at how Drupal 8 is approaching this problem, this issue is proposing adding a new syntax with square brackets that'll be converted to the right identifier marker for the database:

https://www.drupal.org/project/drupal/issues/2986452

I don't think that necessarily makes sense for Drupal 6, but just to point out that this is a kind of unsolved problem even for Drupal 8.

f1mishutka commented 5 years ago

Thank you David!

Will review your note in a couple days and make required changes.

f1mishutka commented 5 years ago

David, I've replied to all your notes. All required changes made to source code. Please let me know if you have any other thoughts on this.

Thank you!

dsnopek commented 5 years ago

Thanks!

I think the main remaining thing here is that backticks are a MySQL-specific thing, and we'd need to make sure that any code that'll run for any database (ex. drupal_write_record(), db_prefix_tables(), etc) use the right method to escape column names for the database that's in use.

f1mishutka commented 5 years ago

I think the main remaining thing here is that backticks are a MySQL-specific thing, and we'd need to make sure that any code that'll run for any database (ex. drupal_write_record(), db_prefix_tables(), etc) use the right method to escape column names for the database that's in use.

Both this methods check MySQL version before table names escaping. So there will no backticks added for MySQL 5.7 or any version of Postgres.

dsnopek commented 5 years ago

Ah, ok, great! Somehow I didn't notice that when I was looking at the diff before, but I see it now. :-) I'll try to do some testing of this when I get a chance. Thanks!

f1mishutka commented 5 years ago

Thank you, David!

Please let me know if you have any other thoughts or suggestions.

f1mishutka commented 5 years ago

Just merged changes from 6.50 version.

Any chances to merge this pull request to original repository? :)

dsnopek commented 5 years ago

Yes, I'd really like to merge this! I just need to find some time to properly test it. Hopefully, I'll get to it soon!

f1mishutka commented 5 years ago

Thank you, David.

Please let me know if I can help you somehow with testing.

P.S.: I use d6lts with this patch to run D6-based website of local cycling community( >6k users, >16k nodes). And it works fine since beginning of March 2019 on MySQL 8.0 and PHP 7.3. Performance increased at least twice comparing to MySQl 5.7 + PHP 5.3. Really happy about this migration! :)

dsnopek commented 5 years ago

I did a whole bunch of testing and review today! I also pushed some additional commits.

Here's the highlights of the code changes:

I tested with CCK, Views and Webform. I didn't do very extensive tests with those modules, I just poked around and made some example content, views, forms, etc. It all seems to be working!

f1mishutka commented 5 years ago

David,

Thank you for great job done!

f1mishutka commented 5 years ago

David, I looked through all your commits: every change seems reasonable. So one more time thank you for you time!

Switched https://veloby.net (cycling community website I mentioned) to d6lts:6.x brach. Everything seems to work fine, and I consider this as "extensive tests" under real load :)

neubreed commented 4 years ago

Thanks for working on this! In my case I have multiple database connections so $db_url can be an array to define multiple database connections

So I amended db_is_version() to get the 'default' db url

function db_is_version($driver, $version, $operator = '>=') {
  global $db_url;

  $default_db_url = is_array($db_url) ? $db_url['default'] : $db_url;

  if(substr($default_db_url, 0, strlen($driver) ) === $driver) {
    if(version_compare(db_version(), $version, $operator)) {
      return true;
    }
  }

  return false;
}
f1mishutka commented 4 years ago

Hi @neubreed ,

Thank you for feedback!

So I amended db_is_version() to get the 'default' db url

This function was renamed to db_version_compare() and there is already check for an array in it. So as I see it should work properly with multiple connections specified.

neubreed commented 4 years ago

Hi @f1mishutka

Thanks for getting back to me .. initially I only patched just this file in my Drupal 6 install .. once I replaced my core with the full d6lts it works great.

Thanks a lot.