? plugins/table_queue.txt
Index: plugins/views_plugin_query_default.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/plugins/Attic/views_plugin_query_default.inc,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 views_plugin_query_default.inc
--- plugins/views_plugin_query_default.inc	15 Sep 2009 19:29:09 -0000	1.1.2.7
+++ plugins/views_plugin_query_default.inc	31 Oct 2009 17:53:29 -0000
@@ -931,47 +931,20 @@ class views_plugin_query_default extends
       }
     }
 
-    $has_aggregate = FALSE;
-    $non_aggregates = array();
-
     foreach ($fields_array as $field) {
       if ($fields) {
         $fields .= ",\n   ";
       }
-      $string = '';
-      if (!empty($field['table'])) {
-        $string .= $field['table'] . '.';
-      }
-      $string .= $field['field'];
-      // store for use with non-aggregates below
-      $fieldname = (!empty($field['alias']) ? $field['alias'] : $string);
-
-      if (!empty($field['distinct'])) {
-        $string = "DISTINCT($string)";
-      }
-      if (!empty($field['count'])) {
-        $string = "COUNT($string)";
-        $has_aggregate = TRUE;
-      }
-      elseif ($this->distinct && !in_array($fieldname, $this->groupby)) {
-        $string = $GLOBALS['db_type'] == 'pgsql' ? "FIRST($string)" : $string;
-      }
-      else {
-        $non_aggregates[] = $fieldname;
-      }
-      if ($field['alias']) {
-        $string .= " AS $field[alias]";
-      }
-      $fields .= $string;
-
+      $fields .= $this->compile_field($field);
+      
       if ($get_count_optimized) {
         // We only want the first field in this case.
         break;
       }
     }
 
-    if ($has_aggregate || $this->groupby) {
-      $groupby = "GROUP BY " . implode(', ', array_unique(array_merge($this->groupby, $non_aggregates))) . "\n";
+    if ($this->has_aggregate || $this->groupby) {
+      $groupby = "GROUP BY " . implode(', ', array_unique(array_merge($this->groupby, $this->non_aggregates))) . "\n";
       if ($this->having) {
         $having = $this->condition_sql('having');
       }
@@ -994,6 +967,36 @@ class views_plugin_query_default extends
     return $query;
   }
 
+  function compile_field($field) {
+    $this->has_aggregate = FALSE;
+    $this->non_aggregates = array();
+    $string = '';
+    if (!empty($field['table'])) {
+      $string .= $field['table'] . '.';
+    }
+    $string .= $field['field'];
+    // store for use with non-aggregates below
+    $fieldname = (!empty($field['alias']) ? $field['alias'] : $string);
+
+    if (!empty($field['distinct'])) {
+      $string = "DISTINCT($string)";
+    }
+    if (!empty($field['count'])) {
+      $string = "COUNT($string)";
+      $this->has_aggregate = TRUE;
+    }
+    elseif ($this->distinct && !in_array($fieldname, $this->groupby)) {
+      $string = $GLOBALS['db_type'] == 'pgsql' ? "FIRST($string)" : $string;
+    }
+    else {
+      $this->non_aggregates[] = $fieldname;
+    }
+    if ($field['alias']) {
+      $string .= " AS $field[alias]";
+    }
+    return $string;
+  }
+
   /**
    * Get the arguments attached to the WHERE and HAVING clauses of this query.
    */
