diff --git a/includes/admin.inc b/includes/admin.inc
index 40c9f18..122beb2 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -188,21 +188,8 @@ function views_ui_preview($view, $display_id, $args = array()) {
         if ($show_query) {
           $query = $view->build_info['query'];
           // Only the sql default class has a method getArguments.
-          $quoted = array();
-
-          if (get_class($view->query) == 'views_plugin_query_default') {
-            $quoted = $query->getArguments();
-            $connection = Database::getConnection();
-            foreach ($quoted as $key => $val) {
-              if (is_array($val)) {
-                $quoted[$key] = implode(', ', array_map(array($connection, 'quote'), $val));
-              }
-              else {
-                $quoted[$key] = $connection->quote($val);
-              }
-            }
-          }
-          $rows['query'][] = array('<strong>' . t('Query') . '</strong>', '<pre>' . check_plain(strtr($query, $quoted)) . '</pre>');
+          $query_string = $query->query_preview($view);
+          $rows['query'][] = array('<strong>' . t('Query') . '</strong>', '<pre>' . check_plain($query_string) . '</pre>');
           if (!empty($view->additional_queries)) {
             $queries = '<strong>' . t('These queries were run during view rendering:') . '</strong>';
             foreach ($view->additional_queries as $query) {
diff --git a/plugins/views_plugin_query.inc b/plugins/views_plugin_query.inc
index d39ed98..3d029a9 100644
--- a/plugins/views_plugin_query.inc
+++ b/plugins/views_plugin_query.inc
@@ -43,6 +43,19 @@ class views_plugin_query extends views_plugin {
   function query($get_count = FALSE) { }
 
   /**
+   * Return a string of the query to be shown in the ui/logging.
+   *
+   * @param view $view
+   *   The view which got built.
+   *
+   * @return string
+   *   The php string of the query.
+   */
+  function query_preview($view) {
+    return isset($view->build_info['query']) ? $view->build_info['query'] : '';
+  }
+
+  /**
    * Let modules modify the query just prior to finalizing it.
    *
    * @param view $view
diff --git a/plugins/views_plugin_query_default.inc b/plugins/views_plugin_query_default.inc
index 7e8900d..0b4e654 100644
--- a/plugins/views_plugin_query_default.inc
+++ b/plugins/views_plugin_query_default.inc
@@ -1356,7 +1356,23 @@ class views_plugin_query_default extends views_plugin_query {
     return $query;
   }
 
-  /**
+  function query_preview($view) {
+    $query = $view->build_info['query'];
+    $quoted = $query->getArguments();
+    $connection = Database::getConnection();
+    foreach ($quoted as $key => $val) {
+      if (is_array($val)) {
+        $quoted[$key] = implode(', ', array_map(array($connection, 'quote'), $val));
+      }
+      else {
+        $quoted[$key] = $connection->quote($val);
+      }
+    }
+    return (string) strtr($query, $quoted);
+  }
+
+
+/**
    * Get the arguments attached to the WHERE and HAVING clauses of this query.
    */
   function get_where_args() {
diff --git a/tests/views_query.test b/tests/views_query.test
index f44306a..c209bec 100644
--- a/tests/views_query.test
+++ b/tests/views_query.test
@@ -119,7 +119,8 @@ abstract class ViewsTestCase extends DrupalWebTestCase {
     $view->set_display();
     $view->pre_execute($args);
     $view->execute();
-    $this->verbose('<pre>Executed view: ' . ((string) $view->build_info['query']) . '</pre>');
+    $query = $view->build_info['query'];
+    $this->verbose('<pre>Executed view: ' . $query->query_preview($view) . '</pre>');
   }
 }
 
