8.x-1.x devel.module dpq($query, $return = FALSE, $name = NULL)
7.x-1.x devel.module dpq($query, $return = FALSE, $name = NULL)

Prints a SQL string from a DBTNG Select object. Includes quoted arguments.

Parameters

object $query: An object that implements the SelectInterface interface.

boolean $return: Whether to return the string. Default is FALSE, meaning to print it and return $query instead.

string $name: Optional name for identifying the output.

Return value

object|string The $query object, or the query string if $return was TRUE.

1 call to dpq()

File

./devel.module, line 446
This module holds functions useful for Drupal development. Please contribute!

Code

function dpq($query, $return = FALSE, $name = NULL) {
  if (\Drupal::currentUser()->hasPermission('access devel information')) {
    if (method_exists($query, 'preExecute')) {
      $query->preExecute();
    }
    $sql = (string) $query;
    $quoted = array(
      
    );
    $connection = Database::getConnection();
    foreach ((array) $query->arguments() as $key => $val) {
      $quoted[$key] = is_null($val) ? 'NULL' : $connection->quote($val);
    }
    $sql = strtr($sql, $quoted);
    if ($return) {
      return $sql;
    }
    dpm($sql, $name);
  }
  return $return ? NULL : $query;
}