Commit 82987986 authored by DamienMcKenna's avatar DamienMcKenna

Issue #1331056 by thekevinday, robertwb, steinmb, DamienMcKenna,...

Issue #1331056 by thekevinday, robertwb, steinmb, DamienMcKenna, joseph.olstad, chamilsanjeewa, Proteo, dawehner, steverweber, hubScrappy, tim.plunkett, colan, acbramley, stevector, merlinofchaos, sylus, seanB, scott.whittaker, matheushamonangan, drmabuse_, bellerophons_pegasus: Regression: Improper use of GROUP BY statement produces ambiguous column error.
parent 4c60cf4a
......@@ -1214,7 +1214,9 @@ class views_plugin_query_default extends views_plugin_query {
}
// This is a formula, using no tables.
elseif (empty($field['table'])) {
$non_aggregates[] = $fieldname;
if (!in_array($fieldname, $non_aggregates)) {
$non_aggregates[] = $fieldname;
}
$placeholders = !empty($field['placeholders']) ? $field['placeholders'] : array();
$query->addExpression($string, $fieldname, $placeholders);
}
......@@ -1222,10 +1224,15 @@ class views_plugin_query_default extends views_plugin_query {
elseif ($this->distinct && !in_array($fieldname, $this->groupby)) {
// d7cx: This code was there, apparently needed for PostgreSQL
// $string = db_driver() == 'pgsql' ? "FIRST($string)" : $string;
if (!in_array($string, $non_aggregates)) {
$non_aggregates[] = $string;
}
$query->addField(!empty($field['table']) ? $field['table'] : $this->base_table, $field['field'], $fieldname);
}
elseif (empty($field['aggregate'])) {
$non_aggregates[] = $fieldname;
if (!in_array($string, $non_aggregates)) {
$non_aggregates[] = $string;
}
$query->addField(!empty($field['table']) ? $field['table'] : $this->base_table, $field['field'], $fieldname);
}
......
......@@ -21,6 +21,86 @@ class ViewsQueryGroupByTest extends ViewsSqlTest {
);
}
// tests ambiguous group by column error (postgresql)
public function testAggregateAmbiguity() {
// Create 4 nodes of type1
$type1 = $this->drupalCreateContentType();
$node_1 = array(
'type' => $type1->type,
);
$this->drupalCreateNode($node_1);
$this->drupalCreateNode($node_1);
$this->drupalCreateNode($node_1);
$this->drupalCreateNode($node_1);
$view = $this->viewsAggregateAmbiguityView();
$output = $view->execute_display();
$this->assertEqual(count($view->result), 1, 'Make sure there are no ambiguity problems with the group by operation.');
}
public function viewsAggregateAmbiguityView() {
$view = new view();
$view->name = 'aggregate_ambiguity';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = '';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: COUNT(Content revision: Nid) */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node_revision';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['group_type'] = 'count';
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid_1']['id'] = 'nid_1';
$handler->display->display_options['fields']['nid_1']['table'] = 'node';
$handler->display->display_options['fields']['nid_1']['field'] = 'nid';
$handler->display->display_options['fields']['nid_1']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid_1']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid_1']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid_1']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid_1']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid_1']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid_1']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid_1']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid_1']['empty_zero'] = 0;
/* Contextual filter: Content: Type */
$handler->display->display_options['arguments']['type']['id'] = 'type';
$handler->display->display_options['arguments']['type']['table'] = 'node';
$handler->display->display_options['arguments']['type']['field'] = 'type';
$handler->display->display_options['arguments']['type']['default_action'] = 'summary';
$handler->display->display_options['arguments']['type']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['type']['summary']['format'] = 'default_summary';
return $view;
}
/**
* Tests aggregate count feature.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment