function devel_query_table in Devel 7
Same name and namespace in other branches
- 5 devel.module \devel_query_table()
- 6 devel.module \devel_query_table()
Shows all the queries for the page.
Adds a table at the bottom of the page cataloguing data on all the database queries that were made to generate the page.
Return value
string Queries themed using devel_querylog.
1 call to devel_query_table()
- devel_shutdown_query in ./
devel.module - Returns the rendered query log.
File
- ./
devel.module, line 1681 - This module holds functions useful for Drupal development.
Code
function devel_query_table($queries, $counts) {
$version = devel_get_core_version(VERSION);
$header = array(
'ms',
'#',
'where',
'ops',
'query',
'target',
);
$i = 0;
$api = variable_get('devel_api_url', 'api.drupal.org');
$conn = Database::getconnection();
foreach ($queries as $query) {
$function = !empty($query['caller']['class']) ? $query['caller']['class'] . '::' : '';
$function .= $query['caller']['function'];
$count = isset($counts[$query['query']]) ? $counts[$query['query']] : 0;
$diff = round($query['time'] * 1000, 2);
if ($diff > variable_get('devel_execution', 5)) {
$cell[$i][] = array(
'data' => $diff,
'class' => 'marker',
);
}
else {
$cell[$i][] = $diff;
}
$cell[$i][] = $count;
$cell[$i][] = l($function, "http://{$api}/api/function/{$function}/{$version}");
$ops[] = l(t('P'), '', array(
'attributes' => array(
'title' => 'Show placeholders',
'class' => array(
'dev-placeholders',
),
'qid' => $i,
),
));
$ops[] = l(t('A'), '', array(
'attributes' => array(
'title' => 'Show arguments',
'class' => array(
'dev-arguments',
),
'qid' => $i,
),
));
// EXPLAIN only valid for select queries.
if (strpos($query['query'], 'UPDATE') === FALSE && strpos($query['query'], 'INSERT') === FALSE && strpos($query['query'], 'DELETE') === FALSE) {
$ops[] = l(t('E'), '', array(
'attributes' => array(
'title' => 'Show EXPLAIN',
'class' => array(
'dev-explain',
),
'qid' => $i,
),
));
}
$cell[$i][] = implode(' ', $ops);
// 3 divs for each variation of the query. Last 2 are hidden by default.
if (variable_get('devel_show_query_args_first', FALSE)) {
$placeholders = '<div class="dev-placeholders" style="display: none;">' . check_plain($query['query']) . "</div>\n";
$quoted = array();
foreach ($query['args'] as $key => $val) {
$quoted[$key] = $conn
->quote($val);
}
$output = strtr($query['query'], $quoted);
$args = '<div class="dev-arguments">' . $output . '</div>' . "\n";
}
else {
$placeholders = '<div class="dev-placeholders">' . check_plain($query['query']) . "</div>\n";
$args = '<div class="dev-arguments" style="display: none;"></div>' . "\n";
}
$explain = '<div class="dev-explain" style="display: none;"></div>' . "\n";
$cell[$i][] = array(
'id' => "devel-query-{$i}",
'data' => $placeholders . $args . $explain,
);
$cell[$i][] = $query['target'];
$i++;
unset($diff, $count, $ops);
}
if (variable_get('devel_query_sort', DEVEL_QUERY_SORT_BY_SOURCE)) {
usort($cell, '_devel_table_sort');
}
return theme('devel_querylog', array(
'header' => $header,
'rows' => $cell,
));
}