After updating Drupal 7 core from 7.74 to 7.77 my website no longer works.
It seems to be an error with MySQL executed on line 174 of view_custom_table.module.

clearing the cash using drush results in the following message:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `mytablename` mytablename LIMIT 50 OFFSET 0' at line 1

WD menu: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ' mytablename ': DESCRIBE { mytablename }; Array [error]
(
)
in view_custom_table_views_data() (line 174 of /var/www/webroot/ROOT/sites/all/modules/view_custom_table/view_custom_table.module).
Invalid argument supplied for foreach() views.module:155

When I disable the module the site works.
When I empty table custom_table_view_data the site also works with the module enabled.
When I add a new custom tabel the site gives an error after displaying this message on screen: Add columns relationship for [tablename]
It looks like information in column 'column_relations' is not correct. It is filled with: a:0:{}
How can this be fixed?

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

LiqueFactive created an issue. See original summary.

eric wassink - qumup’s picture

Issue summary: View changes
sirish.ayyagari’s picture

i am having same issue with views_custom_table, not sure why $query = format_string('DESCRIBE { @table_name }', array('@table_name' => $custom_table->table_name)); is failing in views_custom_table.module

sirish.ayyagari’s picture

Fix::::
$conf['mysql_identifier_quote_character'] = '';

adding this line to settings.php solved the problem

sirish.ayyagari’s picture

Fixed!!!

$conf['mysql_identifier_quote_character'] = '';

adding this line to settings.php solved the problem

ckng’s picture

Status: Active » Needs review

Solution #4 is working.

avpaderno’s picture

Version: 7.x-1.0-rc1 » 7.x-1.x-dev
Status: Needs review » Active
alexh’s picture

Thank you, I can also confirm that solution #4 is working.

eric wassink - qumup’s picture

Thanks for this simple solution (#4).

oldspot made their first commit to this issue’s fork.

oldspot’s picture

Status: Active » Needs review

That solution seemed more like a workaround rather than fixing the actual problem, especially when it involves updating such an important constant.

I've debugged the issue a bit and seems like the error is happening due to the blank spaces before and after the "@table_name" - it looks like it's literally looking for the table name including the spaces which is why it can't find it.

Looking at all other examples of code in core and the db_query documentation the spaces before or after the table name are not needed so I've created a PR for it and works fine for me.

avpaderno’s picture

Title: Adding custom tabel results in break down website » Adding custom table results in break down website
oknaru’s picture

#12 works for me perfect.
Remove space before & after the table_name line 173 'DESCRIBE {@table_name}'

mkrizaj’s picture

I've created a patch for the issue raised above.

khurrami’s picture

#12 works for me perfect.
Thanks

avpaderno’s picture

Status: Needs review » Needs work

The patch needs to be created from the directory containing the module.

oldspot’s picture

I've update my Merge Request to include the extra occurrence of blank space found by @mkrizaj

As per the new gitlab merge requests documentation - https://www.drupal.org/drupalorg/docs/gitlab-integration/issue-forks-mer... - you can get the patch by appending ".patch" to the merge request url rather than creating new patch files:
https://git.drupalcode.org/project/view_custom_table/-/merge_requests/1....

oldspot’s picture

Status: Needs work » Needs review

Updating to 'Needs review' as added the extra fix but the rest of it has been confirmed as working by a few above so could go to RTBC soon.

alexh’s picture

Thanks oldspot and mkrizaj. This is certainly the better solution and it works.

tenamurphy’s picture

view_custom_table-blank-spaces-3186756-15.patch works perfectly for me. Thanks!!!!

oldspot’s picture

Status: Needs review » Reviewed & tested by the community

I've just stumbled into the same issue again when adding another custom table to views and can confirm the last fix added to the patch from @mkrizaj works well:
https://git.drupalcode.org/project/view_custom_table/-/merge_requests/1....

Changing to RTBC so it can be committed soon hopefully as I've just discovered a duplicate issue to this one which has the exact same solution:
https://www.drupal.org/project/view_custom_table/issues/3069124

promo-il’s picture

Error on update Drupal 7.72 to 7.81. Patch #15 is OK

joseph.olstad’s picture

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
+  $text_query = format_string('DESCRIBE {@table_name}', array('@table_name' => $table_name));

The correct code would be the following one.

$text_query = 'DESCRIBE {' . db_escape_table($table_name) . '}';

See the code in DrupalDatabaseCache::getMultiple().

joseph.olstad’s picture

New release for Drupal 7 , version 7.x-1.0

download version 7.x-1.0

joseph.olstad’s picture

StatusFileSize
new1.67 KB
joseph.olstad’s picture

Status: Needs work » Needs review

patch is against 7.x-1.6

joseph.olstad’s picture

Status: Needs review » Fixed

new release shortly

joseph.olstad’s picture

here's the new release, enjoy and thanks everyone! Too bad we had to wait this long to get a maintainer.

https://www.drupal.org/project/view_custom_table/releases/7.x-1.1

Status: Fixed » Closed (fixed)

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