function dpq
Same name in other branches
- 7.x-1.x devel.module \dpq()
- 4.x devel.module \dpq()
- 5.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 460
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;
}