/**
* Handle remembered sorting order, only for single table query
*
* @param string $db database name
* @param string $table table name
* @param array &$analyzed_sql_results the analyzed query results
* @param string &$full_sql_query SQL query
*
* @return void
*/
function PMA_handleSortOrder($db, $table, &$analyzed_sql_results, &$full_sql_query)
{
$pmatable = new Table($table, $db);
if (empty($analyzed_sql_results['order'])) {
// Retrieving the name of the column we should sort after.
$sortCol = $pmatable->getUiProp(Table::PROP_SORTED_COLUMN);
if (empty($sortCol)) {
return;
}
// Remove the name of the table from the retrieved field name.
$sortCol = str_replace(PMA\libraries\Util::backquote($table) . '.', '', $sortCol);
// Create the new query.
$full_sql_query = SqlParser\Utils\Query::replaceClause($analyzed_sql_results['statement'], $analyzed_sql_results['parser']->list, 'ORDER BY ' . $sortCol);
// TODO: Avoid reparsing the query.
$analyzed_sql_results = SqlParser\Utils\Query::getAll($full_sql_query);
} else {
// Store the remembered table into session.
$pmatable->setUiProp(Table::PROP_SORTED_COLUMN, SqlParser\Utils\Query::getClause($analyzed_sql_results['statement'], $analyzed_sql_results['parser']->list, 'ORDER BY'));
}
}