function dpq in Devel 8.2
Same name and namespace in other branches
- 8.3 devel.module \dpq()
- 8 devel.module \dpq()
- 7 devel.module \dpq()
- 4.x devel.module \dpq()
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()
- devel_query_debug_alter in ./devel.module 
- Implements hook_query_TAG_alter().
File
- ./devel.module, line 541 
- This module holds functions useful for Drupal development.
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 = [];
    $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;
}