diff --git a/libraries/common.lib.php b/libraries/common.lib.php index cbce236c5..e7f8441c8 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -1848,16 +1848,18 @@ function PMA_checkParameters($params, $die = true, $request = true) * @param integer $fields_cnt number of fields * @param array $fields_meta meta information about fields * @param array $row current row + * @param boolean $force_unique generate condition only on pk or unique * * @access public * @author Michal Cihar (michal@cihar.com) * @return string calculated condition */ -function PMA_getUniqueCondition($handle, $fields_cnt, $fields_meta, $row) +function PMA_getUniqueCondition($handle, $fields_cnt, $fields_meta, $row, $force_unique=false) { $primary_key = ''; $unique_key = ''; $nonprimary_condition = ''; + $preferred_condition = ''; for ($i = 0; $i < $fields_cnt; ++$i) { $condition = ''; @@ -1946,7 +1948,7 @@ function PMA_getUniqueCondition($handle, $fields_cnt, $fields_meta, $row) $preferred_condition = $primary_key; } elseif ($unique_key) { $preferred_condition = $unique_key; - } else { + } elseif (! $force_unique) { $preferred_condition = $nonprimary_condition; } diff --git a/tbl_change.php b/tbl_change.php index 80c33b837..f10de10cb 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -30,6 +30,10 @@ if (isset($_REQUEST['repeat_cells'])) { if (isset($_REQUEST['dontlimitchars'])) { $dontlimitchars = $_REQUEST['dontlimitchars']; } +/** + * @todo this one is badly named, it's really a WHERE condition + * and exists even for tables not having a primary key or unique key + */ if (isset($_REQUEST['primary_key'])) { $primary_key = $_REQUEST['primary_key']; } @@ -140,6 +144,7 @@ if (isset($primary_key)) { $row = array(); $result = array(); + $found_unique_key = false; foreach ($primary_key_array as $rowcount => $primary_key) { $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';'; $result[$rowcount] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); @@ -152,7 +157,13 @@ if (isset($primary_key)) { PMA_showMessage($strEmptyResultSet, $local_query); echo "\n"; require_once './libraries/footer.inc.php'; - } // end if (no record returned) + } else { // end if (no record returned) + $meta = PMA_DBI_get_fields_meta($result[$rowcount]); + if ($tmp = PMA_getUniqueCondition($result[$rowcount], count($meta), $meta, $row[$rowcount], true)) { + $found_unique_key = true; + } + unset($tmp); + } } } else { $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE); @@ -1008,7 +1019,7 @@ if (isset($primary_key)) { // in 2.8.2, we were looking for `field_name` = numeric_value //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) { // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value - if (preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) { + if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) { ?>