SQL syntax error in Field check when run on PostgreSQL

Created on 12 September 2023, about 1 year ago
Updated 9 November 2023, about 1 year ago

Problem/Motivation

In πŸ› Field check out of memory Fixed , the dynamic database query in the Field check was rewritten as a constructed static query like so:

$query = $this->database()->query("SELECT `$id`, `$column_name` FROM {$table} t");

Unfortunately, this syntax is invalid if the site is using PostgreSQL for its database and generates the following error:

SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near ","
LINE 1: SELECT `entity_id`, `body_value` FROM block_content__body t
^: SELECT `entity_id`, `body_value` FROM block_content__body t; Array
(
)
in Drupal\security_review\Checks\Field->run() (line 107 of modules/contrib/security_review/src/Checks/Field.php).

Steps to reproduce

  1. Set up a site that uses PostgreSQL and install Drupal. (If using ddev, run ddev config --database=postgres:14 to switch the database.)
  2. Install security_review module.
  3. Log in as admin.
  4. Go to /admin/reports/security-review and click Run > Run checklist.

Proposed resolution

Revert to constructing the query dynamically so the database abstraction layer handles the syntax correctly, but do it in a way that doesn't reintroduce the memory problem in the original issue. The fix should still be able to pass the test procedure proposed in #3221065-10: Field check out of memory β†’ .

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States muriqui

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

Comments & Activities

Production build 0.71.5 2024