function dpq
Same name in other branches
- 7.x-1.x devel.module \dpq()
- 8.x-1.x 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.
bool $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().
1 string reference to 'dpq'
- DevelDumperBase::getInternalFunctions in src/
DevelDumperBase.php - Returns a list of internal functions.
File
-
./
devel.module, line 582
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 = [];
$database = Drupal::database();
foreach ((array) $query->arguments() as $key => $val) {
$quoted[$key] = is_null($val) ? 'NULL' : $database->quote($val);
}
$sql = strtr($sql, $quoted);
if ($return) {
return $sql;
}
Drupal::service('devel.dumper')->message(input: $sql, name: $name);
}
return $return ? NULL : $query;
}