Problem/Motivation

Receiving error: Notice: Trying to get property of non-object in optimizedb_admin( ) (line 217 of sites/all/modules/contrib/optimizedb/optimizeddb.module). How to fix this?

CommentFileSizeAuthor
#3 3186413-3.patch758 bytesmcdruid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rczurek created an issue. See original summary.

mcdruid’s picture

This is a little tricky.

The MySQL query in question is:

  switch (db_driver()) {
    case 'mysql':
      $table_length = db_query("SHOW TABLE STATUS LIKE '{cache_form}';")->fetchObject();

Because quoting of table names was introduced in 7.76 to support MySQL 8, this will be replaced with something like:

SHOW TABLE STATUS LIKE '`cache_form`';

That means the table name won't match and db_query returns FALSE.

Doing quoting of table names via the replacement of curly braces for table prefixing is a bit of a hack, but was the least bad solution to retrofit MySQL 8 support into D7.

We had to remove the quoting of table names in at least one place for schema queries, which is quite a similar situation to this:

https://git.drupalcode.org/project/drupal/-/blob/7.77/includes/database/...

It may be possible to rewrite this query such that it doesn't use the curly braces and therefore isn't affected by the table name quoting.

One simple solution might be to remove the curly braces and take advantage of the fact that it's a LIKE pattern e.g.:

      $table_length = db_query("SHOW TABLE STATUS LIKE '%cache_form';")->fetchObject();

That'd probably work in many cases including where there's a prefix on the table name. However, it might cause problems if there are a multiple sites using prefixes to share the same database.

You might be able to do something pragmatic like use the database API to prefix the table name, but then remove any quotes before passing the pattern to this query. I've not looked at how that would work in any depth though.

I wouldn't be surprised if there are other queries in this module that might be affected in a similar way.

A workaround for any affected sites that don't need the table name quoting (e.g. they're on earlier versions of MySQL) is to set this variable to an empty string which disables identifier quoting and should thus avoid this issue:

$conf['mysql_identifier_quote_character'] = '';
mcdruid’s picture

Status: Active » Needs review
FileSize
758 bytes

This is quite ugly, but it works AFAICS.

There may be a more elegant way to do this via the existing db api, or perhaps we need to add a way of accessing prefixed but unquoted table names.

rczurek’s picture

Mcdruid: This is way too complex for me. I will wait for the Database Optimization module update. I have disabled and removed the module for now and the errors disappeared as I expected. Should we notify the maintainer?

sergeypavlenko’s picture

Hi, all

I’m watching on this issue. Soon I will check patch.

rczurek’s picture

Thank you sergeypavlenko!

rayjames’s picture

Hi, I too have this same issue after updating to Drupal 7.77. Waiting for official update to module as well. Thanks for your time and help on this. Much appreciated.

sergeypavlenko’s picture

Status: Needs review » Fixed

Hi

@mcdruid, thanks for the patch! I not found other fast way for fix this problem. Now you patch is best way. Thanks! Pushed to dev version.

For me strange, in drupal 7.77 formed problem with prefixes, and not proposed simple variants for working modules.

Created new release 7.x-1.7.

sergeypavlenko’s picture

Status: Fixed » Closed (fixed)
rczurek’s picture

Thank you to all involved!

rayjames’s picture

Thanks everyone. Fast response, good fix. You rock! Much appreciated!