Show an SQL raw query

Public

The magic

Get raw version
php
  1. <?php
  2.  
  3. function MYMODULE_query_alter($query) {
  4. if ($query->hasTag('debug')) {
  5. $sql = (string)$query;
  6. $connection = Database::getConnection();
  7. foreach ((array) $query->arguments() as $key => $val) {
  8. $quoted[$key] = $connection->quote($val);
  9. }
  10. $sql = strtr($sql, $quoted);
  11. dpm($sql);
  12. }
  13. }

Don't forget this addTag

Get raw version
php
  1. <?php
  2.  
  3. $query = new EntityFieldQuery();
  4. $query
  5. ->entityCondition('entity_type', 'node')
  6. // ->entityCondition('bundle', 'node')
  7. ->fieldCondition($field, 'target_id', $entities_id, 'IN')
  8. ->addTag('debug') // HERE THE MAGIC
  9. ;

Comments

benftwc's picture

Hi.

In fact, i've seen that DPQ don't fully work. I've some result with joins hidden, and I prefer add a single method instead of using another function to debug my obj