'SHOW TABLES'(used in function createTempTables) is a MySQLism, which is crashing PostgreSQL sites

Created on 5 December 2021, almost 3 years ago
Updated 29 March 2023, over 1 year ago

Problem/Motivation

After creating a new Drupal 8.9 site, and adding Cleantalk, I find that the site is WSODing with the error:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "::" LINE 1: SHOW TABLES::text LIKE 'cleantalk_sfw' ^: SHOW TABLES LIKE 'cleantalk_sfw'; Array ( ) in Cleantalk\ApbctDrupal\DB->fetch() (line 62 of /home/accdesign/public_html/web/modules/contrib/cleantalk/src/lib/Cleantalk/ApbctDrupal/DB.php)
#0 /home/accdesign/public_html/web/core/lib/Drupal/Core/Database/Connection.php(665): Drupal\Core\Database\Connection->handleQueryException()
#1 /home/accdesign/public_html/web/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php(202): Drupal\Core\Database\Connection->query()
#2 /home/accdesign/public_html/web/modules/contrib/cleantalk/src/lib/Cleantalk/ApbctDrupal/DB.php(62): Drupal\Core\Database\Driver\pgsql\Connection->query()
#3 /home/accdesign/public_html/web/modules/contrib/cleantalk/src/lib/Cleantalk/Common/Firewall/FirewallUpdater.php(379): Cleantalk\ApbctDrupal\DB->fetch()
#4 /home/accdesign/public_html/web/modules/contrib/cleantalk/src/lib/Cleantalk/Common/Firewall/FirewallUpdater.php(131): Cleantalk\Common\Firewall\FirewallUpdater->createTempTables()
#5 /home/accdesign/public_html/web/modules/contrib/cleantalk/src/CleantalkFuncs.php(675): Cleantalk\Common\Firewall\FirewallUpdater->update()
#6 /home/accdesign/public_html/web/modules/contrib/cleantalk/src/lib/Cleantalk/ApbctDrupal/RemoteCalls.php(13): Drupal\cleantalk\CleantalkFuncs::apbct_sfw_update()
#7 /home/accdesign/public_html/web/modules/contrib/cleantalk/src/lib/Cleantalk/Common/RemoteCalls.php(110): Cleantalk\ApbctDrupal\RemoteCalls->action__sfw_update()
#8 /home/accdesign/public_html/web/modules/contrib/cleantalk/src/EventSubscriber/BootSubscriber.php(136): Cleantalk\Common\RemoteCalls->perform()
#9 /home/accdesign/public_html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\cleantalk\EventSubscriber\BootSubscriber->handle()
#10 /home/accdesign/public_html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#11 /home/accdesign/public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#12 /home/accdesign/public_html/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#13 /home/accdesign/public_html/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#14 {main}
.

I had reported a similar error awhile back, but didn't realize the real problem: 'SHOW TABLES' is a MYSQLism that isn't supported in PostgreSQL. To do the equivalent in PostgreSQL, you have to do a query against pg_catalog.pg_tables. See, for instance https://www.postgresqltutorial.com/postgresql-show-tables/ under the title "PostgreSQL show tables using pg_catalog schema"

Steps to reproduce

Install Cleantalk on a Drupal 8 or 9 site using PostgreSQL

Proposed resolution

The code needs to be changed to detect the use of PostgreSQL, and use an appropriate query against pg_catalog.pg_tables to test for the existence a table.

Workaround

Turn off SFW

Patch forthcoming

I can try to work up a patch on this in the next few days. If you'd rather handle it yourself, and don't have a PostgreSQL setup to test on, I'd be glad to test whatever you come up with.

πŸ› Bug report
Status

Needs review

Version

9.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Ben Coleman

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024