Skip to content

Commit

Permalink
Fix SQL error when custom field is in filter/sort
Browse files Browse the repository at this point in the history
If the same custom field is used for filtering to a value that is not "any" and is also used for sorting,
the generated query defines the same table alias twice causing a SQL error.
The fix is to use different aliasing prefix for filtering vs. sorting.

Fixes #19670
  • Loading branch information
vboctor committed Apr 28, 2015
1 parent f591e7b commit 53ee0c7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/filter_api.php
Expand Up @@ -962,7 +962,9 @@ function filter_get_query_sort_data( array &$p_filter, $p_show_sticky, array $p_
$t_def = custom_field_get_definition( $t_custom_field_id );
$t_value_field = ( $t_def['type'] == CUSTOM_FIELD_TYPE_TEXTAREA ? 'text' : 'value' );
$c_cf_alias = 'custom_field_' . $t_custom_field_id;
$t_cf_table_alias = '{custom_field_string}_' . $t_custom_field_id;

# Distinguish filter table aliases from sort table aliases (see #19670)
$t_cf_table_alias = 'cf_sort_' . $t_custom_field_id;
$t_cf_select = $t_cf_table_alias . '.' . $t_value_field . ' ' . $c_cf_alias;

# check to be sure this field wasn't already added to the query.
Expand Down

0 comments on commit 53ee0c7

Please sign in to comment.