View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0005859 | mantisbt | filters | public | 2005-06-29 08:46 | 2012-09-17 16:04 |
Reporter | hinke | Assigned To | daryn | ||
Priority | normal | Severity | major | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | 1.0.0a3 | ||||
Target Version | 1.2.5 | Fixed in Version | 1.2.5 | ||
Summary | 0005859: "Sort by" can't handle more than one custom field in combination | ||||
Description | When using the "Sort by" feature of the filter with more than one custom field it yields the result of a 0000401 error, and the filter has to be reset. It does not matter if it is with DHTML or not. | ||||
Tags | No tags attached. | ||||
Attached Files | filter-special-chars.patch (1,274 bytes)
diff --git a/core/filter_api.php b/core/filter_api.php index 31d8574..27d9273 100644 --- a/core/filter_api.php +++ b/core/filter_api.php @@ -943,7 +943,7 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause $t_value_field = ( $t_def['type'] == CUSTOM_FIELD_TYPE_TEXTAREA ? 'text' : 'value' ); $c_cf_alias = str_replace( ' ', '_', $t_custom_field ); $t_cf_table_alias = $t_custom_field_string_table . '_' . $t_custom_field_id; - $t_cf_select = "$t_cf_table_alias.$t_value_field $c_cf_alias"; + $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. if( !in_array( $t_cf_select, $p_query_clauses['select'] ) ) { @@ -951,7 +951,7 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause $p_query_clauses['join'][] = "LEFT JOIN $t_custom_field_string_table $t_cf_table_alias ON $t_bug_table.id = $t_cf_table_alias.bug_id AND $t_cf_table_alias.field_id = $t_custom_field_id"; } - $p_query_clauses['order'][] = "$c_cf_alias $c_dir"; + $p_query_clauses['order'][] = "`$c_cf_alias` $c_dir"; # if sorting by plugin columns } else if ( isset( $t_plugin_columns[ $t_sort_fields[$i] ] ) ) { filter1.2-special-chars.patch (1,167 bytes)
diff --git a/core/filter_api.php b/core/filter_api.php index 7ec05f9..55eda21 100644 --- a/core/filter_api.php +++ b/core/filter_api.php @@ -919,7 +919,7 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause $c_cf_alias = str_replace( ' ', '_', $t_custom_field ); $t_cf_table_alias = $t_custom_field_string_table . '_' . $t_custom_field_id; - $t_cf_select = "$t_cf_table_alias.value $c_cf_alias"; + $t_cf_select = "$t_cf_table_alias.value `$c_cf_alias`"; # check to be sure this field wasn't already added to the query. if( !in_array( $t_cf_select, $p_query_clauses['select'] ) ) { @@ -927,7 +927,7 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause $p_query_clauses['join'][] = "LEFT JOIN $t_custom_field_string_table $t_cf_table_alias ON $t_bug_table.id = $t_cf_table_alias.bug_id AND $t_cf_table_alias.field_id = $t_custom_field_id"; } - $p_query_clauses['order'][] = "$c_cf_alias $c_dir"; + $p_query_clauses['order'][] = "`$c_cf_alias` $c_dir"; # if sorting by plugin columns } else if ( isset( $t_plugin_columns[ $t_sort_fields[$i] ] ) ) { | ||||
has duplicate | 0009773 | closed | dhx | Sorting of two custom fields does not work |
has duplicate | 0011737 | closed | atrol | Sorting on two custom fields results in SQL errors |
has duplicate | 0012626 | closed | atrol | SQL Error in sorting custom field in "View Issues" page (APPLICATION ERROR 0000401) |
has duplicate | 0011139 | closed | atrol | APPLICATION ERROR 0000401 - DB -> #1066: Not unique table/alias for custom_field |
related to | 0008323 | closed | dregad | Spaces in custom fields |
Yes. The same db column will appear twice in the query. |
|
This can be solved with alias as tablenames: In core\filter_api.php Old Code: if sorting by a custom field
New Code: if sorting by a custom field
Perhaps could you implement this in the next release. Regards |
|
this still occurs in 1.2.0rc2 and causes the above error. However, cause the filter is cached, even if the user hits the back button, they can't recover from this, resulting in the inability to perform searches. unfortunately the way the query is constructing in 1.2.0rc2 is different from what was posted by qhweb, so a different patch woudl need to be made. To get around this seemingly unrecoverable error: |
|
ghweb code works for me. There was an error happends on ma side while changing the code. Thank you ghweb |
|
Multiple LEFT JOIN's between the same tables sounds very inefficient to me. I think we should be using multiple WHERE clauses instead? |
|
We just installed Mantis 1.2.1 and it seems to be fixed. BUT: Now we get these SQL-errors when sorting for custom fields containing "special" characters:
|
|
0011139 is another duplicate of this issue. My patch for this problem (1.2.0 - 1.2.2) is to prevent multiple left joins: --- mantis-1.2.0/core/filter_api.php 2010-02-24 10:34:19.642476000 +0100 check to be sure this field wasn't already added to the query.
It may be better to use the table name of the joined table as a key (i. e. $p_query_clauses['join'][$t_cf_table_alias] instead of just $p_query_clauses['join'][]), but this would mean to rewrite some code in filter_get_bug_rows() (don't use array_push()). This patch doesn't address the "special character" problem. |
|
filter api already handles duplicate selects, joins, and from clauses. The problem here was that one of the custom field joins was reversed and had extra whitespace. See commit below. The special character problem still exists as far as I know. |
|
Ok I determined that placing backtics around the column name allows special chars in the field name...at least for mysql. I've attached a patch for this and will commit this if I can get some testers for other databases to verify that it works and doesn't break anything else. The patch is against latest master but should work just fine for master-1.2.x as well. |
|
The original patch doesn't work for 1.2 so i uploaded an additional patch for the 1.2.x branch. |
|
Backticks only work with MySQL, not with any other database managemant system I know. Why don't you just eliminate or replace special chars with preg_replace() or something like that before using it? (pregreplace('/^[a-zA-Z0-9]/', '_', $table_name)) |
|
This just fixes the duplicate alias problem not the special character problem |
|
http://www.mantisbt.org/bugs/view.php?id=12691#c28509 Why it is so? |
|
Guys, this is an old issue and I can't reproduce it. I guess it was already fixed. |
|
MantisBT: master be2404c9 2010-12-22 10:39 Details Diff |
Fix for Bug 0005859: "Sort by" can't handle more than one custom field in combination. This just fixes the duplicate alias problem not the special character problem listed in the bug. |
Affected Issues 0005859 |
|
mod - core/filter_api.php | Diff File | ||
MantisBT: master-1.2.x 674e2e17 2010-12-22 10:39 Details Diff |
Fix for Bug 0005859: "Sort by" can't handle more than one custom field in combination. This just fixes the duplicate alias problem not the special character problem listed in the bug. |
Affected Issues 0005859 |
|
mod - core/filter_api.php | Diff File |