From 87b994743bb8553161699d4ff7845a59da758a60 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Wed, 30 Dec 2009 15:27:27 +0000 Subject: [PATCH] primary_key is really a WHERE clause (that works also on tables where no PK is defined) --- libraries/display_tbl.lib.php | 6 ++--- tbl_change.php | 56 +++++++++++++++++++++---------------------- tbl_export.php | 10 ++++---- tbl_replace.php | 34 +++++++++++++------------- tbl_row_action.php | 29 +++++++++++----------- transformation_wrapper.php | 4 ++-- 6 files changed, 68 insertions(+), 71 deletions(-) diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 7b5740d62f..80cf9245b5 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -1074,7 +1074,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { } - // 1. Prepares the row (gets primary keys to use) + // 1. Prepares the row // 1.1 Results from a "SELECT" statement -> builds the // WHERE clause to use in links (a unique key if possible) /** @@ -1101,7 +1101,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { $_url_params = array( 'db' => $db, 'table' => $table, - 'primary_key' => $where_clause, + 'where_clause' => $where_clause, 'clause_is_unique' => $clause_is_unique, 'sql_query' => $url_sql_query, 'goto' => 'sql.php', @@ -1239,7 +1239,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { $_url_params = array( 'db' => $db, 'table' => $table, - 'primary_key' => $where_clause, + 'where_clause' => $where_clause, 'transform_key' => $meta->name, ); diff --git a/tbl_change.php b/tbl_change.php index 1e5b3f73ac..c2fb93aa97 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -24,18 +24,14 @@ require_once './libraries/db_table_exists.lib.php'; * Here it's better to use a if, instead of the '?' operator * to avoid setting a variable to '' when it's not present in $_REQUEST */ -/** - * @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']; +if (isset($_REQUEST['where_clause'])) { + $where_clause = $_REQUEST['where_clause']; } if (isset($_REQUEST['clause_is_unique'])) { $clause_is_unique = $_REQUEST['clause_is_unique']; } if (isset($_SESSION['edit_next'])) { - $primary_key = $_SESSION['edit_next']; + $where_clause = $_SESSION['edit_next']; unset($_SESSION['edit_next']); $after_insert = 'edit_next'; } @@ -156,26 +152,28 @@ PMA_DBI_select_db($db); $table_fields = PMA_DBI_fetch_result('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, null, null, PMA_DBI_QUERY_STORE); $rows = array(); -if (isset($primary_key)) { +if (isset($where_clause)) { // when in edit mode load all selected rows from table $insert_mode = false; - if (is_array($primary_key)) { - $primary_key_array = $primary_key; + if (is_array($where_clause)) { + $where_clause_array = $where_clause; } else { - $primary_key_array = array(0 => $primary_key); + $where_clause_array = array(0 => $where_clause); } $result = array(); $found_unique_key = false; - foreach ($primary_key_array as $key_id => $primary_key) { - $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';'; + $where_clauses = array(); + + foreach ($where_clause_array as $key_id => $where_clause) { + $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';'; $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); - $primary_keys[$key_id] = str_replace('\\', '\\\\', $primary_key); + $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); // No row returned if (! $rows[$key_id]) { - unset($rows[$key_id], $primary_key_array[$key_id]); + unset($rows[$key_id], $where_clause_array[$key_id]); PMA_showMessage($strEmptyResultSet, $local_query); echo "\n"; require_once './libraries/footer.inc.php'; @@ -231,9 +229,9 @@ $_form_params = array( 'err_url' => $err_url, 'sql_query' => $sql_query, ); -if (isset($primary_keys)) { - foreach ($primary_key_array as $key_id => $primary_key) { - $_form_params['primary_key[' . $key_id . ']'] = trim($primary_key); +if (isset($where_clauses)) { + foreach ($where_clause_array as $key_id => $where_clause) { + $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause); } } if (isset($clause_is_unique)) { @@ -263,8 +261,8 @@ $biggest_max_file_size = 0; // (currently does not work for multi-edits) $url_params['db'] = $db; $url_params['table'] = $table; -if (isset($primary_key)) { - $url_params['primary_key'] = trim($primary_key); +if (isset($where_clause)) { + $url_params['where_clause'] = trim($where_clause); } if (! empty($sql_query)) { $url_params['sql_query'] = $sql_query; @@ -752,7 +750,7 @@ foreach ($rows as $row_id => $vrow) { echo '