You are here

public function LoggedStatementsTrait::query in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/database_statement_monitoring_test/src/LoggedStatementsTrait.php \Drupal\database_statement_monitoring_test\LoggedStatementsTrait::query()
  2. 9 core/modules/system/tests/modules/database_statement_monitoring_test/src/LoggedStatementsTrait.php \Drupal\database_statement_monitoring_test\LoggedStatementsTrait::query()

File

core/modules/system/tests/modules/database_statement_monitoring_test/src/LoggedStatementsTrait.php, line 20

Class

LoggedStatementsTrait
Trait for Connection classes that can store logged statements.

Namespace

Drupal\database_statement_monitoring_test

Code

public function query($query, array $args = [], $options = []) {

  // Log the query if it is a string, can receive statement objects e.g
  // in the pgsql driver. These are hard to log as the table name has already
  // been replaced.
  if (is_string($query)) {
    $stringified_args = array_map(function ($v) {
      return is_array($v) ? implode(',', $v) : $v;
    }, $args);
    $this->loggedStatements[] = str_replace(array_keys($stringified_args), array_values($stringified_args), $query);
  }
  return parent::query($query, $args, $options);
}