Is there a method to make Devel initially show real arguments in query log instead of placeholders? This can be achieved for a single query in the log by clicking on the letter "A" in "ops" column in the query log. But e.g. to find all queries that refer to a specific node, or specific language, it is necessary to search for a particular nid, e.g. '184', or language value 'en', and it is not possible with placeholders. Theoreticaly someone may click 200 times on letter "A" on a single page and have all queries diaplay their real arguments, but perhaps there is any method to do it more efficiently?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

raincloud’s picture

Title: Devel: Show real arguments instead of placeholders in query log » Show real arguments instead of placeholders in query log

During search I found a Views issue with similar title, but this is definitely Views issue because the suggested patch refers to Views module and not to Devel. But maybe they have something in common. Anyway, I need this for non-views pages.

raincloud’s picture

Title: Show real arguments instead of placeholders in query log » Devel: Show real arguments instead of placeholders in query log
moshe weitzman’s picture

Title: Show real arguments instead of placeholders in query log » Devel: Show real arguments instead of placeholders in query log
Category: support » feature

Not currently possible. Could be done via a greasemonkey script if you didn't want to submit it as a patch. I chose current default because it is much more compact.

raincloud’s picture

No problem if it will work. Do you know any such particular existing script, a link maybe?

Ilya1st’s picture

Hmmm.
I look at drupal core code on how queries work there.

http://api.drupal.org/api/drupal/includes--database--database.inc/functi...
using that you can replace placeholders with arguments(of course if you have access to them there)

So why they are not replaced before make output? No access to arguments when devel makes it's work?

moshe weitzman’s picture

"I chose current default because the display is much more compact."

KingMoore’s picture

If you can click "A" and it works, why can't it be done by default? At first I thought it was not possible with Devel using the new DB API... but obviously it is possible because when I click "A" it shows it. This absolutely should be the default behavior.

moshe weitzman’s picture

Status: Active » Closed (works as designed)

Please read my earlier answers.

simanta’s picture

Issue summary: View changes

Hope this will help someone. The snippet is already tested with Drupal v7.26+Devel v7.x-1.4

1. Add below line before hook_help()

define('DEVEL_DEFAULT_QUERY_STYLE', 'A'); // Possible values P => Placeholders, A => Arguments

/**
 * Implements hook_help().
 */

2. Replace the below code snippets as shown here -
2A From

$header = array('ms', '#', 'where', 'ops', 'query', 'target');
$i = 0;
$api = variable_get('devel_api_url', 'api.drupal.org');
foreach ($queries as $query) {

To

$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) {

AND

2B. From

// 3 divs for each variation of the query. Last 2 are hidden by default.
$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";

To

// 3 divs for each variation of the query. Last 2 are hidden by default.
if (DEVEL_DEFAULT_QUERY_STYLE == 'A') {
$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";

Please note that the above changes need to be done on the devel.module file. Let me know in case of any further clarification.

greggles’s picture

Here's a patch version of #9.

I also changed from a constant to a variable. Things that are likely to change should be in variables instead of constants.

moshe weitzman’s picture

I dunno how realistic it is to run with this default over a long term. Your pages will routinely get miles long with huge Drupal queries.

greggles’s picture

My experience is that with the query log on the page is already miles long and this doesn't make it significantly different. But...that's why its a variable instead of being hard-coded.

aangel’s picture

This is really nice to work with...thank you simanta and greggles!

rivimey’s picture

Can I just say that the 'patch' in #9 was very useful. Would be good to include some version of it in the main branch. I agree with Moshe's comment in #11 to the extent that placeholder should be the default, but that's easy to arrange.

greggles’s picture

Status: Closed (works as designed) » Needs review

Perhaps we should reopen this?

rivimey’s picture

@greggles, I think it would be useful to have as an enable-able option under devel's config settings.

joachim’s picture

Patch works great.

Here's an updated version which adds a setting to the Devel admin form.

moshe weitzman’s picture

Status: Needs review » Closed (won't fix)

Query log feature is moving to webprofiler module for D8. We won't be adding features to it in prior versions.

rivimey’s picture

Moshe: "We won't be adding features to it in prior versions." :-(

Could we not have this in D7 -- it's no like D7 is dead yet?

pbcelery’s picture

+bump. Great tweak.

salvis’s picture

Status: Closed (won't fix) » Needs review

Technically, 7.x is not a prior version but the last version.

Seeing that we have a popular working patch, maybe we can make an exception here? Moshe?

I know you don't like adding options, but the case for this one (in the OP) is pretty convincing.

moshe weitzman’s picture

If @salvis want to maintain this in D7 then I'm fine with him merging it.

  • salvis committed 62d53dd on 7.x-1.x
    Issue #1190074 by simanta, greggles, joachim: Show real arguments...
salvis’s picture

Status: Needs review » Fixed

Thanks, Moshe, and all who have helped with this.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Marko B’s picture

There is also another problem, for example, eve if you have placeholders filled, queries from VIEWS are not complete. If you look below "field_data_field_last_name_user_entity_type" fields are fields from user fields and they lack relationship in this query. Some joins of tables. But this is what you get in develop, this is also what you get in views sql output, so some changes to query must occur somewhere later?

SELECT users.uid AS uid, users.created AS users_created, users.language AS users_language, users.mail AS users_mail, 'user' AS field_data_field_first_name_user_entity_type, 'user' AS field_data_field_last_name_user_entity_type, 'user' AS field_data_field_date_of_birth_user_entity_type
FROM 
{users} users
WHERE (( (users.status <> '0') AND (users.created > 1441641600) ))
ORDER BY users_created DESC
LIMIT 50 OFFSET 0