bug 2941037 - Database structure not sorted by table correctly

This commit is contained in:
Marc Delisle
2010-02-12 09:37:29 +00:00
parent 1f5a19b69c
commit 0b7a3f716a
2 changed files with 33 additions and 45 deletions

View File

@@ -6,6 +6,7 @@ $Id$
$HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/ChangeLog $ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/ChangeLog $
3.3.1.0 (not yet released) 3.3.1.0 (not yet released)
- bug #2941037 [core] Database structure not sorted by table correctly
3.3.0.0 (not yet released) 3.3.0.0 (not yet released)
+ rfe #2308632 [edit] Use hex for (var)binary fields, + rfe #2308632 [edit] Use hex for (var)binary fields,

View File

@@ -313,31 +313,7 @@ function PMA_DBI_get_tables_full($database, $table = false, $tbl_is_group = fals
' . $sql_where_table; ' . $sql_where_table;
// Sort the tables // 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"; $sql .= " ORDER BY $sort_by $sort_order";
}
if ($limit_count) { if ($limit_count) {
$sql .= ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset; $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'), $tables = PMA_DBI_fetch_result($sql, array('TABLE_SCHEMA', 'TABLE_NAME'),
null, $link); null, $link);
unset($sql_where_table, $sql); 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, // If permissions are wrong on even one database directory,
// information_schema does not return any table info for any database // information_schema does not return any table info for any database