From 0d0f0f3094942bc5cb5cf1ddab131c7bf23cd782 Mon Sep 17 00:00:00 2001 From: Michael Keck Date: Mon, 17 Jan 2005 15:21:28 +0000 Subject: [PATCH] modified function for feature request #1036254 --- ChangeLog | 5 +++++ libraries/common.lib.php | 35 +++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec85fcfb1..09b6b9013 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - Changelog $Id$ $Source$ +2005-01-17 Michael Keck + * libraries/common.lib.php: modified function for + Add a link by MySQL-Error #1062 - Duplicate entry + (feature request #1036254) + 2005-01-17 Michal Čihař * lang/czech: Fix typos (translation #1103785). diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 8f8cddfc6..f00c8b22a 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -671,19 +671,30 @@ if ($is_minimum_common == FALSE) { // feature request #1036254: // Add a link by MySQL-Error #1062 - Duplicate entry - // 2004-10-20 by mk.keck + // 2004-10-20 by mkkeck + // 2005-01-17 modified by mkkeck bugfix if (substr($error_message, 1, 4) == '1062') { - // TODO: do not assume that the error message is in English - // and do not use mysql_result() - - // explode the entry and the column - $arr_mysql_val_key = explode('entry \'',$tmp_mysql_error); - $arr_mysql_val_key = explode('\' for key',$arr_mysql_val_key[1]); - // get the duplicate value - $string_duplicate_val = trim(strtolower($arr_mysql_val_key[0])); - // get the field name ... - $string_duplicate_key = mysql_result(mysql_query("SHOW FIELDS FROM " . $table), ($arr_mysql_val_key[1]-1), 0); - $duplicate_sql_query = "SELECT * FROM " . $table . " WHERE " . $string_duplicate_key . " LIKE '" . $string_duplicate_val . "'"; + // get the duplicate entry + $mysql_error_values = array(); + $mysql_error_words = explode(' ',$tmp_mysql_error); + foreach ($mysql_error_words as $mysql_error_word) { + if (strstr($mysql_error_word, "'")) { + $mysql_error_values = explode('-', preg_replace("/'/", "", $mysql_error_word)); + break; // exit 'foreach' + } + } + $duplicate_sql_query = ''; + if (isset($mysql_error_values[0])) { + $tmp_fields = PMA_DBI_get_fields($db, $table, NULL); + foreach ($tmp_fields as $tmp_field) { + $duplicate_sql_query .= (($duplicate_sql_query!='') ? ' OR ' : '') . $tmp_field['Field'] . " LIKE '" . $mysql_error_values[0] . "'"; + } + } + if ($duplicate_sql_query!='') { + $duplicate_sql_query = "SELECT * FROM " . $table . " WHERE (" . $duplicate_sql_query . ")"; + } else { + $duplicate_sql_query = "SELECT * FROM " . $table . ""; + } echo '
' ."\n" . ' ' . "\n" . ' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n"