function dpq in Devel 7
Same name and namespace in other branches
- 8.3 devel.module \dpq()
- 8 devel.module \dpq()
- 8.2 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 SelectQueryInterface interface.
string $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() for the devel tag.
File
- ./
devel.module, line 1916 - This module holds functions useful for Drupal development.
Code
function dpq($query, $return = FALSE, $name = NULL) {
if (user_access('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] = $connection
->quote($val);
}
$sql = strtr($sql, $quoted);
if ($return) {
return $sql;
}
dpm($sql, $name);
}
return $return ? NULL : $query;
}