Better detection of duplicate rows (bug #1477500).

This commit is contained in:
Michal Čihař
2006-04-27 09:16:32 +00:00
parent 7ad007ccf8
commit 3758013766
2 changed files with 37 additions and 23 deletions

View File

@@ -11,6 +11,8 @@ $Source$
(RFE #1370874). (RFE #1370874).
* sql.php: Show results of REPLACE as affected as it contains both deleted * sql.php: Show results of REPLACE as affected as it contains both deleted
and inserted rows count (bug #1475765). and inserted rows count (bug #1475765).
* libraries/common.lib.php: Better detection of duplicate rows (bug
#1477500).
2006-04-26 Michal Čihař <michal@cihar.com> 2006-04-26 Michal Čihař <michal@cihar.com>
* libraries/plugin_interface.lib.php: * libraries/plugin_interface.lib.php:

View File

@@ -974,33 +974,45 @@ if (!defined('PMA_MINIMUM_COMMON')) {
// special characters that can become high-ascii after editing, // special characters that can become high-ascii after editing,
// depending upon which editor is used by the developer? // depending upon which editor is used by the developer?
$error_table = array(); $error_table = array();
preg_match('@ALTER\sTABLE\s\`([^\`]+)\`@iu', $the_query, $error_table); if (preg_match('@ALTER\s*TABLE\s*\`([^\`]+)\`@iu', $the_query, $error_table)) {
$error_table = $error_table[1]; $error_table = $error_table[1];
} elseif (preg_match('@INSERT\s*INTO\s*\`([^\`]+)\`@iu', $the_query, $error_table)) {
$error_table = $error_table[1];
} elseif (preg_match('@UPDATE\s*\`([^\`]+)\`@iu', $the_query, $error_table)) {
$error_table = $error_table[1];
} elseif (preg_match('@INSERT\s*\`([^\`]+)\`@iu', $the_query, $error_table)) {
$error_table = $error_table[1];
}
// get fields // get fields
$error_fields = array(); $error_fields = array();
preg_match('@\(([^\)]+)\)@i', $the_query, $error_fields); if (preg_match('@\(([^\)]+)\)@i', $the_query, $error_fields)) {
$error_fields = explode(',', $error_fields[1]); $error_fields = explode(',', $error_fields[1]);
} elseif (preg_match('@(`[^`]+`)\s*=@i', $the_query, $error_fields)) {
$error_fields = explode(',', $error_fields[1]);
}
if (is_array($error_table) || is_array($error_fields)) {
// duplicate value // duplicate value
$duplicate_value = array(); $duplicate_value = array();
preg_match('@\'([^\']+)\'@i', $tmp_mysql_error, $duplicate_value); preg_match('@\'([^\']+)\'@i', $tmp_mysql_error, $duplicate_value);
$duplicate_value = $duplicate_value[1]; $duplicate_value = $duplicate_value[1];
$sql = ' $sql = '
SELECT * SELECT *
FROM ' . PMA_backquote($error_table) . ' FROM ' . PMA_backquote($error_table) . '
WHERE CONCAT_WS("-", ' . implode(', ', $error_fields) . ') WHERE CONCAT_WS("-", ' . implode(', ', $error_fields) . ')
= "' . PMA_sqlAddslashes($duplicate_value) . '" = "' . PMA_sqlAddslashes($duplicate_value) . '"
ORDER BY ' . implode(', ', $error_fields); ORDER BY ' . implode(', ', $error_fields);
unset($error_table, $error_fields, $duplicate_value); unset($error_table, $error_fields, $duplicate_value);
echo ' <form method="post" action="import.php" style="padding: 0; margin: 0">' ."\n" echo ' <form method="post" action="import.php" style="padding: 0; margin: 0">' ."\n"
.' <input type="hidden" name="sql_query" value="' . htmlentities($sql) . '" />' . "\n" .' <input type="hidden" name="sql_query" value="' . htmlentities($sql) . '" />' . "\n"
.' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n" .' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n"
.' <input type="submit" name="submit" value="' . $GLOBALS['strBrowse'] . '" />' . "\n" .' <input type="submit" name="submit" value="' . $GLOBALS['strBrowse'] . '" />' . "\n"
.' </form>' . "\n"; .' </form>' . "\n";
unset($sql); unset($sql);
}
} // end of show duplicate entry } // end of show duplicate entry
echo '</div>'; echo '</div>';
@@ -2768,7 +2780,7 @@ if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
} }
/** /**
* Check whether user supplied token is valid, if not remove any * Check whether user supplied token is valid, if not remove any
* possibly dangerous stuff from request. * possibly dangerous stuff from request.
*/ */
if (!isset($_REQUEST['token']) || $_SESSION['PMA_token'] != $_REQUEST['token']) { if (!isset($_REQUEST['token']) || $_SESSION['PMA_token'] != $_REQUEST['token']) {
@@ -2776,7 +2788,7 @@ if (!isset($_REQUEST['token']) || $_SESSION['PMA_token'] != $_REQUEST['token'])
$allow_list = array( $allow_list = array(
'db', 'table', 'lang', 'server', 'convcharset', 'collation_connection', 'target', 'db', 'table', 'lang', 'server', 'convcharset', 'collation_connection', 'target',
/* Session ID */ /* Session ID */
'phpMyAdmin', 'phpMyAdmin',
/* Cookie preferences */ /* Cookie preferences */
'pma_lang', 'pma_charset', 'pma_collation_connection', 'pma_convcharset', 'pma_lang', 'pma_charset', 'pma_collation_connection', 'pma_convcharset',
/* Possible login form */ /* Possible login form */