2

One of drupal view displays reviews based on a selected event. It should display 3 reviews but instead it displays only 2. It doesn't happen for all the events and only for certain events instead of 3 it displays 2 items. As the data is all correct and I have validated the same. I wanted to see the query that is being used. The query that is displayed in the view is not helping me either. If I copy paste the same and run the sql, it throws a lot of error. How can I debug and see what is the query that got executed for that particular view? The view has relationsships and also it uses contextual filters. Thanks

1
  • What errors you are referring to when you execute the query given by the Views UI? If you post a sample of a query, someone could probably explain.
    – cilefen
    May 7, 2016 at 0:48

3 Answers 3

5

The query displayed in the administration UI contains database prefixing brackets. You can remove those brackets to have valid SQL that can be executed by any SQL client.

2
  • Yes I tried removing those {} brackets but still its not working.There are few lines like 'field_collection_item' AS field_data_field_art_id_field_collection_item_entity_type, 'node' AS field_data_field_magazine_published_date_node_entity_type, 'node' AS field_data_field_book_review_synopsis_node_entity_type. How does sql interprets it?
    – Srividhya
    May 9, 2016 at 16:27
  • Aliasing ("column AS alias") is valid SQL syntax. Without knowing the SQL client error, it's hard to know what it doesn't like about the query.
    – Shawn Conn
    May 10, 2016 at 3:43
3

The Devel module has a setting that will show all executed queries in the footer.

1
  • 1
    Yeah, but it keeps the data placeholders. I want to actually see the real query. Mar 8, 2017 at 20:00
0

You have to use hook_views_pre_execute and with Devel installed use dpq to view the SQL String:

function hook_views_pre_execute(&$view) {
  dpq($view->build_info['query']);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.