Is it possible to display the actual values rather than the placeholders in views query output when "Show information and statistics about the view during live preview" and "Show the SQL query" checkboxes and enabled?

The devel module query viewer allows you to toggle between placeholders and values on-the-fly via javascript. This would be nice to have in Views, or at least a checkbox with "Show the SQL query" that reads "Show actual values instead of placeholders in the SQL query".

This might be a feature request, but please let me know if I'm just completely missing something.

Comments

dawehner’s picture

Category: support » feature

This would be indeed a feature request and afaik this would require quite an amount of changes in the code.

mstrelan’s picture

I agreed and accept that the javascript part would be difficult, however I just had a quick search through the code and it actually looks like this feature is meant to exist (without the toggle).

views/includes/admin.inc (around line 203)
$rows['query'][] = array('<strong>' . t('Query') . '</strong>', '<pre>' . check_plain(strtr($query, $quoted)) . '</pre>');
$query is the sql with placeholders
$quoted is an array of replacements from the database layer

Further up the code (around line 191) the query arguments that views takes care of are stored in a variable $arguments however this variable is not used again.

Change line 203 to the following and it will work.
$rows['query'][] = array('<strong>' . t('Query') . '</strong>', '<pre>' . check_plain(strtr($query, array_merge($quoted, $arguments))) . '</pre>');

Happy to create a patch if you need, just in a rush right now. I could probably also make it a setting on the advanced settings page.

mstrelan’s picture

Title: Show or toggle between argument values instead of placeholders in views query output » Show argument values instead of placeholders in views query output
Component: User interface » Code
Category: feature » bug
Status: Active » Needs review
StatusFileSize
new916 bytes

I've changed my perspective slightly on this. It would seem to me that placeholders such as :views_join_condition_0 are pretty meaningless here and it is probably not likely that you would need to toggle between them. It is also a regression as I don't believe we had this in 6.x-2.x. Patch attached.

merlinofchaos’s picture

Status: Needs review » Fixed

Shockingly easy.

mototribe’s picture

subscribe

mstrelan’s picture

@mototribe - Just go download 7.x-3.0-rc1, the patch is committed there.

mstrelan’s picture

Status: Fixed » Needs review
StatusFileSize
new1022 bytes

What's the difference between $query->arguments() and $query->getArguments()? This issue isn't quite resolved for some use cases. An example is if you have a node reference as an argument the query output prints entity_type = node rather than entity_type = 'node'.

A more detailed output
LEFT JOIN {field_data_field_exhibition} field_data_field_exhibition ON node.nid = field_data_field_exhibition.entity_id AND (field_data_field_exhibition.entity_type = node AND field_data_field_exhibition.deleted = 0)

I've attached a patch that will call $connection->quote() on ALL of the arguments, but I'm not sure if there is a reason this was not already done.

mstrelan’s picture

This one is probably better.

mstrelan’s picture

Another use case that has the issue described in #7 is when you have a filter criteria of a taxonomy term in a particular vocabulary.

The query output is:

LEFT JOIN (SELECT td.*, tn.nid AS nid
FROM 
{taxonomy_term_data} td
LEFT JOIN {taxonomy_vocabulary} tv ON td.vid = tv.vid
LEFT JOIN {taxonomy_index} tn ON tn.tid = td.tid
WHERE  (tv.machine_name IN  (my_vocabulary)) ) taxonomy_term_data_node ON node.nid = taxonomy_term_data_node.nid

my_vocabulary needs quotes around it. The patch in #8 also resolves this issue.

dawehner’s picture

Status: Needs review » Fixed

Oh this seemed to be a duplicate of #1185914: Missed quotes in SQL query visualisation but the patch got commited.

Status: Fixed » Closed (fixed)

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