headwords for sorted column

This commit is contained in:
Marc Delisle
2008-07-26 15:18:59 +00:00
parent 14e5a97890
commit e6db29ed88
4 changed files with 78 additions and 17 deletions

View File

@@ -68,6 +68,7 @@ danbarry
+ rfe #1692928 [transformation] Option to disable browser transformations + rfe #1692928 [transformation] Option to disable browser transformations
+ [import] Speed optimization to be able to import the sakila database + [import] Speed optimization to be able to import the sakila database
+ [doc] Documentation for distributing phpMyAdmin in README.VENDOR. + [doc] Documentation for distributing phpMyAdmin in README.VENDOR.
+ [display] headwords for sorted column
2.11.8.0 (not yet released) 2.11.8.0 (not yet released)
- patch #1987593 [interface] Table list pagination in navi, - patch #1987593 [interface] Table list pagination in navi,

View File

@@ -187,6 +187,19 @@ function PMA_DBI_fetch_row($result)
return mysql_fetch_array($result, MYSQL_NUM); return mysql_fetch_array($result, MYSQL_NUM);
} }
/*
* Adjusts the result pointer to an arbitrary row in the result
*
* @uses mysql_data_seek()
* @param $result
* @param $offset
* @return boolean true on success, false on failure
*/
function PMA_DBI_data_seek($result, $offset)
{
return mysql_data_seek($result, $offset);
}
/** /**
* Frees the memory associated with the results * Frees the memory associated with the results
* *

View File

@@ -240,6 +240,19 @@ function PMA_DBI_fetch_row($result)
return mysqli_fetch_array($result, MYSQLI_NUM); return mysqli_fetch_array($result, MYSQLI_NUM);
} }
/*
* Adjusts the result pointer to an arbitrary row in the result
*
* @uses mysqli_data_seek()
* @param $result
* @param $offset
* @return boolean true on success, false on failure
*/
function PMA_DBI_data_seek($result, $offset)
{
return mysqli_data_seek($result, $offset);
}
/** /**
* Frees the memory associated with the results * Frees the memory associated with the results
* *

View File

@@ -448,7 +448,7 @@ onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo
* *
* @see PMA_displayTable() * @see PMA_displayTable()
*/ */
function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '') function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection)
{ {
global $db, $table, $goto; global $db, $table, $goto;
global $sql_query, $num_rows; global $sql_query, $num_rows;
@@ -467,18 +467,6 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
$unsorted_sql_query = $analyzed_sql[0]['unsorted_query']; $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
} }
// we need $sort_expression and $sort_expression_nodirection
// even if there are many table references
$sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
/**
* Get rid of ASC|DESC
* @todo analyzer
*/
preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
$sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
// sorting by indexes, only if it makes sense (only one table ref) // sorting by indexes, only if it makes sense (only one table ref)
if (isset($analyzed_sql) && isset($analyzed_sql[0]) && if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' && isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
@@ -1752,9 +1740,53 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
} }
} // end if } // end if
// 1.3 URL-encodes the query to use in input form fields // 1.3 Find the sort expression
// @todo where is this used?
//$encoded_sql_query = urlencode($sql_query); // we need $sort_expression and $sort_expression_nodirection
// even if there are many table references
$sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
/**
* Get rid of ASC|DESC
* @todo analyzer
*/
preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
$sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
unset($matches);
list($sort_db, $sort_table) = explode('.', $sort_expression_nodirection);
// 1.4 Prepares display of first and last value of the sorted column
if (! empty($sort_expression_nodirection)) {
list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
$sort_table = PMA_unQuote($sort_table);
$sort_column = PMA_unQuote($sort_column);
// find the sorted column index in row result
// (this might be a multi-table query)
$sorted_column_index = false;
foreach($fields_meta as $key => $meta) {
if ($meta->table == $sort_table && $meta->name == $sort_column) {
$sorted_column_index = $key;
break;
}
}
if ($sorted_column_index !== false) {
// fetch first row of the result set
$row = PMA_DBI_fetch_row($dt_result);
$column_for_first_row = $row[$sorted_column_index];
// fetch last row of the result set
PMA_DBI_data_seek($dt_result, $num_rows - 1);
$row = PMA_DBI_fetch_row($dt_result);
$column_for_last_row = $row[$sorted_column_index];
// reset to first row for the loop in PMA_displayTableBody()
PMA_DBI_data_seek($dt_result, 0);
// we could also use here $sort_expression_nodirection
$sorted_column_message = ' [' . $sort_column . ': ' . $column_for_first_row . ' - ' . $column_for_last_row . ']';
unset($row, $column_for_first_row, $column_for_last_row);
}
unset($sorted_column_index, $sort_table, $sort_column);
}
// 2. ----- Displays the top of the page ----- // 2. ----- Displays the top of the page -----
@@ -1800,6 +1832,8 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
$message->addMessage($messagge_qt, ''); $message->addMessage($messagge_qt, '');
$message->addMessage(')', ''); $message->addMessage(')', '');
$message->addMessage(isset($sorted_column_message) ? htmlspecialchars($sorted_column_message) : '', '');
PMA_showMessage($message, $sql_query, 'success'); PMA_showMessage($message, $sql_query, 'success');
} elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
@@ -1861,7 +1895,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
// end 2b // end 2b
// 3. ----- Displays the results table ----- // 3. ----- Displays the results table -----
PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql); PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection);
$url_query = ''; $url_query = '';
echo '<tbody>' . "\n"; echo '<tbody>' . "\n";
PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql); PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);