bug 2941037 - Database structure not sorted by table correctly
This commit is contained in:
@@ -6,6 +6,7 @@ $Id$
|
||||
$HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/ChangeLog $
|
||||
|
||||
3.3.1.0 (not yet released)
|
||||
- bug #2941037 [core] Database structure not sorted by table correctly
|
||||
|
||||
3.3.0.0 (not yet released)
|
||||
+ rfe #2308632 [edit] Use hex for (var)binary fields,
|
||||
|
@@ -313,31 +313,7 @@ function PMA_DBI_get_tables_full($database, $table = false, $tbl_is_group = fals
|
||||
' . $sql_where_table;
|
||||
|
||||
// Sort the tables
|
||||
if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) {
|
||||
// This crazy bit of SQL was inspired by a post here:
|
||||
// http://forums.mysql.com/read.php?10,34908,35959#msg-35959
|
||||
|
||||
// Find the longest table name
|
||||
$max_name_sql = "SELECT MAX(LENGTH(TABLE_NAME)) FROM `information_schema`.`TABLES`
|
||||
WHERE `TABLE_SCHEMA` IN ('" . implode("', '", $this_databases) . "')";
|
||||
$max_name_array = PMA_DBI_fetch_result($max_name_sql);
|
||||
$max_name_length = $max_name_array[0];
|
||||
|
||||
// Put the CASE statement SQL together.
|
||||
$sql_case = '';
|
||||
for ($i = 1; $i < $max_name_length; $i++) {
|
||||
$sql_case .= " when substr(Name, $i) between '0' and '9' then $i";
|
||||
}
|
||||
$sql_case .= " ELSE $max_name_length end) ";
|
||||
|
||||
// Add the CASE statement to the main SQL
|
||||
$sql .= " ORDER BY left(Name, (CASE ";
|
||||
$sql .= $sql_case . "-1) $sort_order, 0+substr(Name, CASE";
|
||||
$sql .= $sql_case . $sort_order;
|
||||
} else {
|
||||
// Just let MySQL sort as it normally does
|
||||
$sql .= " ORDER BY $sort_by $sort_order";
|
||||
}
|
||||
|
||||
if ($limit_count) {
|
||||
$sql .= ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset;
|
||||
@@ -346,7 +322,18 @@ function PMA_DBI_get_tables_full($database, $table = false, $tbl_is_group = fals
|
||||
$tables = PMA_DBI_fetch_result($sql, array('TABLE_SCHEMA', 'TABLE_NAME'),
|
||||
null, $link);
|
||||
unset($sql_where_table, $sql);
|
||||
if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) {
|
||||
// here, the array's first key is by schema name
|
||||
foreach($tables as $one_database_name => $one_database_tables) {
|
||||
uksort($one_database_tables, 'strnatcasecmp');
|
||||
|
||||
if ($sort_order == 'DESC') {
|
||||
$one_database_tables = array_reverse($one_database_tables);
|
||||
}
|
||||
$tables[$one_database_name] = $one_database_tables;
|
||||
}
|
||||
}
|
||||
} // end (get information from table schema)
|
||||
|
||||
// If permissions are wrong on even one database directory,
|
||||
// information_schema does not return any table info for any database
|
||||
|
Reference in New Issue
Block a user