bug #967610, double column sort with JOIN

This commit is contained in:
Marc Delisle
2004-10-11 13:24:59 +00:00
parent 620f9b764b
commit 0a06f5c57c
3 changed files with 55 additions and 40 deletions

View File

@@ -698,6 +698,7 @@ if ($is_minimum_common == FALSE) {
'having_clause' => '',
'where_clause' => '',
'where_clause_identifiers' => array(),
'unsorted_query' => '',
'queryflags' => array(),
'select_expr' => array(),
'table_ref' => array(),
@@ -750,9 +751,10 @@ if ($is_minimum_common == FALSE) {
* Currently, those are generated:
*
* ['queryflags']['need_confirm'] = 1; if the query needs confirmation
* ['queryflags']['select_from'] = 1; if this is a real SELECT...FROM
* ['queryflags']['distinct'] = 1; for a DISTINCT
* ['queryflags']['union'] = 1; for a UNION
* ['queryflags']['select_from'] = 1; if this is a real SELECT...FROM
* ['queryflags']['distinct'] = 1; for a DISTINCT
* ['queryflags']['union'] = 1; for a UNION
* ['queryflags']['join'] = 1; for a JOIN
*
* lem9: query clauses
* -------------
@@ -765,9 +767,12 @@ if ($is_minimum_common == FALSE) {
* ['having_clause']
* ['where_clause']
*
* and the identifiers of the where clause are put into the array
* The identifiers of the WHERE clause are put into the array
* ['where_clause_identifier']
*
* For a SELECT, the whole query without the ORDER BY clause is put into
* ['unsorted_query']
*
* lem9: foreign keys
* ------------
* The CREATE TABLE may contain FOREIGN KEY clauses, so they get
@@ -781,6 +786,8 @@ if ($is_minimum_common == FALSE) {
*
* The array index of the first SELECT we find. Will be used to
* insert a SQL_CALC_FOUND_ROWS.
*
* End of description of analyzer results
*/
// must be sorted
@@ -1235,13 +1242,14 @@ if ($is_minimum_common == FALSE) {
$seen_reserved_word = FALSE;
$seen_group = FALSE;
$seen_order = FALSE;
$in_group_by = FALSE; // true when we are into the GROUP BY clause
$in_order_by = FALSE; // true when we are into the ORDER BY clause
$in_having = FALSE; // true when we are into the HAVING clause
$in_select_expr = FALSE; // true when we are into the select expr clause
$in_where = FALSE; // true when we are into the WHERE clause
$in_group_by = FALSE; // true when we are inside the GROUP BY clause
$in_order_by = FALSE; // true when we are inside the ORDER BY clause
$in_having = FALSE; // true when we are inside the HAVING clause
$in_select_expr = FALSE; // true when we are inside the select expr clause
$in_where = FALSE; // true when we are inside the WHERE clause
$in_from = FALSE;
$in_group_concat = FALSE;
$unsorted_query = '';
for ($i = 0; $i < $size; $i++) {
//DEBUG echo "trace loop2 <b>" . $arr[$i]['data'] . "</b> (" . $arr[$i]['type'] . ")<br />";
@@ -1297,6 +1305,10 @@ if ($is_minimum_common == FALSE) {
$subresult['queryflags']['union'] = 1;
}
if ($upper_data == 'JOIN') {
$subresult['queryflags']['join'] = 1;
}
// if this is a real SELECT...FROM
if ($upper_data == 'FROM' && isset($subresult['queryflags']['select_from']) && $subresult['queryflags']['select_from'] == 1) {
$in_from = TRUE;
@@ -1431,6 +1443,13 @@ if ($is_minimum_common == FALSE) {
}
}
// FIXME: is it correct to always add $sep ?
if (isset($subresult['queryflags']['select_from'])
&& $subresult['queryflags']['select_from'] == 1
&& !$seen_order) {
$unsorted_query .= $arr[$i]['data'] . $sep;
}
// clear $upper_data for next iteration
$upper_data='';
@@ -1594,6 +1613,9 @@ if ($is_minimum_common == FALSE) {
if (isset($where_clause)) {
$subresult['where_clause'] = $where_clause;
}
if (isset($unsorted_query) && !empty($unsorted_query)) {
$subresult['unsorted_query'] = $unsorted_query;
}
if (isset($where_clause_identifiers)) {
$subresult['where_clause_identifiers'] = $where_clause_identifiers;
}