@@ -8,6 +8,7 @@ $HeadURL$
|
|||||||
+ [import] support handling of DELIMITER to mimic mysql CLI, thanks to fb1
|
+ [import] support handling of DELIMITER to mimic mysql CLI, thanks to fb1
|
||||||
- bug #1674914 [structure] changing definition of a TIMESTAMP field
|
- bug #1674914 [structure] changing definition of a TIMESTAMP field
|
||||||
- bug #1615530 [upload] added more specific error message if field upload fails
|
- bug #1615530 [upload] added more specific error message if field upload fails
|
||||||
|
- bug #1627210, #1083301, #1482401 [data] warning on duplicate indexes
|
||||||
- [gui] avoid displaying a wide selector in server selection
|
- [gui] avoid displaying a wide selector in server selection
|
||||||
+ [core] added PMA_fatalError() and made use of it
|
+ [core] added PMA_fatalError() and made use of it
|
||||||
. [i18n] use generic $strOptions
|
. [i18n] use generic $strOptions
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
/* $Id$ */
|
/* vim: expandtab sw=4 ts=4 sts=4: */
|
||||||
// vim: expandtab sw=4 ts=4 sts=4:
|
|
||||||
/**
|
/**
|
||||||
* function library for handling table indexes
|
* function library for handling table indexes
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,68 +13,114 @@
|
|||||||
* @return array Index types
|
* @return array Index types
|
||||||
* @author Garvin Hicking (pma@supergarv.de)
|
* @author Garvin Hicking (pma@supergarv.de)
|
||||||
*/
|
*/
|
||||||
function PMA_get_indextypes() {
|
function PMA_get_indextypes()
|
||||||
|
{
|
||||||
return array(
|
return array(
|
||||||
'PRIMARY',
|
'PRIMARY',
|
||||||
'INDEX',
|
'INDEX',
|
||||||
'UNIQUE',
|
'UNIQUE',
|
||||||
'FULLTEXT'
|
'FULLTEXT',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get all index information from a certain table
|
* Function to get all index information from a certain table
|
||||||
*
|
*
|
||||||
* @param string Table name
|
* @uses PMA_DBI_fetch_result()
|
||||||
* @param string Error URL
|
* @uses PMA_backquote()
|
||||||
|
* @param string $tbl_name Table name to ftech indexes from
|
||||||
|
* @param string $err_url_0 Error URL
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return array Index keys
|
* @return array Index keys
|
||||||
*/
|
*/
|
||||||
function PMA_get_indexes($tbl_name, $err_url_0 = '') {
|
function PMA_get_indexes($tbl_name, $err_url_0 = '')
|
||||||
$tbl_local_query = 'SHOW KEYS FROM ' . PMA_backquote($tbl_name);
|
{
|
||||||
$tbl_result = PMA_DBI_query($tbl_local_query) or PMA_mysqlDie('', $tbl_local_query, '', $err_url_0);
|
return PMA_DBI_fetch_result('SHOW KEYS FROM ' . PMA_backquote($tbl_name));
|
||||||
$tbl_ret_keys = array();
|
|
||||||
while ($tbl_row = PMA_DBI_fetch_assoc($tbl_result)) {
|
|
||||||
$tbl_ret_keys[] = $tbl_row;
|
|
||||||
}
|
|
||||||
PMA_DBI_free_result($tbl_result);
|
|
||||||
|
|
||||||
return $tbl_ret_keys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to check over array of indexes and look for common problems
|
* Function to check over array of indexes and look for common problems
|
||||||
*
|
*
|
||||||
* @param array Array of indexes
|
* @uses $GLOBALS['strIndexesSeemEqual']
|
||||||
* @param boolean Whether to output HTML in table layout
|
* @uses PMA_get_indexes()
|
||||||
*
|
* @uses is_string()
|
||||||
|
* @uses is_array()
|
||||||
|
* @uses count()
|
||||||
|
* @uses array_pop()
|
||||||
|
* @uses reset()
|
||||||
|
* @uses current()
|
||||||
* @access public
|
* @access public
|
||||||
|
* @param mixed array of indexes from PMA_get_indexes()
|
||||||
|
* or name of table
|
||||||
* @return string Output HTML
|
* @return string Output HTML
|
||||||
* @author Garvin Hicking (pma@supergarv.de)
|
|
||||||
*/
|
*/
|
||||||
function PMA_check_indexes($idx_collection, $table = true) {
|
function PMA_check_indexes($idx_collection)
|
||||||
$index_types = PMA_get_indextypes();
|
{
|
||||||
$output = '';
|
if (is_string($idx_collection)) {
|
||||||
|
$idx_collection = PMA_get_indexes($idx_collection);
|
||||||
if ( ! is_array($idx_collection) || empty($idx_collection['ALL'])) {
|
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($idx_collection['ALL'] AS $w_keyname => $w_count) {
|
// count($idx_collection) < 2:
|
||||||
if (isset($idx_collection['PRIMARY'][$w_keyname]) && (isset($idx_collection['INDEX'][$w_keyname]) || isset($idx_collection['UNIQUE'][$w_keyname]))) {
|
// there is no need to check if there less than two indexes
|
||||||
$output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningPrimary'], htmlspecialchars($w_keyname)), $table);
|
if (! is_array($idx_collection) || count($idx_collection) < 2) {
|
||||||
} elseif (isset($idx_collection['UNIQUE'][$w_keyname]) && isset($idx_collection['INDEX'][$w_keyname])) {
|
return false;
|
||||||
$output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningUnique'], htmlspecialchars($w_keyname)), $table);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($index_types AS $index_type) {
|
$indexes = array();
|
||||||
if (isset($idx_collection[$index_type][$w_keyname]) && $idx_collection[$index_type][$w_keyname] > 1) {
|
foreach ($idx_collection as $index_field) {
|
||||||
$output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningMultiple'], $index_type, htmlspecialchars($w_keyname)), $table);
|
$indexes[$index_field['Key_name']][$index_field['Column_name']]
|
||||||
|
= $index_field;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = '';
|
||||||
|
|
||||||
|
// remove last index from stack and ...
|
||||||
|
while ($while_index = array_pop($indexes)) {
|
||||||
|
// ... compare with every remaining index in stack
|
||||||
|
foreach ($indexes as $each_index_name => $each_index) {
|
||||||
|
if (count($while_index) !== count($each_index)) {
|
||||||
|
// number of fields are not equal
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compare some key elements of every column in this two indexes
|
||||||
|
foreach ($each_index as $col_name => $each_index_column) {
|
||||||
|
if (! isset($while_index[$col_name])
|
||||||
|
// the position
|
||||||
|
|| $while_index[$col_name]['Seq_in_index'] !== $each_index_column['Seq_in_index']
|
||||||
|
// the order, ASC or DESC
|
||||||
|
|| $while_index[$col_name]['Collation'] !== $each_index_column['Collation']
|
||||||
|
// the length
|
||||||
|
|| $while_index[$col_name]['Sub_part'] !== $each_index_column['Sub_part']
|
||||||
|
// BTREE or HASH
|
||||||
|
|| $while_index[$col_name]['Index_type'] !== $each_index_column['Index_type']) {
|
||||||
|
continue 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// did not find any difference
|
||||||
|
// so it makes no sense to have this two equal indexes
|
||||||
|
|
||||||
|
// use first column from index to fetch index name
|
||||||
|
reset($while_index);
|
||||||
|
$first_column = current($while_index);
|
||||||
|
|
||||||
|
$output .= '<div class="warning">';
|
||||||
|
$output .= $GLOBALS['strIndexesSeemEqual'];
|
||||||
|
$output .= $each_index_name . ', ' . $first_column['Key_name'];
|
||||||
|
$output .= '</div>';
|
||||||
|
|
||||||
|
// there is no need to check any further indexes if we have already
|
||||||
|
// found that this one has a duplicate
|
||||||
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($output) {
|
||||||
|
$output = '<tr><td colspan=7">' . $output . '</td></tr>';
|
||||||
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +137,9 @@ function PMA_check_indexes($idx_collection, $table = true) {
|
|||||||
* @return boolean void
|
* @return boolean void
|
||||||
* @author Garvin Hicking (pma@supergarv.de)
|
* @author Garvin Hicking (pma@supergarv.de)
|
||||||
*/
|
*/
|
||||||
function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_data) {
|
function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_data)
|
||||||
if (!is_array($ret_keys)) {
|
{
|
||||||
|
if (! is_array($ret_keys)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +189,9 @@ function PMA_extract_indexes(&$ret_keys, &$indexes, &$indexes_info, &$indexes_da
|
|||||||
* @return array Index collection array
|
* @return array Index collection array
|
||||||
* @author Garvin Hicking (pma@supergarv.de)
|
* @author Garvin Hicking (pma@supergarv.de)
|
||||||
*/
|
*/
|
||||||
function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $display_html = true, $print_mode = false) {
|
function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data,
|
||||||
|
$display_html = true, $print_mode = false)
|
||||||
|
{
|
||||||
$idx_collection = array();
|
$idx_collection = array();
|
||||||
$odd_row = true;
|
$odd_row = true;
|
||||||
foreach ($indexes as $index_name) {
|
foreach ($indexes as $index_name) {
|
||||||
@@ -175,7 +225,9 @@ function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $di
|
|||||||
|
|
||||||
if (!$print_mode) {
|
if (!$print_mode) {
|
||||||
echo ' <td ' . $row_span . '>' . "\n"
|
echo ' <td ' . $row_span . '>' . "\n"
|
||||||
. ' <a href="tbl_indexes.php?' . $GLOBALS['url_query'] . '&index=' . urlencode($index_name) . '">' . $GLOBALS['edit_link_text'] . '</a>' . "\n"
|
. ' <a href="tbl_indexes.php?'
|
||||||
|
. $GLOBALS['url_query'] . '&index=' . urlencode($index_name)
|
||||||
|
. '">' . $GLOBALS['edit_link_text'] . '</a>' . "\n"
|
||||||
. ' </td>' . "\n";
|
. ' </td>' . "\n";
|
||||||
|
|
||||||
if ($index_name == 'PRIMARY') {
|
if ($index_name == 'PRIMARY') {
|
||||||
@@ -189,7 +241,10 @@ function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $di
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo ' <td ' . $row_span . '>' . "\n"
|
echo ' <td ' . $row_span . '>' . "\n"
|
||||||
. ' <a href="sql.php?' . $GLOBALS['url_query'] . '&sql_query=' . $local_query . '&zero_rows=' . $zero_rows . '" onclick="return confirmLink(this, \'' . $js_msg . '\')">' . $GLOBALS['drop_link_text'] . '</a>' . "\n"
|
. ' <a href="sql.php?' . $GLOBALS['url_query']
|
||||||
|
. '&sql_query=' . $local_query . '&zero_rows='
|
||||||
|
. $zero_rows . '" onclick="return confirmLink(this, \''
|
||||||
|
. $js_msg . '\')">' . $GLOBALS['drop_link_text'] . '</a>' . "\n"
|
||||||
. ' </td>' . "\n";
|
. ' </td>' . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,22 +292,4 @@ function PMA_show_indexes($table, &$indexes, &$indexes_info, &$indexes_data, $di
|
|||||||
return $idx_collection;
|
return $idx_collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to emit a index warning
|
|
||||||
*
|
|
||||||
* @author Garvin Hicking (pma@supergarv.de)
|
|
||||||
* @access public
|
|
||||||
* @param string $string Message string
|
|
||||||
* @param boolean $table Whether to output HTML in table layout
|
|
||||||
* @return string Output HTML
|
|
||||||
*/
|
|
||||||
function PMA_index_warning($string, $table = true) {
|
|
||||||
$output = '<div class="warning">' . $string . '</div>';
|
|
||||||
|
|
||||||
if ( $table ) {
|
|
||||||
$output = '<tr><td colspan=7">' . $output . '</td></tr>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output . "\n";
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
|
12
sql.php
12
sql.php
@@ -724,15 +724,9 @@ else {
|
|||||||
|
|
||||||
// BEGIN INDEX CHECK See if indexes should be checked.
|
// BEGIN INDEX CHECK See if indexes should be checked.
|
||||||
if (isset($query_type) && $query_type == 'check_tbl' && isset($selected) && is_array($selected)) {
|
if (isset($query_type) && $query_type == 'check_tbl' && isset($selected) && is_array($selected)) {
|
||||||
foreach ($selected AS $idx => $tbl_name) {
|
foreach ($selected as $idx => $tbl_name) {
|
||||||
$indexes = $indexes_info = $indexes_data = array();
|
$check = PMA_check_indexes($tbl_name);
|
||||||
$tbl_ret_keys = PMA_get_indexes(urldecode($tbl_name), $err_url_0);
|
if (! empty($check)) {
|
||||||
|
|
||||||
PMA_extract_indexes($tbl_ret_keys, $indexes, $indexes_info, $indexes_data);
|
|
||||||
|
|
||||||
$idx_collection = PMA_show_indexes(urldecode($tbl_name), $indexes, $indexes_info, $indexes_data, false);
|
|
||||||
$check = PMA_check_indexes($idx_collection);
|
|
||||||
if (!empty($check)) {
|
|
||||||
?>
|
?>
|
||||||
<table border="0" cellpadding="2" cellspacing="0">
|
<table border="0" cellpadding="2" cellspacing="0">
|
||||||
<tr>
|
<tr>
|
||||||
|
@@ -1,18 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
/* $Id$ */
|
/* vim: expandtab sw=4 ts=4 sts=4: */
|
||||||
// vim: expandtab sw=4 ts=4 sts=4:
|
/**
|
||||||
|
* display information about indexes in a table
|
||||||
|
*
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets some core libraries
|
* Gets some core libraries
|
||||||
*/
|
*/
|
||||||
require_once('./libraries/common.lib.php');
|
require_once './libraries/common.lib.php';
|
||||||
require_once('./libraries/tbl_indexes.lib.php');
|
require_once './libraries/tbl_indexes.lib.php';
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines the index types ("FULLTEXT" is available since MySQL 3.23.23)
|
|
||||||
*/
|
|
||||||
$index_types = PMA_get_indextypes();
|
|
||||||
$index_types_cnt = count($index_types);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures the db & table are valid, then loads headers and gets indexes
|
* Ensures the db & table are valid, then loads headers and gets indexes
|
||||||
@@ -56,7 +54,7 @@ if (!defined('PMA_IDX_INCLUDED')) {
|
|||||||
$js_to_run = isset($index) && isset($do_save_data)
|
$js_to_run = isset($index) && isset($do_save_data)
|
||||||
? 'functions.js'
|
? 'functions.js'
|
||||||
: 'indexes.js';
|
: 'indexes.js';
|
||||||
require_once('./libraries/header.inc.php');
|
require_once './libraries/header.inc.php';
|
||||||
} // end if
|
} // end if
|
||||||
|
|
||||||
|
|
||||||
@@ -184,7 +182,7 @@ if (!defined('PMA_IDX_INCLUDED')
|
|||||||
. $strHasBeenAltered;
|
. $strHasBeenAltered;
|
||||||
|
|
||||||
$active_page = 'tbl_structure.php';
|
$active_page = 'tbl_structure.php';
|
||||||
require('./tbl_structure.php');
|
require './tbl_structure.php';
|
||||||
} // end builds the new index
|
} // end builds the new index
|
||||||
|
|
||||||
|
|
||||||
@@ -296,22 +294,18 @@ elseif (!defined('PMA_IDX_INCLUDED')
|
|||||||
<label for="select_index_type"><?php echo $strIndexType; ?></label>
|
<label for="select_index_type"><?php echo $strIndexType; ?></label>
|
||||||
<select name="index_type" id="select_index_type" onchange="return checkIndexName()">
|
<select name="index_type" id="select_index_type" onchange="return checkIndexName()">
|
||||||
<?php
|
<?php
|
||||||
for ($i = 0; $i < $index_types_cnt; $i++) {
|
foreach (PMA_get_indextypes() as $each_index_type) {
|
||||||
if ($index_types[$i] == 'PRIMARY') {
|
if ($each_index_type === 'PRIMARY'
|
||||||
if ($index == 'PRIMARY' || !isset($indexes_info['PRIMARY'])) {
|
&& $index !== 'PRIMARY'
|
||||||
echo ' '
|
&& isset($indexes_info['PRIMARY'])) {
|
||||||
. '<option value="PRIMARY"'
|
// skip PRIMARY if there is already one in the table
|
||||||
. (($index_type == 'PRIMARY') ? ' selected="selected"' : '')
|
continue;
|
||||||
. '>PRIMARY</option>' . "\n";
|
}
|
||||||
}
|
echo ' '
|
||||||
} else {
|
. '<option value="' . $each_index_type . '"'
|
||||||
echo ' '
|
. (($index_type == $each_index_type) ? ' selected="selected"' : '')
|
||||||
. '<option value="' . $index_types[$i] . '"'
|
. '>'. $each_index_type . '</option>' . "\n";
|
||||||
. (($index_type == $index_types[$i]) ? ' selected="selected"' : '')
|
}
|
||||||
. '>'. $index_types[$i] . '</option>' . "\n";
|
|
||||||
|
|
||||||
} // end if... else...
|
|
||||||
} // end for
|
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
<?php echo PMA_showMySQLDocu('SQL-Syntax', 'ALTER_TABLE'); ?>
|
<?php echo PMA_showMySQLDocu('SQL-Syntax', 'ALTER_TABLE'); ?>
|
||||||
@@ -412,7 +406,7 @@ elseif (!defined('PMA_IDX_INCLUDED')
|
|||||||
</caption>
|
</caption>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( count($ret_keys) > 0) {
|
if (count($ret_keys) > 0) {
|
||||||
$edit_link_text = '';
|
$edit_link_text = '';
|
||||||
$drop_link_text = '';
|
$drop_link_text = '';
|
||||||
|
|
||||||
@@ -446,7 +440,7 @@ elseif (!defined('PMA_IDX_INCLUDED')
|
|||||||
<?php
|
<?php
|
||||||
$idx_collection = PMA_show_indexes($table, $indexes, $indexes_info,
|
$idx_collection = PMA_show_indexes($table, $indexes, $indexes_info,
|
||||||
$indexes_data, true);
|
$indexes_data, true);
|
||||||
echo PMA_check_indexes($idx_collection);
|
echo PMA_check_indexes($ret_keys);
|
||||||
} // end display indexes
|
} // end display indexes
|
||||||
else {
|
else {
|
||||||
// none indexes
|
// none indexes
|
||||||
@@ -478,6 +472,6 @@ elseif (!defined('PMA_IDX_INCLUDED')
|
|||||||
echo "\n";
|
echo "\n";
|
||||||
|
|
||||||
if (!defined('PMA_IDX_INCLUDED')){
|
if (!defined('PMA_IDX_INCLUDED')){
|
||||||
require_once('./libraries/footer.inc.php');
|
require_once './libraries/footer.inc.php';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Reference in New Issue
Block a user