Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Delisle <marc@infomarc.info>2009-12-30 18:27:27 +0300
committerMarc Delisle <marc@infomarc.info>2009-12-30 18:27:27 +0300
commit87b994743bb8553161699d4ff7845a59da758a60 (patch)
tree540ab878dde6008deab98c24a0638a09af25776f
parentd63ed916fc1fb91adbf158e61297376b0f98477c (diff)
primary_key is really a WHERE clause (that works also on tables where no PK is defined)
-rw-r--r--libraries/display_tbl.lib.php6
-rw-r--r--tbl_change.php56
-rw-r--r--tbl_export.php10
-rw-r--r--tbl_replace.php34
-rw-r--r--tbl_row_action.php29
-rw-r--r--transformation_wrapper.php4
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 '<option value="' . $enum_value['html'] . '"';
if ($data == $enum_value['plain']
|| ($data == ''
- && (! isset($primary_key) || $field['Null'] != 'YES')
+ && (! isset($where_clause) || $field['Null'] != 'YES')
&& isset($field['Default'])
&& $enum_value['plain'] == $field['Default'])) {
echo ' selected="selected"';
@@ -773,7 +771,7 @@ foreach ($rows as $row_id => $vrow) {
echo $unnullify_trigger;
if ($data == $enum_value['plain']
|| ($data == ''
- && (! isset($primary_key) || $field['Null'] != 'YES')
+ && (! isset($where_clause) || $field['Null'] != 'YES')
&& isset($field['Default'])
&& $enum_value['plain'] == $field['Default'])) {
echo ' checked="checked"';
@@ -1101,7 +1099,7 @@ foreach ($rows as $row_id => $vrow) {
<td valign="middle" nowrap="nowrap">
<select name="submit_type" tabindex="<?php echo ($tabindex + $tabindex_for_value + 1); ?>">
<?php
-if (isset($primary_key)) {
+if (isset($where_clause)) {
?>
<option value="<?php echo $strSave; ?>"><?php echo $strSave; ?></option>
<?php
@@ -1125,15 +1123,15 @@ if (!isset($after_insert)) {
<option value="back" <?php echo ($after_insert == 'back' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertBack; ?></option>
<option value="new_insert" <?php echo ($after_insert == 'new_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNewInsert; ?></option>
<?php
-if (isset($primary_key)) {
+if (isset($where_clause)) {
?>
<option value="same_insert" <?php echo ($after_insert == 'same_insert' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertSame; ?></option>
<?php
// If we have just numeric primary key, we can also edit next
// in 2.8.2, we were looking for `field_name` = numeric_value
- //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) {
+ //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
// in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
- if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $primary_key)) {
+ if ($found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause)) {
?>
<option value="edit_next" <?php echo ($after_insert == 'edit_next' ? 'selected="selected"' : ''); ?>><?php echo $strAfterInsertNext; ?></option>
<?php
@@ -1169,9 +1167,9 @@ if ($insert_mode) {
<input type="hidden" name="err_url" value="<?php echo htmlspecialchars($err_url); ?>" />
<input type="hidden" name="sql_query" value="<?php echo htmlspecialchars($sql_query); ?>" />
<?php
- if (isset($primary_keys)) {
- foreach ($primary_key_array as $key_id => $primary_key) {
- echo '<input type="hidden" name="primary_key[' . $key_id . ']" value="' . htmlspecialchars(trim($primary_key)) . '" />'. "\n";
+ if (isset($where_clauses)) {
+ foreach ($where_clause_array as $key_id => $where_clause) {
+ echo '<input type="hidden" name="where_clause[' . $key_id . ']" value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
}
}
$tmp = '<select name="insert_rows" id="insert_rows" onchange="this.form.submit();" >' . "\n";
diff --git a/tbl_export.php b/tbl_export.php
index ed13551cf7..11df4b6f1b 100644
--- a/tbl_export.php
+++ b/tbl_export.php
@@ -31,8 +31,8 @@ if (! empty($sql_query)) {
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
// Need to generate WHERE clause?
- if (isset($primary_key)) {
- // Yes => rebuild query from scracts, this doesn't work with nested
+ if (isset($where_clause)) {
+ // Yes => rebuild query from scratch; this doesn't work with nested
// selects :-(
$sql_query = 'SELECT ';
@@ -48,9 +48,9 @@ if (! empty($sql_query)) {
$wheres = array();
- if (isset($primary_key) && is_array($primary_key)
- && count($primary_key) > 0) {
- $wheres[] = '(' . implode(') OR (',$primary_key) . ')';
+ if (isset($where_clause) && is_array($where_clause)
+ && count($where_clause) > 0) {
+ $wheres[] = '(' . implode(') OR (',$where_clause) . ')';
}
if (!empty($analyzed_sql[0]['where_clause'])) {
diff --git a/tbl_replace.php b/tbl_replace.php
index a3602bfe88..a7da0bc56c 100644
--- a/tbl_replace.php
+++ b/tbl_replace.php
@@ -80,15 +80,15 @@ if (isset($_REQUEST['after_insert'])
//$GLOBALS['goto'] = 'tbl_change.php';
$goto_include = 'tbl_change.php';
- if (isset($_REQUEST['primary_key'])) {
+ if (isset($_REQUEST['where_clause'])) {
if ($_REQUEST['after_insert'] == 'same_insert') {
- foreach ($_REQUEST['primary_key'] as $pk) {
- $url_params['primary_key'][] = $pk;
+ foreach ($_REQUEST['where_clause'] as $one_where_clause) {
+ $url_params['where_clause'][] = $one_where_clause;
}
} elseif ($_REQUEST['after_insert'] == 'edit_next') {
- foreach ($_REQUEST['primary_key'] as $pk) {
+ foreach ($_REQUEST['where_clause'] as $one_where_clause) {
$local_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($GLOBALS['table'])
- . ' WHERE ' . str_replace('` =', '` >', $pk)
+ . ' WHERE ' . str_replace('` =', '` >', $one_where_clause)
. ' LIMIT 1;';
$res = PMA_DBI_query($local_query);
$row = PMA_DBI_fetch_row($res);
@@ -134,9 +134,9 @@ if (isset($_REQUEST['err_url'])) {
/**
* Prepares the update/insert of a row
*/
-if (isset($_REQUEST['primary_key'])) {
- // we were editing something => use primary key
- $loop_array = (is_array($_REQUEST['primary_key']) ? $_REQUEST['primary_key'] : array($_REQUEST['primary_key']));
+if (isset($_REQUEST['where_clause'])) {
+ // we were editing something => use the WHERE clause
+ $loop_array = (is_array($_REQUEST['where_clause']) ? $_REQUEST['where_clause'] : array($_REQUEST['where_clause']));
$using_key = true;
$is_insert = ($_REQUEST['submit_type'] == $GLOBALS['strInsertAsNewRow']);
} else {
@@ -166,9 +166,9 @@ $func_no_param = array(
'CURRENT_USER',
);
-foreach ($loop_array as $rowcount => $primary_key) {
+foreach ($loop_array as $rowcount => $where_clause) {
// skip fields to be ignored
- if (! $using_key && isset($_REQUEST['insert_ignore_' . $primary_key])) {
+ if (! $using_key && isset($_REQUEST['insert_ignore_' . $where_clause])) {
continue;
}
@@ -215,8 +215,8 @@ foreach ($loop_array as $rowcount => $primary_key) {
// Fetch the current values of a row to use in case we have a protected field
// @todo possibly move to ./libraries/tbl_replace_fields.inc.php
- if ($is_insert && $using_key && isset($me_fields_type) && is_array($me_fields_type) && isset($primary_key)) {
- $prot_row = PMA_DBI_fetch_single_row('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';');
+ if ($is_insert && $using_key && isset($me_fields_type) && is_array($me_fields_type) && isset($where_clause)) {
+ $prot_row = PMA_DBI_fetch_single_row('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';');
}
foreach ($me_fields as $key => $val) {
@@ -298,13 +298,13 @@ foreach ($loop_array as $rowcount => $primary_key) {
} else {
// build update query
$query[] = 'UPDATE ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($GLOBALS['table'])
- . ' SET ' . implode(', ', $query_values) . ' WHERE ' . $primary_key . ($_REQUEST['clause_is_unique'] ? '' : ' LIMIT 1');
+ . ' SET ' . implode(', ', $query_values) . ' WHERE ' . $where_clause . ($_REQUEST['clause_is_unique'] ? '' : ' LIMIT 1');
}
}
-} // end foreach ($loop_array as $primary_key)
+} // end foreach ($loop_array as $where_clause)
unset($me_fields_name, $me_fields_prev, $me_funcs, $me_fields_type, $me_fields_null, $me_fields_null_prev,
- $me_auto_increment, $cur_value, $key, $val, $loop_array, $primary_key, $using_key,
+ $me_auto_increment, $cur_value, $key, $val, $loop_array, $where_clause, $using_key,
$func_no_param);
@@ -420,11 +420,11 @@ $active_page = $goto_include;
/**
* If user asked for "and then Insert another new row" we have to remove
- * primary key information so that tbl_change.php does not go back
+ * WHERE clause information so that tbl_change.php does not go back
* to the current record
*/
if (isset($_REQUEST['after_insert']) && 'new_insert' == $_REQUEST['after_insert']) {
- unset($_REQUEST['primary_key']);
+ unset($_REQUEST['where_clause']);
}
/**
diff --git a/tbl_row_action.php b/tbl_row_action.php
index c2204a509d..d72c7d5373 100644
--- a/tbl_row_action.php
+++ b/tbl_row_action.php
@@ -79,13 +79,13 @@ require_once './libraries/header.inc.php';
if (!empty($submit_mult)) {
switch($submit_mult) {
case 'row_edit':
- // garvin: As we got the fields to be edited from the 'rows_to_delete'
- // checkbox, we use the index of it as the
- // indicating primary key. Then we built the array which is used for
- // the tbl_change.php script.
- $primary_key = array();
- foreach ($_REQUEST['rows_to_delete'] as $i_primary_key => $del_query) {
- $primary_key[] = urldecode($i_primary_key);
+ // garvin: As we got the fields to be edited from the
+ // 'rows_to_delete' checkbox, we use the index of it as the
+ // indicating WHERE clause. Then we build the array which is used
+ // for the tbl_change.php script.
+ $where_clause = array();
+ foreach ($_REQUEST['rows_to_delete'] as $i_where_clause => $del_query) {
+ $where_clause[] = urldecode($i_where_clause);
}
$active_page = 'tbl_change.php';
@@ -96,14 +96,13 @@ if (!empty($submit_mult)) {
// Needed to allow SQL export
$single_table = TRUE;
- //$sql_query = urldecode($sql_query);
- // garvin: As we got the fields to be edited from the 'rows_to_delete'
- // checkbox, we use the index of it as the
- // indicating primary key. Then we built the array which is used for
- // the tbl_change.php script.
- $primary_key = array();
- foreach ($_REQUEST['rows_to_delete'] as $i_primary_key => $del_query) {
- $primary_key[] = urldecode($i_primary_key);
+ // garvin: As we got the fields to be edited from the
+ // 'rows_to_delete' checkbox, we use the index of it as the
+ // indicating WHERE clause. Then we build the array which is used
+ // for the tbl_change.php script.
+ $where_clause = array();
+ foreach ($_REQUEST['rows_to_delete'] as $i_where_clause => $del_query) {
+ $where_clause[] = urldecode($i_where_clause);
}
$active_page = 'tbl_export.php';
diff --git a/transformation_wrapper.php b/transformation_wrapper.php
index d79e89de5a..011effeb35 100644
--- a/transformation_wrapper.php
+++ b/transformation_wrapper.php
@@ -30,8 +30,8 @@ require_once './libraries/db_table_exists.lib.php';
*/
PMA_DBI_select_db($db);
$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE);
-if (isset($primary_key)) {
- $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';', null, PMA_DBI_QUERY_STORE);
+if (isset($where_clause)) {
+ $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';', null, PMA_DBI_QUERY_STORE);
$row = PMA_DBI_fetch_assoc($result);
} else {
$result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE);