From a86ca38f925a39847348fcb794974fc60f4f94c6 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Sun, 6 May 2012 20:01:48 +0530 Subject: [PATCH 01/28] small code refactoring on tbl_change script --- tbl_change.php | 123 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 94 insertions(+), 29 deletions(-) diff --git a/tbl_change.php b/tbl_change.php index d6b46b51a4..f8bb7a0d10 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -153,52 +153,117 @@ unset($show_create_table); PMA_DBI_select_db($db); $table_fields = array_values(PMA_DBI_get_columns($db, $table)); $rows = array(); -if (isset($where_clause)) { - // when in edit mode load all selected rows from table - $insert_mode = false; - if (is_array($where_clause)) { - $where_clause_array = $where_clause; - } else { - $where_clause_array = array(0 => $where_clause); - } +$insertMode_whereClauses_reult = PMA_insert_mode($where_clause, $rows, $table, $db, $cfg); +$insert_mode = $insertMode_whereClauses_reult['insertMode']; +$where_clauses = $insertMode_whereClauses_reult['whereClauses']; +$result = $insertMode_whereClauses_reult['result']; +$rows = $insertMode_whereClauses_reult['rows']; + +/** + * + * @param array $where_clause + * @param array $rows + * @param srting $table + * @param sring $db + * @param array $cfg + * @return type array + */ +function PMA_insert_mode($where_clause, $rows, $table, $db, $cfg) +{ + if (isset($where_clause)) { + // when in edit mode load all selected rows from table + $where_clause_array = PMA_where_clause_array($where_clause); + $where_clauses_and_result = PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db); + return array('insertMode' => false, 'whereClauses' => $where_clauses_and_result['where_clauses'], 'result' =>$where_clauses_and_result['result'], 'rows' => $where_clauses_and_result['rows']); + } else { + $result = PMA_edit_load_first_raw($table, $db, $rows, $cfg); + return array('insertMode' => true, 'result' => $result['result'], 'rows' => $result['rows']); + } +} + +/** + * + * @param array $where_clause + * @return array + */ +function PMA_where_clause_array($where_clause) +{ + if (is_array($where_clause)) { + return $where_clause; + } else { + return array(0 => $where_clause); + } +} + +/** + * + * @param array $where_clause_array + * @param array $rows + * @param string $table + * @param string $db + * @return array + */ +function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db) +{ $result = array(); $found_unique_key = false; $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]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); - - // No row returned - if (! $rows[$key_id]) { - unset($rows[$key_id], $where_clause_array[$key_id]); - PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); - echo "\n"; - include 'libraries/footer.inc.php'; - } else { // end if (no row returned) - $meta = PMA_DBI_get_fields_meta($result[$key_id]); - list($unique_condition, $tmp_clause_is_unique) - = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); - if (! empty($unique_condition)) { - $found_unique_key = true; - } - unset($unique_condition, $tmp_clause_is_unique); - } - + PMA_edit_no_raw_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); } -} else { - // no primary key given, just load first row - but what happens if table is empty? - $insert_mode = true; + return array('whereClauses' => $where_clauses, 'resullt' => $result, 'rows' => $rows); +} + +/** + * + * @param array $rows + * @param string $key_id + * @param array $where_clause_array + * @param string $local_query + * @param array $result + * @param boolean $found_unique_key + */ +function PMA_edit_no_raw_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) +{ + // No row returned + if (! $rows[$key_id]) { + unset($rows[$key_id], $where_clause_array[$key_id]); + PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); + echo "\n"; + include 'libraries/footer.inc.php'; + } else {// end if (no row returned) + $meta = PMA_DBI_get_fields_meta($result[$key_id]); + list($unique_condition, $tmp_clause_is_unique) + = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); + if (! empty($unique_condition)) { + $found_unique_key = true; + } + unset($unique_condition, $tmp_clause_is_unique); + } +} +/** + * + * @param string $table + * @param string $db + * @param array $rows + * @param array $cfg + * @return array + */ +function PMA_edit_load_first_raw($table, $db, $rows, $cfg ) +{ $result = PMA_DBI_query( 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE ); $rows = array_fill(0, $cfg['InsertRows'], false); + return array('result' => $result, 'rows' => $rows); } // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. From 426e4b66dc4131dac8bf97175d0ff17fbd03f1e1 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Mon, 7 May 2012 11:14:28 +0530 Subject: [PATCH 02/28] improve code refactoring on tbl_change script --- tbl_change.php | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/tbl_change.php b/tbl_change.php index f8bb7a0d10..be8965563e 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -154,30 +154,32 @@ PMA_DBI_select_db($db); $table_fields = array_values(PMA_DBI_get_columns($db, $table)); $rows = array(); -$insertMode_whereClauses_reult = PMA_insert_mode($where_clause, $rows, $table, $db, $cfg); -$insert_mode = $insertMode_whereClauses_reult['insertMode']; -$where_clauses = $insertMode_whereClauses_reult['whereClauses']; -$result = $insertMode_whereClauses_reult['result']; -$rows = $insertMode_whereClauses_reult['rows']; +$found_unique_key = false; +$insertMode_whereClauses_result = PMA_edit_and_insert($where_clause, $rows, $table, $db, $cfg, $found_unique_key); +$insert_mode = $insertMode_whereClauses_result['insertMode']; +$where_clauses = $insertMode_whereClauses_result['whereClauses']; +$result = $insertMode_whereClauses_result['result']; +$rows = $insertMode_whereClauses_result['rows']; +$where_clause_array = PMA_where_clause_array($where_clause); /** - * + * phpmyadmin edit row or insert + * * @param array $where_clause * @param array $rows - * @param srting $table - * @param sring $db + * @param string $table + * @param string $db * @param array $cfg * @return type array */ -function PMA_insert_mode($where_clause, $rows, $table, $db, $cfg) +function PMA_edit_and_insert($where_clause, $rows, $table, $db, $cfg, $found_unique_key) { if (isset($where_clause)) { - // when in edit mode load all selected rows from table $where_clause_array = PMA_where_clause_array($where_clause); - $where_clauses_and_result = PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db); - return array('insertMode' => false, 'whereClauses' => $where_clauses_and_result['where_clauses'], 'result' =>$where_clauses_and_result['result'], 'rows' => $where_clauses_and_result['rows']); + $where_clauses_and_result = PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $found_unique_key); + return array('insertMode' => false, 'whereClauses' => $where_clauses_and_result['whereClauses'], 'result' =>$where_clauses_and_result['result'], 'rows' => $where_clauses_and_result['rows']); } else { - $result = PMA_edit_load_first_raw($table, $db, $rows, $cfg); + $result = PMA_edit_load_first_row($table, $db, $rows, $cfg); return array('insertMode' => true, 'result' => $result['result'], 'rows' => $result['rows']); } } @@ -197,17 +199,17 @@ function PMA_where_clause_array($where_clause) } /** - * + * When in edit mode load all selected rows from table + * * @param array $where_clause_array * @param array $rows * @param string $table * @param string $db * @return array */ -function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db) +function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $found_unique_key) { $result = array(); - $found_unique_key = false; $where_clauses = array(); foreach ($where_clause_array as $key_id => $where_clause) { $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) @@ -215,9 +217,9 @@ function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db) $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); - PMA_edit_no_raw_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); + PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); } - return array('whereClauses' => $where_clauses, 'resullt' => $result, 'rows' => $rows); + return array('whereClauses' => $where_clauses, 'result' => $result, 'rows' => $rows); } /** @@ -229,7 +231,7 @@ function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db) * @param array $result * @param boolean $found_unique_key */ -function PMA_edit_no_raw_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) +function PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) { // No row returned if (! $rows[$key_id]) { @@ -247,15 +249,17 @@ function PMA_edit_no_raw_return($rows, $key_id, $where_clause_array, $local_quer unset($unique_condition, $tmp_clause_is_unique); } } + /** - * + * No primary key given, just load first row + * * @param string $table * @param string $db * @param array $rows * @param array $cfg * @return array */ -function PMA_edit_load_first_raw($table, $db, $rows, $cfg ) +function PMA_edit_load_first_row($table, $db, $rows, $cfg ) { $result = PMA_DBI_query( 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', From 4d8069b5b05c95568fd36f3d9d7bc0609250ccaa Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Mon, 7 May 2012 11:31:27 +0530 Subject: [PATCH 03/28] improve code refactoring on tbl_change script-attempt2 --- tbl_change.php | 217 +++++++++++++++++++++++++------------------------ 1 file changed, 109 insertions(+), 108 deletions(-) diff --git a/tbl_change.php b/tbl_change.php index be8965563e..218343ddcd 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -162,114 +162,6 @@ $result = $insertMode_whereClauses_result['result']; $rows = $insertMode_whereClauses_result['rows']; $where_clause_array = PMA_where_clause_array($where_clause); -/** - * phpmyadmin edit row or insert - * - * @param array $where_clause - * @param array $rows - * @param string $table - * @param string $db - * @param array $cfg - * @return type array - */ -function PMA_edit_and_insert($where_clause, $rows, $table, $db, $cfg, $found_unique_key) -{ - if (isset($where_clause)) { - $where_clause_array = PMA_where_clause_array($where_clause); - $where_clauses_and_result = PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $found_unique_key); - return array('insertMode' => false, 'whereClauses' => $where_clauses_and_result['whereClauses'], 'result' =>$where_clauses_and_result['result'], 'rows' => $where_clauses_and_result['rows']); - } else { - $result = PMA_edit_load_first_row($table, $db, $rows, $cfg); - return array('insertMode' => true, 'result' => $result['result'], 'rows' => $result['rows']); - } -} - -/** - * - * @param array $where_clause - * @return array - */ -function PMA_where_clause_array($where_clause) -{ - if (is_array($where_clause)) { - return $where_clause; - } else { - return array(0 => $where_clause); - } -} - -/** - * When in edit mode load all selected rows from table - * - * @param array $where_clause_array - * @param array $rows - * @param string $table - * @param string $db - * @return array - */ -function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $found_unique_key) -{ - $result = array(); - $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]); - $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); - PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); - } - return array('whereClauses' => $where_clauses, 'result' => $result, 'rows' => $rows); -} - -/** - * - * @param array $rows - * @param string $key_id - * @param array $where_clause_array - * @param string $local_query - * @param array $result - * @param boolean $found_unique_key - */ -function PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) -{ - // No row returned - if (! $rows[$key_id]) { - unset($rows[$key_id], $where_clause_array[$key_id]); - PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); - echo "\n"; - include 'libraries/footer.inc.php'; - } else {// end if (no row returned) - $meta = PMA_DBI_get_fields_meta($result[$key_id]); - list($unique_condition, $tmp_clause_is_unique) - = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); - if (! empty($unique_condition)) { - $found_unique_key = true; - } - unset($unique_condition, $tmp_clause_is_unique); - } -} - -/** - * No primary key given, just load first row - * - * @param string $table - * @param string $db - * @param array $rows - * @param array $cfg - * @return array - */ -function PMA_edit_load_first_row($table, $db, $rows, $cfg ) -{ - $result = PMA_DBI_query( - 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', - null, - PMA_DBI_QUERY_STORE - ); - $rows = array_fill(0, $cfg['InsertRows'], false); - return array('result' => $result, 'rows' => $rows); -} - // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. if (isset($default_action) && $default_action === 'insert') { unset($where_clause, $where_clauses); @@ -1219,4 +1111,113 @@ if ($insert_mode) { * Displays the footer */ require 'libraries/footer.inc.php'; + +/** + * phpmyadmin edit row or insert + * + * @param array $where_clause + * @param array $rows + * @param string $table + * @param string $db + * @param array $cfg + * @return type array + */ +function PMA_edit_and_insert($where_clause, $rows, $table, $db, $cfg, $found_unique_key) +{ + if (isset($where_clause)) { + $where_clause_array = PMA_where_clause_array($where_clause); + $where_clauses_and_result = PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $found_unique_key); + return array('insertMode' => false, 'whereClauses' => $where_clauses_and_result['whereClauses'], 'result' =>$where_clauses_and_result['result'], 'rows' => $where_clauses_and_result['rows']); + } else { + $result = PMA_edit_load_first_row($table, $db, $rows, $cfg); + return array('insertMode' => true, 'result' => $result['result'], 'rows' => $result['rows']); + } +} + +/** + * + * @param array $where_clause + * @return array + */ +function PMA_where_clause_array($where_clause) +{ + if (is_array($where_clause)) { + return $where_clause; + } else { + return array(0 => $where_clause); + } +} + +/** + * When in edit mode load all selected rows from table + * + * @param array $where_clause_array + * @param array $rows + * @param string $table + * @param string $db + * @return array + */ +function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $found_unique_key) +{ + $result = array(); + $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]); + $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); + PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); + } + return array('whereClauses' => $where_clauses, 'result' => $result, 'rows' => $rows); +} + +/** + * + * @param array $rows + * @param string $key_id + * @param array $where_clause_array + * @param string $local_query + * @param array $result + * @param boolean $found_unique_key + */ +function PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) +{ + // No row returned + if (! $rows[$key_id]) { + unset($rows[$key_id], $where_clause_array[$key_id]); + PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); + echo "\n"; + include 'libraries/footer.inc.php'; + } else {// end if (no row returned) + $meta = PMA_DBI_get_fields_meta($result[$key_id]); + list($unique_condition, $tmp_clause_is_unique) + = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); + if (! empty($unique_condition)) { + $found_unique_key = true; + } + unset($unique_condition, $tmp_clause_is_unique); + } +} + +/** + * No primary key given, just load first row + * + * @param string $table + * @param string $db + * @param array $rows + * @param array $cfg + * @return array + */ +function PMA_edit_load_first_row($table, $db, $rows, $cfg ) +{ + $result = PMA_DBI_query( + 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', + null, + PMA_DBI_QUERY_STORE + ); + $rows = array_fill(0, $cfg['InsertRows'], false); + return array('result' => $result, 'rows' => $rows); +} + ?> From 6ecaf3e1429a4a0011ba3a913dd55795f00b3cc2 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Mon, 7 May 2012 12:58:56 +0530 Subject: [PATCH 04/28] improve code refactoring on tbl_change script-attempt3 --- tbl_change.php | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/tbl_change.php b/tbl_change.php index 218343ddcd..39504756c2 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -155,11 +155,8 @@ $table_fields = array_values(PMA_DBI_get_columns($db, $table)); $rows = array(); $found_unique_key = false; -$insertMode_whereClauses_result = PMA_edit_and_insert($where_clause, $rows, $table, $db, $cfg, $found_unique_key); -$insert_mode = $insertMode_whereClauses_result['insertMode']; -$where_clauses = $insertMode_whereClauses_result['whereClauses']; -$result = $insertMode_whereClauses_result['result']; -$rows = $insertMode_whereClauses_result['rows']; +$paramArray = array($rows, $table, $db, $cfg); +list($insert_mode, $where_clauses, $result, $rows) = PMA_edit_and_insert($where_clause, $paramArray, $found_unique_key); $where_clause_array = PMA_where_clause_array($where_clause); // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. @@ -170,7 +167,6 @@ if (isset($default_action) && $default_action === 'insert') { // retrieve keys into foreign fields, if any $foreigners = PMA_getForeigners($db, $table); - /** * Displays the form */ @@ -1116,21 +1112,20 @@ require 'libraries/footer.inc.php'; * phpmyadmin edit row or insert * * @param array $where_clause - * @param array $rows - * @param string $table - * @param string $db - * @param array $cfg + * @param array $paramArray + * @param boolean $found_unique_key * @return type array */ -function PMA_edit_and_insert($where_clause, $rows, $table, $db, $cfg, $found_unique_key) +function PMA_edit_and_insert($where_clause, $paramArray, $found_unique_key) { + list($rows, $table, $db, $cfg) = $paramArray; if (isset($where_clause)) { $where_clause_array = PMA_where_clause_array($where_clause); - $where_clauses_and_result = PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $found_unique_key); - return array('insertMode' => false, 'whereClauses' => $where_clauses_and_result['whereClauses'], 'result' =>$where_clauses_and_result['result'], 'rows' => $where_clauses_and_result['rows']); + list($whereClauses, $resultArray, $rowsArray) = PMA_edit_load_all_selected_row($where_clause_array, $paramArray, $found_unique_key); + return array(false, $whereClauses, $resultArray, $rowsArray); } else { - $result = PMA_edit_load_first_row($table, $db, $rows, $cfg); - return array('insertMode' => true, 'result' => $result['result'], 'rows' => $result['rows']); + list($results, $row) = PMA_edit_load_first_row($paramArray); + return array(true, null, $results, $row); } } @@ -1152,13 +1147,13 @@ function PMA_where_clause_array($where_clause) * When in edit mode load all selected rows from table * * @param array $where_clause_array - * @param array $rows - * @param string $table - * @param string $db + * @param array $paramArray + * @param boolean $found_unique_key * @return array */ -function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $found_unique_key) +function PMA_edit_load_all_selected_row($where_clause_array, $paramArray, $found_unique_key) { + list($rows, $table, $db, $cfg) = $paramArray; $result = array(); $where_clauses = array(); foreach ($where_clause_array as $key_id => $where_clause) { @@ -1169,7 +1164,7 @@ function PMA_edit_load_all_selected_row($where_clause_array, $rows, $table, $db, $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); } - return array('whereClauses' => $where_clauses, 'result' => $result, 'rows' => $rows); + return array($where_clauses, $result, $rows); } /** @@ -1203,21 +1198,19 @@ function PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_quer /** * No primary key given, just load first row * - * @param string $table - * @param string $db - * @param array $rows - * @param array $cfg + * @param array $paramArray * @return array */ -function PMA_edit_load_first_row($table, $db, $rows, $cfg ) +function PMA_edit_load_first_row($paramArray ) { + list($rows, $table, $db, $cfg) = $paramArray; $result = PMA_DBI_query( 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE ); $rows = array_fill(0, $cfg['InsertRows'], false); - return array('result' => $result, 'rows' => $rows); + return array($result, $rows); } ?> From 6f6f480f4a4ece882489e1cd5dd80eea9c76c55b Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Mon, 7 May 2012 18:03:19 +0530 Subject: [PATCH 05/28] code refactoring on tbl_change script-attempt4 --- tbl_change.php | 80 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/tbl_change.php b/tbl_change.php index 39504756c2..b77bfc5d7f 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -232,37 +232,19 @@ $biggest_max_file_size = 0; // (currently does not work for multi-edits) $url_params['db'] = $db; $url_params['table'] = $table; -if (isset($where_clause)) { - $url_params['where_clause'] = trim($where_clause); -} -if (! empty($sql_query)) { - $url_params['sql_query'] = $sql_query; -} +$url_params = PMA_edit_url_params($url_params, $where_clause, $sql_query); if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) { echo __('Show'); } + if (! $cfg['ShowFunctionFields']) { - $this_url_params = array_merge( - $url_params, - array( - 'ShowFunctionFields' => 1, - 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], - 'goto' => 'sql.php' - ) - ); - echo ' : ' . __('Function') . '' . "\n"; + list($this_url_params, $common_url) = PMA_edit_show_function_fields($url_params); + echo $common_url; } + if (! $cfg['ShowFieldTypesInDataEditView']) { - $this_other_url_params = array_merge( - $url_params, - array( - 'ShowFieldTypesInDataEditView' => 1, - 'ShowFunctionFields' => $cfg['ShowFunctionFields'], - 'goto' => 'sql.php' - ) - ); - echo ' : ' . __('Type') . '' . "\n"; + echo PMA_Show_field_types_in_data_edit_view($url_params); } foreach ($rows as $row_id => $vrow) { @@ -1213,4 +1195,54 @@ function PMA_edit_load_first_row($paramArray ) return array($result, $rows); } +/** + * Add some url parameters + * + * @param array $url_params + * @param array $where_clause + * @param array $sql_query + * @return array + */ +function PMA_edit_url_params($url_params, $where_clause, $sql_query) +{ + if (isset($where_clause)) { + $url_params['where_clause'] = trim($where_clause); + } + if (! empty($sql_query)) { + $url_params['sql_query'] = $sql_query; + } + return $url_params; +} + +/** + * + * @param array $url_params + * @return string + */ +function PMA_edit_show_function_fields($url_params) +{ + $params = array( + 'ShowFunctionFields' => 1, + 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], + 'goto' => 'sql.php'); + $this_url_params = array_merge($url_params, $params); + $return_value = ' : ' . __('Function') . '' . "\n"; + return array($this_url_params, $return_value); +} + +/** + * + * @param array $url_params + * @return stirng + */ +function PMA_Show_field_types_in_data_edit_view($url_params) +{ + $params = array( + 'ShowFieldTypesInDataEditView' => 1, + 'ShowFunctionFields' => $cfg['ShowFunctionFields'], + 'goto' => 'sql.php'); + $this_other_url_params = array_merge($url_params, $params); + return ' : ' . __('Type') . '' . "\n"; +} + ?> From db738b1debc871155ececa14a39bcfe52f9bbb2e Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Tue, 8 May 2012 00:48:17 +0530 Subject: [PATCH 06/28] code improvement in tbl_change script --- tbl_change.php | 160 +++++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 77 deletions(-) diff --git a/tbl_change.php b/tbl_change.php index b77bfc5d7f..3404e92373 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -35,9 +35,6 @@ if (isset($_SESSION['edit_next'])) { unset($_SESSION['edit_next']); $after_insert = 'edit_next'; } -if (isset($_REQUEST['sql_query'])) { - $sql_query = $_REQUEST['sql_query']; -} if (isset($_REQUEST['ShowFunctionFields'])) { $cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields']; } @@ -74,7 +71,7 @@ if (empty($GLOBALS['goto'])) { */ $_url_params = array( 'db' => $db, - 'sql_query' => $sql_query + 'sql_query' => $_REQUEST['sql_query'] ); if (preg_match('@^tbl_@', $GLOBALS['goto'])) { @@ -155,9 +152,8 @@ $table_fields = array_values(PMA_DBI_get_columns($db, $table)); $rows = array(); $found_unique_key = false; -$paramArray = array($rows, $table, $db, $cfg); -list($insert_mode, $where_clauses, $result, $rows) = PMA_edit_and_insert($where_clause, $paramArray, $found_unique_key); -$where_clause_array = PMA_where_clause_array($where_clause); +$paramArray = array($rows, $table, $db); +list($insert_mode, $where_clauses, $result, $rows, $where_clause_array) = PMA_loadAllSelectedRowInEditMode($paramArray, $found_unique_key); // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. if (isset($default_action) && $default_action === 'insert') { @@ -194,7 +190,7 @@ $_form_params = array( 'table' => $table, 'goto' => $GLOBALS['goto'], 'err_url' => $err_url, - 'sql_query' => $sql_query, + 'sql_query' => $_REQUEST['sql_query'], ); if (isset($where_clauses)) { foreach ($where_clause_array as $key_id => $where_clause) { @@ -232,19 +228,18 @@ $biggest_max_file_size = 0; // (currently does not work for multi-edits) $url_params['db'] = $db; $url_params['table'] = $table; -$url_params = PMA_edit_url_params($url_params, $where_clause, $sql_query); +$url_params = PMA_urlParamsInEditMode($url_params, $cfg); if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) { echo __('Show'); } if (! $cfg['ShowFunctionFields']) { - list($this_url_params, $common_url) = PMA_edit_show_function_fields($url_params); - echo $common_url; + echo PMA_showFunctionFieldsInEditMode($url_params, $cfg); } if (! $cfg['ShowFieldTypesInDataEditView']) { - echo PMA_Show_field_types_in_data_edit_view($url_params); + echo PMA_showFieldTypesInDataEditView($url_params, $cfg); } foreach ($rows as $row_id => $vrow) { @@ -267,31 +262,14 @@ foreach ($rows as $row_id => $vrow) { - 0, - 'ShowFunctionFields' => $cfg['ShowFunctionFields'], - 'goto' => 'sql.php' - ) - ); - echo ' ' . __('Type') . '' . "\n"; - } - - if ($cfg['ShowFunctionFields']) { - $this_url_params = array_merge( - $url_params, - array( - 'ShowFunctionFields' => 0, - 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], - 'goto' => 'sql.php' - ) - ); - echo ' ' . __('Function') . '' . "\n"; - } -?> + @@ -1063,7 +1041,7 @@ if ($insert_mode) { - + $where_clause) { @@ -1093,35 +1071,35 @@ require 'libraries/footer.inc.php'; /** * phpmyadmin edit row or insert * - * @param array $where_clause * @param array $paramArray * @param boolean $found_unique_key - * @return type array + * @return array */ -function PMA_edit_and_insert($where_clause, $paramArray, $found_unique_key) +function PMA_loadAllSelectedRowInEditMode($paramArray, $found_unique_key) { - list($rows, $table, $db, $cfg) = $paramArray; - if (isset($where_clause)) { - $where_clause_array = PMA_where_clause_array($where_clause); - list($whereClauses, $resultArray, $rowsArray) = PMA_edit_load_all_selected_row($where_clause_array, $paramArray, $found_unique_key); - return array(false, $whereClauses, $resultArray, $rowsArray); + list($rows, $table, $db) = $paramArray; + if (isset($_REQUEST['where_clause'])) { + $where_clause_array = PMA_getWhereClauseArray(); + list($whereClauses, $resultArray, $rowsArray) = PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_unique_key); + return array(false, $whereClauses, $resultArray, $rowsArray, $where_clause_array); } else { - list($results, $row) = PMA_edit_load_first_row($paramArray); - return array(true, null, $results, $row); + list($results, $row) = PMA_loadFirstRowInEditMode($paramArray); + return array(true, null, $results, $row, null); } } /** * - * @param array $where_clause - * @return array + * @return whereClauseArray */ -function PMA_where_clause_array($where_clause) +function PMA_getWhereClauseArray() { - if (is_array($where_clause)) { - return $where_clause; - } else { - return array(0 => $where_clause); + if(isset ($_REQUEST['where_clause'])) { + if (is_array($_REQUEST['where_clause'])) { + return $_REQUEST['where_clause']; + } else { + return array(0 => $_REQUEST['where_clause']); + } } } @@ -1131,11 +1109,11 @@ function PMA_where_clause_array($where_clause) * @param array $where_clause_array * @param array $paramArray * @param boolean $found_unique_key - * @return array + * @return array $where_clauses, $result, $rows */ -function PMA_edit_load_all_selected_row($where_clause_array, $paramArray, $found_unique_key) +function PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_unique_key) { - list($rows, $table, $db, $cfg) = $paramArray; + list($rows, $table, $db) = $paramArray; $result = array(); $where_clauses = array(); foreach ($where_clause_array as $key_id => $where_clause) { @@ -1144,7 +1122,7 @@ function PMA_edit_load_all_selected_row($where_clause_array, $paramArray, $found $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); - PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); + PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); } return array($where_clauses, $result, $rows); } @@ -1158,7 +1136,7 @@ function PMA_edit_load_all_selected_row($where_clause_array, $paramArray, $found * @param array $result * @param boolean $found_unique_key */ -function PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) +function PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) { // No row returned if (! $rows[$key_id]) { @@ -1183,15 +1161,15 @@ function PMA_edit_no_row_return($rows, $key_id, $where_clause_array, $local_quer * @param array $paramArray * @return array */ -function PMA_edit_load_first_row($paramArray ) +function PMA_loadFirstRowInEditMode($paramArray ) { - list($rows, $table, $db, $cfg) = $paramArray; + list($rows, $table, $db) = $paramArray; $result = PMA_DBI_query( 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE ); - $rows = array_fill(0, $cfg['InsertRows'], false); + $rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false); return array($result, $rows); } @@ -1199,17 +1177,15 @@ function PMA_edit_load_first_row($paramArray ) * Add some url parameters * * @param array $url_params - * @param array $where_clause - * @param array $sql_query * @return array */ -function PMA_edit_url_params($url_params, $where_clause, $sql_query) +function PMA_urlParamsInEditMode($url_params) { - if (isset($where_clause)) { - $url_params['where_clause'] = trim($where_clause); + if (isset($_REQUEST['where_clause'])) { + $url_params['where_clause'] = trim($_REQUEST['where_clause']); } - if (! empty($sql_query)) { - $url_params['sql_query'] = $sql_query; + if (! empty($_REQUEST['sql_query'])) { + $url_params['sql_query'] = $_REQUEST['sql_query']; } return $url_params; } @@ -1219,15 +1195,14 @@ function PMA_edit_url_params($url_params, $where_clause, $sql_query) * @param array $url_params * @return string */ -function PMA_edit_show_function_fields($url_params) +function PMA_showFunctionFieldsInEditMode($url_params) { $params = array( 'ShowFunctionFields' => 1, - 'ShowFieldTypesInDataEditView' => $cfg['ShowFieldTypesInDataEditView'], + 'ShowFieldTypesInDataEditView' => $GLOBALS['cfg']['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'); $this_url_params = array_merge($url_params, $params); - $return_value = ' : ' . __('Function') . '' . "\n"; - return array($this_url_params, $return_value); + return ' : ' . __('Function') . '' . "\n"; } /** @@ -1235,14 +1210,45 @@ function PMA_edit_show_function_fields($url_params) * @param array $url_params * @return stirng */ -function PMA_Show_field_types_in_data_edit_view($url_params) +function PMA_showFieldTypesInDataEditView($url_params) { $params = array( 'ShowFieldTypesInDataEditView' => 1, - 'ShowFunctionFields' => $cfg['ShowFunctionFields'], + 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], 'goto' => 'sql.php'); $this_other_url_params = array_merge($url_params, $params); return ' : ' . __('Type') . '' . "\n"; } - + + /** + * + * @param array $url_params + * @return string + */ + function PMA_fieldTypesInDataEditView($url_params) + { + $params = array( + 'ShowFieldTypesInDataEditView' => 0, + 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], + 'goto' => 'sql.php' + ); + $this_url_params = array_merge($url_params, $params); + return ' ' . __('Type') . '' . "\n"; + } + + /** + * + * @param array $url_params + * @return string + */ + function PMA_functionFfiledsInEditView($url_params) + { + $params = array( + 'ShowFieldTypesInDataEditView' => 0, + 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], + 'goto' => 'sql.php' + ); + $this_url_params = array_merge($url_params, $params); + return ' ' . __('Type') . '' . "\n"; + } ?> From 6c1601bc81007ee269aa01753b0b9a1e657dcb63 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Tue, 8 May 2012 18:41:19 +0530 Subject: [PATCH 07/28] add libraries-insert_edit-lib file --- libraries/insert_edit.lib.php | 192 ++++++++++++++++++++++++++++++++++ tbl_change.php | 188 +-------------------------------- 2 files changed, 197 insertions(+), 183 deletions(-) create mode 100644 libraries/insert_edit.lib.php diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php new file mode 100644 index 0000000000..2457ccc992 --- /dev/null +++ b/libraries/insert_edit.lib.php @@ -0,0 +1,192 @@ + $_REQUEST['where_clause']); + } + } +} + +/** + * When in edit mode load all selected rows from table + * + * @param array $where_clause_array + * @param array $paramArray + * @param boolean $found_unique_key + * @return array $where_clauses, $result, $rows + */ +function PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_unique_key) +{ + list($rows, $table, $db) = $paramArray; + $result = array(); + $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]); + $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); + PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); + } + return array($where_clauses, $result, $rows); +} + +/** + * + * @param array $rows + * @param string $key_id + * @param array $where_clause_array + * @param string $local_query + * @param array $result + * @param boolean $found_unique_key + */ +function PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) +{ + // No row returned + if (! $rows[$key_id]) { + unset($rows[$key_id], $where_clause_array[$key_id]); + PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); + echo "\n"; + include 'libraries/footer.inc.php'; + } else {// end if (no row returned) + $meta = PMA_DBI_get_fields_meta($result[$key_id]); + list($unique_condition, $tmp_clause_is_unique) + = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); + if (! empty($unique_condition)) { + $found_unique_key = true; + } + unset($unique_condition, $tmp_clause_is_unique); + } +} + +/** + * No primary key given, just load first row + * + * @param array $paramArray + * @return array + */ +function PMA_loadFirstRowInEditMode($paramArray ) +{ + list($rows, $table, $db) = $paramArray; + $result = PMA_DBI_query( + 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', + null, + PMA_DBI_QUERY_STORE + ); + $rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false); + return array($result, $rows); +} + +/** + * Add some url parameters + * + * @param array $url_params + * @return array + */ +function PMA_urlParamsInEditMode($url_params) +{ + if (isset($_REQUEST['where_clause'])) { + $url_params['where_clause'] = trim($_REQUEST['where_clause']); + } + if (! empty($_REQUEST['sql_query'])) { + $url_params['sql_query'] = $_REQUEST['sql_query']; + } + return $url_params; +} + +/** + * + * @param array $url_params + * @return string + */ +function PMA_showFunctionFieldsInEditMode($url_params) +{ + $params = array( + 'ShowFunctionFields' => 1, + 'ShowFieldTypesInDataEditView' => $GLOBALS['cfg']['ShowFieldTypesInDataEditView'], + 'goto' => 'sql.php'); + $this_url_params = array_merge($url_params, $params); + return ' : ' . __('Function') . '' . "\n"; +} + +/** + * + * @param array $url_params + * @return stirng + */ +function PMA_showFieldTypesInDataEditView($url_params) +{ + $params = array( + 'ShowFieldTypesInDataEditView' => 1, + 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], + 'goto' => 'sql.php'); + $this_other_url_params = array_merge($url_params, $params); + return ' : ' . __('Type') . '' . "\n"; +} + + /** + * + * @param array $url_params + * @return string + */ + function PMA_fieldTypesInDataEditView($url_params) + { + $params = array( + 'ShowFieldTypesInDataEditView' => 0, + 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], + 'goto' => 'sql.php' + ); + $this_url_params = array_merge($url_params, $params); + return ' ' . __('Type') . '' . "\n"; + } + + /** + * + * @param array $url_params + * @return string + */ + function PMA_functionFfiledsInEditView($url_params) + { + $params = array( + 'ShowFieldTypesInDataEditView' => 0, + 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], + 'goto' => 'sql.php' + ); + $this_url_params = array_merge($url_params, $params); + return ' ' . __('Type') . '' . "\n"; + } +?> diff --git a/tbl_change.php b/tbl_change.php index 3404e92373..f87cbf928c 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -19,6 +19,11 @@ require_once 'libraries/common.lib.php'; */ require_once 'libraries/db_table_exists.lib.php'; +/** + * functions implementation for this script + */ +require_once 'libraries/insert_edit.lib.php'; + /** * Sets global variables. * Here it's better to use a if, instead of the '?' operator @@ -1068,187 +1073,4 @@ if ($insert_mode) { */ require 'libraries/footer.inc.php'; -/** - * phpmyadmin edit row or insert - * - * @param array $paramArray - * @param boolean $found_unique_key - * @return array - */ -function PMA_loadAllSelectedRowInEditMode($paramArray, $found_unique_key) -{ - list($rows, $table, $db) = $paramArray; - if (isset($_REQUEST['where_clause'])) { - $where_clause_array = PMA_getWhereClauseArray(); - list($whereClauses, $resultArray, $rowsArray) = PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_unique_key); - return array(false, $whereClauses, $resultArray, $rowsArray, $where_clause_array); - } else { - list($results, $row) = PMA_loadFirstRowInEditMode($paramArray); - return array(true, null, $results, $row, null); - } -} - -/** - * - * @return whereClauseArray - */ -function PMA_getWhereClauseArray() -{ - if(isset ($_REQUEST['where_clause'])) { - if (is_array($_REQUEST['where_clause'])) { - return $_REQUEST['where_clause']; - } else { - return array(0 => $_REQUEST['where_clause']); - } - } -} - -/** - * When in edit mode load all selected rows from table - * - * @param array $where_clause_array - * @param array $paramArray - * @param boolean $found_unique_key - * @return array $where_clauses, $result, $rows - */ -function PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_unique_key) -{ - list($rows, $table, $db) = $paramArray; - $result = array(); - $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]); - $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); - PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); - } - return array($where_clauses, $result, $rows); -} - -/** - * - * @param array $rows - * @param string $key_id - * @param array $where_clause_array - * @param string $local_query - * @param array $result - * @param boolean $found_unique_key - */ -function PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) -{ - // No row returned - if (! $rows[$key_id]) { - unset($rows[$key_id], $where_clause_array[$key_id]); - PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); - echo "\n"; - include 'libraries/footer.inc.php'; - } else {// end if (no row returned) - $meta = PMA_DBI_get_fields_meta($result[$key_id]); - list($unique_condition, $tmp_clause_is_unique) - = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); - if (! empty($unique_condition)) { - $found_unique_key = true; - } - unset($unique_condition, $tmp_clause_is_unique); - } -} - -/** - * No primary key given, just load first row - * - * @param array $paramArray - * @return array - */ -function PMA_loadFirstRowInEditMode($paramArray ) -{ - list($rows, $table, $db) = $paramArray; - $result = PMA_DBI_query( - 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', - null, - PMA_DBI_QUERY_STORE - ); - $rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false); - return array($result, $rows); -} - -/** - * Add some url parameters - * - * @param array $url_params - * @return array - */ -function PMA_urlParamsInEditMode($url_params) -{ - if (isset($_REQUEST['where_clause'])) { - $url_params['where_clause'] = trim($_REQUEST['where_clause']); - } - if (! empty($_REQUEST['sql_query'])) { - $url_params['sql_query'] = $_REQUEST['sql_query']; - } - return $url_params; -} - -/** - * - * @param array $url_params - * @return string - */ -function PMA_showFunctionFieldsInEditMode($url_params) -{ - $params = array( - 'ShowFunctionFields' => 1, - 'ShowFieldTypesInDataEditView' => $GLOBALS['cfg']['ShowFieldTypesInDataEditView'], - 'goto' => 'sql.php'); - $this_url_params = array_merge($url_params, $params); - return ' : ' . __('Function') . '' . "\n"; -} - -/** - * - * @param array $url_params - * @return stirng - */ -function PMA_showFieldTypesInDataEditView($url_params) -{ - $params = array( - 'ShowFieldTypesInDataEditView' => 1, - 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], - 'goto' => 'sql.php'); - $this_other_url_params = array_merge($url_params, $params); - return ' : ' . __('Type') . '' . "\n"; -} - - /** - * - * @param array $url_params - * @return string - */ - function PMA_fieldTypesInDataEditView($url_params) - { - $params = array( - 'ShowFieldTypesInDataEditView' => 0, - 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], - 'goto' => 'sql.php' - ); - $this_url_params = array_merge($url_params, $params); - return ' ' . __('Type') . '' . "\n"; - } - - /** - * - * @param array $url_params - * @return string - */ - function PMA_functionFfiledsInEditView($url_params) - { - $params = array( - 'ShowFieldTypesInDataEditView' => 0, - 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], - 'goto' => 'sql.php' - ); - $this_url_params = array_merge($url_params, $params); - return ' ' . __('Type') . '' . "\n"; - } ?> From 1d7f48b966c66b06f9a9ef6e5c78178d645d4bdf Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Wed, 9 May 2012 01:23:23 +0530 Subject: [PATCH 08/28] improve code refactoring in tbl_changes --- libraries/insert_edit.lib.php | 106 +++++++++++++++++++--------------- tbl_change.php | 41 ++++--------- 2 files changed, 70 insertions(+), 77 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 2457ccc992..b28b9ae546 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -7,22 +7,22 @@ /** - * phpmyadmin edit row or insert + * Retrive the values for pma edit mode * * @param array $paramArray * @param boolean $found_unique_key * @return array */ -function PMA_loadAllSelectedRowInEditMode($paramArray, $found_unique_key) +function PMA_getValuesForEditMode($paramArray, $found_unique_key) { list($rows, $table, $db) = $paramArray; if (isset($_REQUEST['where_clause'])) { $where_clause_array = PMA_getWhereClauseArray(); - list($whereClauses, $resultArray, $rowsArray) = PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_unique_key); - return array(false, $whereClauses, $resultArray, $rowsArray, $where_clause_array); + list($whereClauses, $resultArray, $rowsArray, $foundUniqueKey) = PMA_analysWhereClauses($where_clause_array, $paramArray, $found_unique_key); + return array(false, $whereClauses, $resultArray, $rowsArray, $where_clause_array, $foundUniqueKey); } else { list($results, $row) = PMA_loadFirstRowInEditMode($paramArray); - return array(true, null, $results, $row, null); + return array(true, null, $results, $row, null, $found_unique_key); } } @@ -42,14 +42,14 @@ function PMA_getWhereClauseArray() } /** - * When in edit mode load all selected rows from table + * Analysing where cluases array * * @param array $where_clause_array * @param array $paramArray * @param boolean $found_unique_key * @return array $where_clauses, $result, $rows */ -function PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_unique_key) +function PMA_analysWhereClauses($where_clause_array, $paramArray, $found_unique_key) { list($rows, $table, $db) = $paramArray; $result = array(); @@ -60,13 +60,14 @@ function PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_uniqu $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); - PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); + $found_unique_key = PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key); } - return array($where_clauses, $result, $rows); + return array($where_clauses, $result, $rows, $found_unique_key); } /** - * + * Show message for empty reult or set the unique_condition + * * @param array $rows * @param string $key_id * @param array $where_clause_array @@ -74,7 +75,7 @@ function PMA_whereClausesAnalyses($where_clause_array, $paramArray, $found_uniqu * @param array $result * @param boolean $found_unique_key */ -function PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) +function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, $where_clause_array, $local_query, $result, $found_unique_key) { // No row returned if (! $rows[$key_id]) { @@ -91,6 +92,7 @@ function PMA_noRowReturnInEditMode($rows, $key_id, $where_clause_array, $local_q } unset($unique_condition, $tmp_clause_is_unique); } + return $found_unique_key; } /** @@ -133,14 +135,22 @@ function PMA_urlParamsInEditMode($url_params) * @param array $url_params * @return string */ -function PMA_showFunctionFieldsInEditMode($url_params) +function PMA_showFunctionFieldsInEditMode($url_params, $notShowFuncFields) { + if($notShowFuncFields) { + $val = 1; + } else { + $val = 0; + } $params = array( - 'ShowFunctionFields' => 1, + 'ShowFunctionFields' => $val, 'ShowFieldTypesInDataEditView' => $GLOBALS['cfg']['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'); $this_url_params = array_merge($url_params, $params); - return ' : ' . __('Function') . '' . "\n"; + if($notShowFuncFields) { + return ' : ' . __('Function') . '' . "\n"; + } + return ' ' . __('Function') . '' . "\n"; } /** @@ -148,45 +158,49 @@ function PMA_showFunctionFieldsInEditMode($url_params) * @param array $url_params * @return stirng */ -function PMA_showFieldTypesInDataEditView($url_params) +function PMA_showFieldTypesInDataEditView($url_params, $notShowFieldType) { + if($notShowFieldType) { + $val = 1; + } else { + $val = 0; + } $params = array( - 'ShowFieldTypesInDataEditView' => 1, + 'ShowFieldTypesInDataEditView' => $val, 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], 'goto' => 'sql.php'); $this_other_url_params = array_merge($url_params, $params); - return ' : ' . __('Type') . '' . "\n"; + if($notShowFieldType) { + return ' : ' . __('Type') . '' . "\n"; + } + return ' ' . __('Type') . '' . "\n"; + } - - /** - * - * @param array $url_params - * @return string - */ - function PMA_fieldTypesInDataEditView($url_params) + + function PMA_getDefaultForDatetime($table_fields) { - $params = array( - 'ShowFieldTypesInDataEditView' => 0, - 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], - 'goto' => 'sql.php' - ); - $this_url_params = array_merge($url_params, $params); - return ' ' . __('Type') . '' . "\n"; + // d a t e t i m e + // + // Current date should not be set as default if the field is NULL + // for the current row, but do not put here the current datetime + // if there is a default value (the real default value will be set + // in the Default value logic below) + + // Note: (tested in MySQL 4.0.16): when lang is some UTF-8, + // $field['Default'] is not set if it contains NULL: + // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime) + // but, look what we get if we switch to iso: (Default is NULL) + // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime) + // so I force a NULL into it (I don't think it's possible + // to have an empty default value for DATETIME) + // then, the "if" after this one will work + if ($table_fields['Type'] == 'datetime' + && ! isset($table_fields['Default']) + && isset($table_fields['Null']) + && $table_fields['Null'] == 'YES' + ) { + $table_fields['Default'] = null; + } } - /** - * - * @param array $url_params - * @return string - */ - function PMA_functionFfiledsInEditView($url_params) - { - $params = array( - 'ShowFieldTypesInDataEditView' => 0, - 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], - 'goto' => 'sql.php' - ); - $this_url_params = array_merge($url_params, $params); - return ' ' . __('Type') . '' . "\n"; - } ?> diff --git a/tbl_change.php b/tbl_change.php index f87cbf928c..220ecc4e88 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -158,7 +158,8 @@ $rows = array(); $found_unique_key = false; $paramArray = array($rows, $table, $db); -list($insert_mode, $where_clauses, $result, $rows, $where_clause_array) = PMA_loadAllSelectedRowInEditMode($paramArray, $found_unique_key); +list($insert_mode, $where_clauses, $result, $rows, $where_clause_array, $found_unique_key) + = PMA_getValuesForEditMode($paramArray, $found_unique_key); // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. if (isset($default_action) && $default_action === 'insert') { @@ -233,18 +234,18 @@ $biggest_max_file_size = 0; // (currently does not work for multi-edits) $url_params['db'] = $db; $url_params['table'] = $table; -$url_params = PMA_urlParamsInEditMode($url_params, $cfg); +$url_params = PMA_urlParamsInEditMode($url_params); if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) { echo __('Show'); } if (! $cfg['ShowFunctionFields']) { - echo PMA_showFunctionFieldsInEditMode($url_params, $cfg); + echo PMA_showFunctionFieldsInEditMode($url_params, true); } if (! $cfg['ShowFieldTypesInDataEditView']) { - echo PMA_showFieldTypesInDataEditView($url_params, $cfg); + echo PMA_showFieldTypesInDataEditView($url_params, true); } foreach ($rows as $row_id => $vrow) { @@ -269,10 +270,10 @@ foreach ($rows as $row_id => $vrow) { @@ -300,32 +301,10 @@ foreach ($rows as $row_id => $vrow) { $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']); // True_Type contains only the type (stops at first bracket) $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']); + + PMA_getDefaultForDatetime($table_fields[$i]); - // d a t e t i m e - // - // Current date should not be set as default if the field is NULL - // for the current row, but do not put here the current datetime - // if there is a default value (the real default value will be set - // in the Default value logic below) - - // Note: (tested in MySQL 4.0.16): when lang is some UTF-8, - // $field['Default'] is not set if it contains NULL: - // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime) - // but, look what we get if we switch to iso: (Default is NULL) - // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime) - // so I force a NULL into it (I don't think it's possible - // to have an empty default value for DATETIME) - // then, the "if" after this one will work - if ($table_fields[$i]['Type'] == 'datetime' - && ! isset($table_fields[$i]['Default']) - && isset($table_fields[$i]['Null']) - && $table_fields[$i]['Null'] == 'YES' - ) { - $table_fields[$i]['Default'] = null; - } - - $table_fields[$i]['len'] - = preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1; + $table_fields[$i]['len'] = preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1; if (isset($comments_map[$table_fields[$i]['Field']])) { From b2338b7154fbcab47678970c3b3118b1bd9412d9 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Thu, 10 May 2012 11:56:04 +0530 Subject: [PATCH 09/28] code improvement in tbl_change and libraries-insert_edit_lib --- libraries/insert_edit.lib.php | 58 +++++++++++++++++++++-------------- tbl_change.php | 14 ++++----- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index b28b9ae546..37cd50a3ce 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -1,25 +1,31 @@ $where_clause) { @@ -103,7 +110,7 @@ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, $where_c */ function PMA_loadFirstRowInEditMode($paramArray ) { - list($rows, $table, $db) = $paramArray; + list($table, $db) = $paramArray; $result = PMA_DBI_query( 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;', null, @@ -131,52 +138,57 @@ function PMA_urlParamsInEditMode($url_params) } /** - * + * Show function fields in data edit view in pma + * * @param array $url_params * @return string */ -function PMA_showFunctionFieldsInEditMode($url_params, $notShowFuncFields) +function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields) { - if($notShowFuncFields) { - $val = 1; + if(!$showFuncFields) { + $params = array('ShowFunctionFields' => 1); } else { - $val = 0; + $params = array('ShowFunctionFields' => 0); } $params = array( - 'ShowFunctionFields' => $val, 'ShowFieldTypesInDataEditView' => $GLOBALS['cfg']['ShowFieldTypesInDataEditView'], 'goto' => 'sql.php'); $this_url_params = array_merge($url_params, $params); - if($notShowFuncFields) { + if(!$showFuncFields) { return ' : ' . __('Function') . '' . "\n"; } return ' ' . __('Function') . '' . "\n"; } /** - * + * Show field types in data edit view in pma + * * @param array $url_params * @return stirng */ -function PMA_showFieldTypesInDataEditView($url_params, $notShowFieldType) +function PMA_showColumnTypesInDataEditView($url_params, $showColumnType ) { - if($notShowFieldType) { - $val = 1; + if(!$showColumnType) { + $params = array('ShowFieldTypesInDataEditView' => 1); } else { - $val = 0; + $params = array('ShowFieldTypesInDataEditView' => 0); } $params = array( - 'ShowFieldTypesInDataEditView' => $val, 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], 'goto' => 'sql.php'); $this_other_url_params = array_merge($url_params, $params); - if($notShowFieldType) { + if(!$showColumnType) { return ' : ' . __('Type') . '' . "\n"; } return ' ' . __('Type') . '' . "\n"; } +/** + * Retrieve the default for datetime data type + * + * @param array $table_fields + */ function PMA_getDefaultForDatetime($table_fields) { // d a t e t i m e diff --git a/tbl_change.php b/tbl_change.php index 220ecc4e88..1cbe34f442 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -154,12 +154,10 @@ unset($show_create_table); */ PMA_DBI_select_db($db); $table_fields = array_values(PMA_DBI_get_columns($db, $table)); -$rows = array(); -$found_unique_key = false; -$paramArray = array($rows, $table, $db); +$paramArray = array($table, $db); list($insert_mode, $where_clauses, $result, $rows, $where_clause_array, $found_unique_key) - = PMA_getValuesForEditMode($paramArray, $found_unique_key); + = PMA_getValuesForEditMode($paramArray); // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. if (isset($default_action) && $default_action === 'insert') { @@ -241,11 +239,11 @@ if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) { } if (! $cfg['ShowFunctionFields']) { - echo PMA_showFunctionFieldsInEditMode($url_params, true); + echo PMA_showFunctionFieldsInEditMode($url_params, false); } if (! $cfg['ShowFieldTypesInDataEditView']) { - echo PMA_showFieldTypesInDataEditView($url_params, true); + echo PMA_showColumnTypesInDataEditView($url_params, false); } foreach ($rows as $row_id => $vrow) { @@ -270,10 +268,10 @@ foreach ($rows as $row_id => $vrow) { From 798ccce1510eb4f3503175c00c4e60ced62a7e2e Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Thu, 10 May 2012 14:00:54 +0530 Subject: [PATCH 10/28] code refactoring for insert form in tbl_change --- libraries/insert_edit.lib.php | 182 ++++++++++++++++++++++++++++++++-- tbl_change.php | 106 ++------------------ 2 files changed, 180 insertions(+), 108 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 37cd50a3ce..8f39f8e2f1 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -10,6 +10,34 @@ if (! defined('PHPMYADMIN')) { exit; } +/** + * Retrieve form parameters for insert/edit form + * + * @param array $where_clauses + * @param array $where_clause_array + * @return array $_form_params + */ +function PMA_getFormParametersForInsertForm($paramArray, $where_clauses, $where_clause_array, $err_url) +{ + list($table, $db) = $paramArray; + $_form_params = array( + 'db' => $db, + 'table' => $table, + 'goto' => $GLOBALS['goto'], + 'err_url' => $err_url, + 'sql_query' => $_REQUEST['sql_query'], + ); + if (isset($where_clauses)) { + foreach ($where_clause_array as $key_id => $where_clause) { + $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause); + } + } + if (isset($_REQUEST['clause_is_unique'])) { + $_form_params['clause_is_unique'] = $_REQUEST['clause_is_unique']; + } + return $_form_params; +} + /** * Retrieve the values for pma edit mode * @@ -189,8 +217,8 @@ function PMA_showColumnTypesInDataEditView($url_params, $showColumnType ) * * @param array $table_fields */ - function PMA_getDefaultForDatetime($table_fields) - { +function PMA_getDefaultForDatetime($field) +{ // d a t e t i m e // // Current date should not be set as default if the field is NULL @@ -206,13 +234,151 @@ function PMA_showColumnTypesInDataEditView($url_params, $showColumnType ) // so I force a NULL into it (I don't think it's possible // to have an empty default value for DATETIME) // then, the "if" after this one will work - if ($table_fields['Type'] == 'datetime' - && ! isset($table_fields['Default']) - && isset($table_fields['Null']) - && $table_fields['Null'] == 'YES' + if ($field['Type'] == 'datetime' + && ! isset($field['Default']) + && isset($field['Null']) + && $field['Null'] == 'YES' ) { - $table_fields['Default'] = null; + $field['Default'] = null; } - } +} + /** + * Analyze the table fields array + * + * @param array $field + * @param array $comments_map + * @return type + */ +function PMA_analyzeTableFieldsArray($field, $comments_map, $timestamp_seen) +{ + $field['Field_html'] = htmlspecialchars($field['Field']); + $field['Field_md5'] = md5($field['Field']); + // True_Type contains only the type (stops at first bracket) + $field['True_Type'] = preg_replace('@\(.*@s', '', $field['Type']); + PMA_getDefaultForDatetime($field); + $field['len'] = preg_match('@float|double@', $field['Type']) ? 100 : -1; + $field['Field_title'] = PMA_getFieldTitle($field, $comments_map); + $field['is_binary'] = PMA_isTableFieldBinary($field); + $field['is_blob'] = PMA_istableFieldBlob($field); + $field['is_char'] = PMA_isTablefieldChar($field); + list($field['pma_type'], $field['wrap'], $field['first_timestamp']) = + PMA_getEnumSetAndTimestampTableFields($field, $timestamp_seen); + + return $field; +} + + /** + * Retrieve the field title + * + * @param array $field + * @param array $comments_map + * @return string + */ +function PMA_getFieldTitle($field, $comments_map) +{ + if (isset($comments_map[$field['Field']])) { + return '' + . $field['Field_html'] . ''; + } else { + return $field['Field_html']; + } +} + + /** + * check is table field bainary + * + * @param array $field + * @return boolean + */ +function PMA_isTableFieldBinary($field) +{ + // The type column. + // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option' + // If check to ensure types such as "enum('one','two','binary',..)" or + // "enum('one','two','varbinary',..)" are not categorized as binary. + if (stripos($field['Type'], 'binary') === 0 + || stripos($field['Type'], 'varbinary') === 0 + ) { + return stristr($field['Type'], 'binary'); + } else { + return false; + } + +} + + /** + * check is table field blob + * + * @param array $field + * @return boolean + */ +function PMA_istableFieldBlob($field) +{ + // If check to ensure types such as "enum('one','two','blob',..)" or + // "enum('one','two','tinyblob',..)" etc. are not categorized as blob. + if (stripos($field['Type'], 'blob') === 0 + || stripos($field['Type'], 'tinyblob') === 0 + || stripos($field['Type'], 'mediumblob') === 0 + || stripos($field['Type'], 'longblob') === 0 + ) { + return stristr($field['Type'], 'blob'); + } else { + return false; + } +} + +/** + * check is table field char + * + * @param array $field + * @return boolean + */ +function PMA_isTablefieldChar($field) +{ + // If check to ensure types such as "enum('one','two','char',..)" or + // "enum('one','two','varchar',..)" are not categorized as char. + if (stripos($field['Type'], 'char') === 0 + || stripos($field['Type'], 'varchar') === 0 + ) { + return stristr($field['Type'], 'char'); + } else { + return false; + } +} +/** + * Retieve set, enum, timestamp tbale fields + * + * @param array $field + * @param int $timestamp_seen + */ +function PMA_getEnumSetAndTimestampTableFields($field, $timestamp_seen) +{ + $field['first_timestamp'] = false; + switch ($field['True_Type']) { + case 'set': + $field['pma_type'] = 'set'; + $field['wrap'] = ''; + break; + case 'enum': + $field['pma_type'] = 'enum'; + $field['wrap'] = ''; + break; + case 'timestamp': + if (!$timestamp_seen) { // can only occur once per table + $timestamp_seen = 1; + $field['first_timestamp'] = true; + } + $field['pma_type'] = $field['Type']; + $field['wrap'] = ' nowrap'; + break; + + default: + $field['pma_type'] = $field['Type']; + $field['wrap'] = ' nowrap'; + break; + } + return array($field['pma_type'], $field['wrap'], $field['first_timestamp']); +} ?> diff --git a/tbl_change.php b/tbl_change.php index 1cbe34f442..b4a783f88b 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -32,9 +32,6 @@ require_once 'libraries/insert_edit.lib.php'; 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'])) { $where_clause = $_SESSION['edit_next']; unset($_SESSION['edit_next']); @@ -167,6 +164,9 @@ if (isset($default_action) && $default_action === 'insert') { // retrieve keys into foreign fields, if any $foreigners = PMA_getForeigners($db, $table); +// Retrieve form parameters for insert/edit form +$_form_params = PMA_getFormParametersForInsertForm($paramArray, $where_clauses, $where_clause_array, $err_url); + /** * Displays the form */ @@ -187,25 +187,6 @@ var switch_movement = 0; document.onkeydown = onKeyDownArrowsHandler; //]]> - $db, - 'table' => $table, - 'goto' => $GLOBALS['goto'], - 'err_url' => $err_url, - 'sql_query' => $_REQUEST['sql_query'], -); -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)) { - $_form_params['clause_is_unique'] = $clause_is_unique; -} - -?>
$vrow) { - $vrow) { $odd_row = true; for ($i = 0; $i < $fields_cnt; $i++) { if (! isset($table_fields[$i]['processed'])) { - $table_fields[$i]['Field_html'] = htmlspecialchars($table_fields[$i]['Field']); - $table_fields[$i]['Field_md5'] = md5($table_fields[$i]['Field']); - // True_Type contains only the type (stops at first bracket) - $table_fields[$i]['True_Type'] = preg_replace('@\(.*@s', '', $table_fields[$i]['Type']); - - PMA_getDefaultForDatetime($table_fields[$i]); - - $table_fields[$i]['len'] = preg_match('@float|double@', $table_fields[$i]['Type']) ? 100 : -1; - - - if (isset($comments_map[$table_fields[$i]['Field']])) { - $table_fields[$i]['Field_title'] = '' - . $table_fields[$i]['Field_html'] . ''; - } else { - $table_fields[$i]['Field_title'] = $table_fields[$i]['Field_html']; - } - - // The type column. - // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option' - // If check to ensure types such as "enum('one','two','binary',..)" or - // "enum('one','two','varbinary',..)" are not categorized as binary. - if (stripos($table_fields[$i]['Type'], 'binary') === 0 - || stripos($table_fields[$i]['Type'], 'varbinary') === 0 - ) { - $table_fields[$i]['is_binary'] = stristr($table_fields[$i]['Type'], 'binary'); - } else { - $table_fields[$i]['is_binary'] = false; - } - - // If check to ensure types such as "enum('one','two','blob',..)" or - // "enum('one','two','tinyblob',..)" etc. are not categorized as blob. - if (stripos($table_fields[$i]['Type'], 'blob') === 0 - || stripos($table_fields[$i]['Type'], 'tinyblob') === 0 - || stripos($table_fields[$i]['Type'], 'mediumblob') === 0 - || stripos($table_fields[$i]['Type'], 'longblob') === 0 - ) { - $table_fields[$i]['is_blob'] = stristr($table_fields[$i]['Type'], 'blob'); - } else { - $table_fields[$i]['is_blob'] = false; - } - - // If check to ensure types such as "enum('one','two','char',..)" or - // "enum('one','two','varchar',..)" are not categorized as char. - if (stripos($table_fields[$i]['Type'], 'char') === 0 - || stripos($table_fields[$i]['Type'], 'varchar') === 0 - ) { - $table_fields[$i]['is_char'] = stristr($table_fields[$i]['Type'], 'char'); - } else { - $table_fields[$i]['is_char'] = false; - } - - $table_fields[$i]['first_timestamp'] = false; - switch ($table_fields[$i]['True_Type']) { - case 'set': - $table_fields[$i]['pma_type'] = 'set'; - $table_fields[$i]['wrap'] = ''; - break; - case 'enum': - $table_fields[$i]['pma_type'] = 'enum'; - $table_fields[$i]['wrap'] = ''; - break; - case 'timestamp': - if (!$timestamp_seen) { // can only occur once per table - $timestamp_seen = 1; - $table_fields[$i]['first_timestamp'] = true; - } - $table_fields[$i]['pma_type'] = $table_fields[$i]['Type']; - $table_fields[$i]['wrap'] = ' nowrap'; - break; - - default: - $table_fields[$i]['pma_type'] = $table_fields[$i]['Type']; - $table_fields[$i]['wrap'] = ' nowrap'; - break; - } + $field = $table_fields[$i]; + $field = PMA_analyzeTableFieldsArray($field, $comments_map, $timestamp_seen); } - $field = $table_fields[$i]; + $extracted_columnspec = PMA_extractColumnSpec($field['Type']); if (-1 === $field['len']) { From 954e200b207d60f712b6d0aa2817222c04335af2 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Thu, 10 May 2012 21:59:46 +0530 Subject: [PATCH 11/28] code refactoring for insertForm --- libraries/insert_edit.lib.php | 109 +++++++++++++++++++++++++++++++++- tbl_change.php | 84 ++++---------------------- 2 files changed, 121 insertions(+), 72 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 8f39f8e2f1..1003684fb7 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -348,7 +348,7 @@ function PMA_isTablefieldChar($field) } } /** - * Retieve set, enum, timestamp tbale fields + * Retieve set, enum, timestamp table fields * * @param array $field * @param int $timestamp_seen @@ -381,4 +381,111 @@ function PMA_getEnumSetAndTimestampTableFields($field, $timestamp_seen) } return array($field['pma_type'], $field['wrap'], $field['first_timestamp']); } + +/** + * The function column + * We don't want binary data to be destroyed + * Note: from the MySQL manual: "BINARY doesn't affect how the column is + * stored or retrieved" so it does not mean that the contents is binary + * + * @param array $params_for_function_column + * @return string $html_output + */ +function PMA_getFunctionColumn($params_for_function_column) +{ + list($field, $is_upload, $field_name_appendix, $unnullify_trigger, + $no_support_types, $tabindex, $tabindex_for_function, + $idindex, $insert_mode) = $params_for_function_column; + + $html_output = ''; + if (($GLOBALS['cfg']['ProtectBinary'] && $field['is_blob'] && !$is_upload) + || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $field['is_binary']) + || ($GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$field['is_blob']) + ) { + $html_output .= ' ' . __('Binary') . '' . "\n"; + } elseif (strstr($field['True_Type'], 'enum') + || strstr($field['True_Type'], 'set') + || in_array($field['pma_type'], $no_support_types) + ) { + $html_output .= ' --' . "\n"; + } else { + $html_output .= '' . "\n"; + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + } + $html_output .= ' ' . "\n"; + + return $html_output; +} + +/** + * Retrieve the nullify code for the null column + * + * @param array $field + * @param array $foreigners + * @param array $foreignData + * @return integer + */ +function PMA_getNullifyCodeForNullColumn($field, $foreigners, $foreignData) +{ + if (strstr($field['True_Type'], 'enum')) { + if (strlen($field['Type']) > 20) { + $nullify_code = '1'; + } else { + $nullify_code = '2'; + } + } elseif (strstr($field['True_Type'], 'set')) { + $nullify_code = '3'; + } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) { + // foreign key in a drop-down + $nullify_code = '4'; + } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) { + // foreign key with a browsing icon + $nullify_code = '6'; + } else { + $nullify_code = '5'; + } + return $nullify_code; +} ?> diff --git a/tbl_change.php b/tbl_change.php index b4a783f88b..d97b8a5f02 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -311,8 +311,9 @@ foreach ($rows as $row_id => $vrow) { - - + + + $vrow) { // Get a list of data types that are not yet supported. $no_support_types = PMA_unsupportedDatatypes(); + $params_for_function_column = array( + $field, $is_upload, $field_name_appendix, $unnullify_trigger, + $no_support_types, $tabindex, $tabindex_for_function, + $idindex, $insert_mode); // The function column // ------------------- - // We don't want binary data to be destroyed - // Note: from the MySQL manual: "BINARY doesn't affect how the column is - // stored or retrieved" so it does not mean that the contents is - // binary if ($cfg['ShowFunctionFields']) { - if (($cfg['ProtectBinary'] && $field['is_blob'] && !$is_upload) - || ($cfg['ProtectBinary'] == 'all' && $field['is_binary']) - || ($cfg['ProtectBinary'] == 'noblob' && !$field['is_blob']) - ) { - echo ' ' . __('Binary') . '' . "\n"; - } elseif (strstr($field['True_Type'], 'enum') - || strstr($field['True_Type'], 'set') - || in_array($field['pma_type'], $no_support_types) - ) { - echo ' --' . "\n"; - } else { - ?> - - - - ' . "\n"; - if ($field['Null'] == 'YES') { - echo ' ' . "\n"; - - echo ' '; - - // nullify_code is needed by the js nullify() function - if (strstr($field['True_Type'], 'enum')) { - if (strlen($field['Type']) > 20) { - $nullify_code = '1'; - } else { - $nullify_code = '2'; - } - } elseif (strstr($field['True_Type'], 'set')) { - $nullify_code = '3'; - } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) { - // foreign key in a drop-down - $nullify_code = '4'; - } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) { - // foreign key with a browsing icon - $nullify_code = '6'; - } else { - $nullify_code = '5'; - } - // to be able to generate calls to nullify() in jQuery - echo ''; - echo ''; - echo ''; - } - echo ' ' . "\n"; + $params_for_null_column = array( + $field, $field_name_appendix, $real_null_value, $tabindex, $tabindex_for_null, + $idindex, $vkey, $foreigners, $foreignData); + echo PMA_getNullColumn($params_for_null_column); // The value column (depends on type) // ---------------- From 9745dbb386a016cd171fd373ee8ff564082aad49 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Fri, 11 May 2012 07:04:27 +0530 Subject: [PATCH 12/28] code improvement insert_edit-lib --- libraries/insert_edit.lib.php | 68 ++++++++++++++++++----------------- tbl_change.php | 9 ++--- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 1003684fb7..fab304e486 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -86,6 +86,7 @@ function PMA_getWhereClauseArray() function PMA_analyzeWhereClauses($where_clause_array, $paramArray, $found_unique_key) { list($table, $db) = $paramArray; + var_dump($paramArray); $rows = array(); $result = array(); $where_clauses = array(); @@ -173,16 +174,16 @@ function PMA_urlParamsInEditMode($url_params) */ function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields) { - if(!$showFuncFields) { - $params = array('ShowFunctionFields' => 1); + $params = array(); + if(! $showFuncFields) { + $params['ShowFunctionFields'] = 1; } else { - $params = array('ShowFunctionFields' => 0); + $params['ShowFunctionFields'] = 0; } - $params = array( - 'ShowFieldTypesInDataEditView' => $GLOBALS['cfg']['ShowFieldTypesInDataEditView'], - 'goto' => 'sql.php'); + $params['ShowFieldTypesInDataEditView'] = $GLOBALS['cfg']['ShowFieldTypesInDataEditView']; + $params['goto'] = 'sql.php'; $this_url_params = array_merge($url_params, $params); - if(!$showFuncFields) { + if(! $showFuncFields) { return ' : ' . __('Function') . '' . "\n"; } return ' ' . __('Function') . '' . "\n"; @@ -196,16 +197,16 @@ function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields) */ function PMA_showColumnTypesInDataEditView($url_params, $showColumnType ) { - if(!$showColumnType) { - $params = array('ShowFieldTypesInDataEditView' => 1); + $params = array(); + if(! $showColumnType) { + $params['ShowFieldTypesInDataEditView'] = 1; } else { - $params = array('ShowFieldTypesInDataEditView' => 0); + $params['ShowFieldTypesInDataEditView'] = 0; } - $params = array( - 'ShowFunctionFields' => $GLOBALS['cfg']['ShowFunctionFields'], - 'goto' => 'sql.php'); + $params['ShowFunctionFields'] = $GLOBALS['cfg']['ShowFunctionFields']; + $params['goto'] = 'sql.php'; $this_other_url_params = array_merge($url_params, $params); - if(!$showColumnType) { + if(! $showColumnType) { return ' : ' . __('Type') . '' . "\n"; } return ' ' . __('Type') . '' . "\n"; @@ -244,13 +245,13 @@ function PMA_getDefaultForDatetime($field) } /** - * Analyze the table fields array + * Analyze the table column array * * @param array $field * @param array $comments_map * @return type */ -function PMA_analyzeTableFieldsArray($field, $comments_map, $timestamp_seen) +function PMA_analyzeTableColumnsArray($field, $comments_map, $timestamp_seen) { $field['Field_html'] = htmlspecialchars($field['Field']); $field['Field_md5'] = md5($field['Field']); @@ -258,24 +259,24 @@ function PMA_analyzeTableFieldsArray($field, $comments_map, $timestamp_seen) $field['True_Type'] = preg_replace('@\(.*@s', '', $field['Type']); PMA_getDefaultForDatetime($field); $field['len'] = preg_match('@float|double@', $field['Type']) ? 100 : -1; - $field['Field_title'] = PMA_getFieldTitle($field, $comments_map); - $field['is_binary'] = PMA_isTableFieldBinary($field); - $field['is_blob'] = PMA_istableFieldBlob($field); - $field['is_char'] = PMA_isTablefieldChar($field); + $field['Field_title'] = PMA_getColumnTitle($field, $comments_map); + $field['is_binary'] = PMA_isTableColumnBinary($field); + $field['is_blob'] = PMA_istableColumnBlob($field); + $field['is_char'] = PMA_isTableColumnChar($field); list($field['pma_type'], $field['wrap'], $field['first_timestamp']) = - PMA_getEnumSetAndTimestampTableFields($field, $timestamp_seen); + PMA_getEnumSetAndTimestampTableColumns($field, $timestamp_seen); return $field; } /** - * Retrieve the field title + * Retrieve the column title * * @param array $field * @param array $comments_map * @return string */ -function PMA_getFieldTitle($field, $comments_map) +function PMA_getColumnTitle($field, $comments_map) { if (isset($comments_map[$field['Field']])) { return ''; + $html_output .= PMA_getFunctionsForField($field, $insert_mode) . "\n"; $html_output .= '' . "\n"; $html_output .= '' . "\n"; } @@ -429,6 +430,7 @@ function PMA_getNullColumn($params_for_null_column) { list($field, $field_name_appendix, $real_null_value, $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData) = $params_for_null_column; + $html_output = ''; $html_output .= ' ' . "\n"; if ($field['Null'] == 'YES') { $html_output .= ' $vrow) { for ($i = 0; $i < $fields_cnt; $i++) { if (! isset($table_fields[$i]['processed'])) { $field = $table_fields[$i]; - $field = PMA_analyzeTableFieldsArray($field, $comments_map, $timestamp_seen); + $field = PMA_analyzeTableColumnsArray($field, $comments_map, $timestamp_seen); } $extracted_columnspec = PMA_extractColumnSpec($field['Type']); From b1b57f7131b2dc0e740df5d3d9639a9551721c18 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Mon, 14 May 2012 06:22:48 +0530 Subject: [PATCH 13/28] code refactoring for value column in insert form --- libraries/insert_edit.lib.php | 845 ++++++++++++++++++++++++++++++---- tbl_change.php | 275 ++++++----- 2 files changed, 884 insertions(+), 236 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index fab304e486..0f3a1eb71d 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -86,7 +86,6 @@ function PMA_getWhereClauseArray() function PMA_analyzeWhereClauses($where_clause_array, $paramArray, $found_unique_key) { list($table, $db) = $paramArray; - var_dump($paramArray); $rows = array(); $result = array(); $where_clauses = array(); @@ -218,7 +217,7 @@ function PMA_showColumnTypesInDataEditView($url_params, $showColumnType ) * * @param array $table_fields */ -function PMA_getDefaultForDatetime($field) +function PMA_getDefaultForDatetime($column) { // d a t e t i m e // @@ -228,81 +227,81 @@ function PMA_getDefaultForDatetime($field) // in the Default value logic below) // Note: (tested in MySQL 4.0.16): when lang is some UTF-8, - // $field['Default'] is not set if it contains NULL: + // $column['Default'] is not set if it contains NULL: // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Extra] => [True_Type] => datetime) // but, look what we get if we switch to iso: (Default is NULL) // Array ([Field] => d [Type] => datetime [Null] => YES [Key] => [Default] => [Extra] => [True_Type] => datetime) // so I force a NULL into it (I don't think it's possible // to have an empty default value for DATETIME) // then, the "if" after this one will work - if ($field['Type'] == 'datetime' - && ! isset($field['Default']) - && isset($field['Null']) - && $field['Null'] == 'YES' + if ($column['Type'] == 'datetime' + && ! isset($column['Default']) + && isset($column['Null']) + && $column['Null'] == 'YES' ) { - $field['Default'] = null; + $column['Default'] = null; } } /** * Analyze the table column array * - * @param array $field + * @param array $column * @param array $comments_map * @return type */ -function PMA_analyzeTableColumnsArray($field, $comments_map, $timestamp_seen) +function PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen) { - $field['Field_html'] = htmlspecialchars($field['Field']); - $field['Field_md5'] = md5($field['Field']); + $column['Field_html'] = htmlspecialchars($column['Field']); + $column['Field_md5'] = md5($column['Field']); // True_Type contains only the type (stops at first bracket) - $field['True_Type'] = preg_replace('@\(.*@s', '', $field['Type']); - PMA_getDefaultForDatetime($field); - $field['len'] = preg_match('@float|double@', $field['Type']) ? 100 : -1; - $field['Field_title'] = PMA_getColumnTitle($field, $comments_map); - $field['is_binary'] = PMA_isTableColumnBinary($field); - $field['is_blob'] = PMA_istableColumnBlob($field); - $field['is_char'] = PMA_isTableColumnChar($field); - list($field['pma_type'], $field['wrap'], $field['first_timestamp']) = - PMA_getEnumSetAndTimestampTableColumns($field, $timestamp_seen); + $column['True_Type'] = preg_replace('@\(.*@s', '', $column['Type']); + PMA_getDefaultForDatetime($column); + $column['len'] = preg_match('@float|double@', $column['Type']) ? 100 : -1; + $column['Field_title'] = PMA_getColumnTitle($column, $comments_map); + $column['is_binary'] = PMA_isColumnBinary($column); + $column['is_blob'] = PMA_isColumnBlob($column); + $column['is_char'] = PMA_isColumnChar($column); + list($column['pma_type'], $column['wrap'], $column['first_timestamp']) = + PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen); - return $field; + return $column; } /** * Retrieve the column title * - * @param array $field + * @param array $column * @param array $comments_map * @return string */ -function PMA_getColumnTitle($field, $comments_map) +function PMA_getColumnTitle($column, $comments_map) { - if (isset($comments_map[$field['Field']])) { + if (isset($comments_map[$column['Field']])) { return '' - . $field['Field_html'] . ''; + . htmlspecialchars($comments_map[$column['Field']]) . '">' + . $column['Field_html'] . ''; } else { - return $field['Field_html']; + return $column['Field_html']; } } /** * check is table column bainary * - * @param array $field + * @param array $column * @return boolean */ -function PMA_isTableColumnBinary($field) +function PMA_isColumnBinary($column) { // The type column. // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option' // If check to ensure types such as "enum('one','two','binary',..)" or // "enum('one','two','varbinary',..)" are not categorized as binary. - if (stripos($field['Type'], 'binary') === 0 - || stripos($field['Type'], 'varbinary') === 0 + if (stripos($column['Type'], 'binary') === 0 + || stripos($column['Type'], 'varbinary') === 0 ) { - return stristr($field['Type'], 'binary'); + return stristr($column['Type'], 'binary'); } else { return false; } @@ -312,19 +311,19 @@ function PMA_isTableColumnBinary($field) /** * check is table column blob * - * @param array $field + * @param array $column * @return boolean */ -function PMA_istableColumnBlob($field) +function PMA_isColumnBlob($column) { // If check to ensure types such as "enum('one','two','blob',..)" or // "enum('one','two','tinyblob',..)" etc. are not categorized as blob. - if (stripos($field['Type'], 'blob') === 0 - || stripos($field['Type'], 'tinyblob') === 0 - || stripos($field['Type'], 'mediumblob') === 0 - || stripos($field['Type'], 'longblob') === 0 + if (stripos($column['Type'], 'blob') === 0 + || stripos($column['Type'], 'tinyblob') === 0 + || stripos($column['Type'], 'mediumblob') === 0 + || stripos($column['Type'], 'longblob') === 0 ) { - return stristr($field['Type'], 'blob'); + return stristr($column['Type'], 'blob'); } else { return false; } @@ -333,17 +332,17 @@ function PMA_istableColumnBlob($field) /** * check is table column char * - * @param array $field + * @param array $column * @return boolean */ -function PMA_isTableColumnChar($field) +function PMA_isColumnChar($column) { // If check to ensure types such as "enum('one','two','char',..)" or // "enum('one','two','varchar',..)" are not categorized as char. - if (stripos($field['Type'], 'char') === 0 - || stripos($field['Type'], 'varchar') === 0 + if (stripos($column['Type'], 'char') === 0 + || stripos($column['Type'], 'varchar') === 0 ) { - return stristr($field['Type'], 'char'); + return stristr($column['Type'], 'char'); } else { return false; } @@ -351,36 +350,36 @@ function PMA_isTableColumnChar($field) /** * Retieve set, enum, timestamp table columns * - * @param array $field + * @param array $column * @param int $timestamp_seen */ -function PMA_getEnumSetAndTimestampTableColumns($field, $timestamp_seen) +function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen) { - $field['first_timestamp'] = false; - switch ($field['True_Type']) { + $column['first_timestamp'] = false; + switch ($column['True_Type']) { case 'set': - $field['pma_type'] = 'set'; - $field['wrap'] = ''; + $column['pma_type'] = 'set'; + $column['wrap'] = ''; break; case 'enum': - $field['pma_type'] = 'enum'; - $field['wrap'] = ''; + $column['pma_type'] = 'enum'; + $column['wrap'] = ''; break; case 'timestamp': if (!$timestamp_seen) { // can only occur once per table $timestamp_seen = 1; - $field['first_timestamp'] = true; + $column['first_timestamp'] = true; } - $field['pma_type'] = $field['Type']; - $field['wrap'] = ' nowrap'; + $column['pma_type'] = $column['Type']; + $column['wrap'] = ' nowrap'; break; default: - $field['pma_type'] = $field['Type']; - $field['wrap'] = ' nowrap'; + $column['pma_type'] = $column['Type']; + $column['wrap'] = ' nowrap'; break; } - return array($field['pma_type'], $field['wrap'], $field['first_timestamp']); + return array($column['pma_type'], $column['wrap'], $column['first_timestamp']); } /** @@ -389,31 +388,37 @@ function PMA_getEnumSetAndTimestampTableColumns($field, $timestamp_seen) * Note: from the MySQL manual: "BINARY doesn't affect how the column is * stored or retrieved" so it does not mean that the contents is binary * - * @param array $params_for_function_column - * @return string $html_output + * @param array $column + * @param boolean $is_upload + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param array $no_support_types + * @param integer $tabindex_for_function + * @param integer $tabindex + * @param integer $idindex + * @param boolean $insert_mode + * @return string */ -function PMA_getFunctionColumn($params_for_function_column) -{ - list($field, $is_upload, $field_name_appendix, $unnullify_trigger, - $no_support_types, $tabindex, $tabindex_for_function, - $idindex, $insert_mode) = $params_for_function_column; - +function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, + $unnullify_trigger, $no_support_types, $tabindex_for_function, + $tabindex, $idindex, $insert_mode +) { $html_output = ''; - if (($GLOBALS['cfg']['ProtectBinary'] && $field['is_blob'] && !$is_upload) - || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $field['is_binary']) - || ($GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$field['is_blob']) + if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'] && !$is_upload) + || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $column['is_binary']) + || ($GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$column['is_blob']) ) { $html_output .= ' ' . __('Binary') . '' . "\n"; - } elseif (strstr($field['True_Type'], 'enum') - || strstr($field['True_Type'], 'set') - || in_array($field['pma_type'], $no_support_types) + } elseif (strstr($column['True_Type'], 'enum') + || strstr($column['True_Type'], 'set') + || in_array($column['pma_type'], $no_support_types) ) { $html_output .= ' --' . "\n"; } else { $html_output .= '' . "\n"; - $html_output .= '' . "\n"; $html_output .= '' . "\n"; } @@ -423,38 +428,45 @@ function PMA_getFunctionColumn($params_for_function_column) /** * The null column * - * @param array $params_for_null_column - * @return string $html_output + * @param array $column + * @param string $column_name_appendix + * @param array $real_null_value + * @param integer $tabindex + * @param integer $tabindex_for_null + * @param integer $idindex + * @param array $vkey + * @param array $foreigners + * @param array $foreignData + * @return string */ -function PMA_getNullColumn($params_for_null_column) -{ - list($field, $field_name_appendix, $real_null_value, $tabindex, $tabindex_for_null, - $idindex, $vkey, $foreigners, $foreignData) = $params_for_null_column; +function PMA_getNullColumn($column, $column_name_appendix, $real_null_value, + $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData +) { $html_output = ''; $html_output .= ' ' . "\n"; - if ($field['Null'] == 'YES') { - $html_output .= ' '; // nullify_code is needed by the js nullify() function - $nullify_code = PMA_getNullifyCodeForNullColumn($field, $foreigners, $foreignData); + $nullify_code = PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData); // to be able to generate calls to nullify() in jQuery $html_output .= ''; + . $column_name_appendix . '" value="' . $nullify_code . '" />'; $html_output .= ''; + . $column_name_appendix . '" value="' . $column['Field_md5'] . '" />'; $html_output .= ''; + . $column_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />'; } $html_output .= ' ' . "\n"; @@ -464,25 +476,25 @@ function PMA_getNullColumn($params_for_null_column) /** * Retrieve the nullify code for the null column * - * @param array $field + * @param array $column * @param array $foreigners * @param array $foreignData * @return integer */ -function PMA_getNullifyCodeForNullColumn($field, $foreigners, $foreignData) +function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData) { - if (strstr($field['True_Type'], 'enum')) { - if (strlen($field['Type']) > 20) { + if (strstr($column['True_Type'], 'enum')) { + if (strlen($column['Type']) > 20) { $nullify_code = '1'; } else { $nullify_code = '2'; } - } elseif (strstr($field['True_Type'], 'set')) { + } elseif (strstr($column['True_Type'], 'set')) { $nullify_code = '3'; - } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == false) { + } elseif ($foreigners && isset($foreigners[$column['Field']]) && $foreignData['foreign_link'] == false) { // foreign key in a drop-down $nullify_code = '4'; - } elseif ($foreigners && isset($foreigners[$field['Field']]) && $foreignData['foreign_link'] == true) { + } elseif ($foreigners && isset($foreigners[$column['Field']]) && $foreignData['foreign_link'] == true) { // foreign key with a browsing icon $nullify_code = '6'; } else { @@ -490,4 +502,643 @@ function PMA_getNullifyCodeForNullColumn($field, $foreigners, $foreignData) } return $nullify_code; } + +/** + * Get the HTML elements for value column in inert form + * + * @param array $column + * @param string $backup_field + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param integer $tabindex + * @param integer $tabindex_for_value + * @param integer $idindex + * @param array $data + * @param array $special_chars + * @param array $foreignData + * @param array $paramTableDbArray + * @param array $rownumber_param + * @param array $titles + * @param array $text_dir + * @param array $special_chars_encoded + * @param integer $biggest_max_file_size + * @param string $default_char_editing + * @param array $no_support_types + * @param array $gis_data_types + * @return type + */ +function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $unnullify_trigger, + $tabindex, $tabindex_for_value, $idindex, $data,$special_chars, $foreignData, $odd_row, + $paramTableDbArray,$rownumber_param, $titles, $text_dir, $special_chars_encoded, $vkey,$is_upload, + $biggest_max_file_size, $default_char_editing, $no_support_types, $gis_data_types +) { + $html_output = ''; + + if ($foreignData['foreign_link'] == true) { + $html_output .= PMA_getForeignLink($column, $backup_field, $column_name_appendix, + $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, + $paramTableDbArray, $rownumber_param, $titles + ); + + } elseif (is_array($foreignData['disp_row'])) { + $html_output .= PMA_dispRawForeignData($backup_field, $column_name_appendix, + $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $foreignData + ); + + } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea'] && strstr($column['pma_type'], 'longtext')) { + $html_output = ' '; + $html_output .= ''; + $html_output .= '' + . ''; + $html_output .= PMA_getTextarea($backup_field, $column_name_appendix, $unnullify_trigger, + $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded + ); + + } elseif (strstr($column['pma_type'], 'text')) { + $html_output .= PMA_getTextarea($backup_field, $column_name_appendix, $unnullify_trigger, + $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded + ); + $html_output .= "\n"; + if (strlen($special_chars) > 32000) { + $html_output .= " \n"; + $html_output .= ' ' . __('Because of its length,
this column might not be editable'); + } + + } elseif ($column['pma_type'] == 'enum') { + $html_output .= PMA_getPmaTypeEnum($paramsArrayForColumns, $column,$extracted_columnspec); + + } elseif ($column['pma_type'] == 'set') { + $html_output .= PMA_getPmaTypeSet($column,$extracted_columnspec, $backup_field, + $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex); + + } elseif ($column['is_binary'] || $column['is_blob']) { + $html_output .= PMA_getBinaryAndBlobColumn($column, $data, $special_chars,$biggest_max_file_size, + $backup_field,$column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, + $idindex, $text_dir, $special_chars_encoded, $vkey, $is_upload); + + } elseif (! in_array($column['pma_type'], $no_support_types)) { + $html_output .= PMA_getNoSupportTypes($column, $default_char_editing,$backup_field, + $column_name_appendix, $unnullify_trigger,$tabindex,$special_chars, + $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded); + + } if (in_array($column['pma_type'], $gis_data_types)) { + $html_output .= PMA_getHTMLforGisDataTypes($vrow, $column); + } + + return $html_output; +} + +/** + * Get HTML for foreign link in insert form + * + * @param array $column + * @param string $backup_field + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param integer $tabindex + * @param integer $tabindex_for_value + * @param integer $idindex + * @param array $data + * @param array $paramTableDbArray + * @param array $rownumber_param + * @param array $titles + * @return string + */ +function PMA_getForeignLink($column, $backup_field, $column_name_appendix, + $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, + $paramTableDbArray, $rownumber_param, $titles +) { + list($db, $table) = $paramTableDbArray; + $html_output = ''; + $html_output .= $backup_field . "\n"; + $html_output .= ''; + $html_output .= '' + . '' + . str_replace("'", "\'", $titles['Browse']) . ''; + return $html_output; +} + +/** + * Get HTML to display foreign data + * + * @param string $backup_field + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param integer $tabindex + * @param integer $tabindex_for_value + * @param integer $idindex + * @param array $data + * @param array $foreignData + * @return string + */ +function PMA_dispRawForeignData($backup_field, $column_name_appendix, + $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $foreignData +) { + $html_output = ''; + $html_output .= $backup_field . "\n"; + $html_output .= '' + . ''; + + return $html_output; +} + +/** + * Get HTML for enum type + * + * @param array $column + * @param string $backup_field + * @param string $column_name_appendix + * @param array $extracted_columnspec + * @return string + */ +function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix, $extracted_columnspec) +{ + $html_output = ''; + if (! isset($column['values'])) { + $column['values'] = PMA_getColumnEnumValues($column, $extracted_columnspec); + } + $column_enum_values = $column['values']; + $html_output .= ''; + $html_output .= ''; + $html_output .= "\n" . ' ' . $backup_field . "\n"; + if (strlen($column['Type']) > 20) { + $html_output .= PMA_showDropDownDependOnLength($column, $column_name_appendix, $unnullify_trigger, + $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values + ); + } else { + $html_output .= PMA_showRadioButtonDependOnLength($column_name_appendix, $unnullify_trigger, + $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values + ); + } + return $html_output; +} + +/** + * Get column values + * + * @param array $column + * @param array $extracted_columnspec + * @return array + */ +function PMA_getColumnEnumValues($column, $extracted_columnspec) +{ + $column['values'] = array(); + foreach ($extracted_columnspec['enum_set_values'] as $val) { + // Removes automatic MySQL escape format + $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val)); + $column['values'][] = array( + 'plain' => $val, + 'html' => htmlspecialchars($val), + ); + } + return $column['values']; +} + +/** + * Get HTML drop down for more than 20 string length + * + * @param array $column + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param integer $tabindex + * @param integer $tabindex_for_value + * @param integer $idindex + * @param array $data + * @param array $column_enum_values + * @return string + */ +function PMA_showDropDownDependOnLength($column, $column_name_appendix, $unnullify_trigger, + $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values +) { + $html_output = ''; + return $html_output; +} + +/** + * Get HTML radio button for less than 20 string length + * + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param integer $tabindex + * @param array $column + * @param integer $tabindex_for_value + * @param integer $idindex + * @param array $data + * @param array $column_enum_values + * @return string + */ +function PMA_showRadioButtonDependOnLength($column_name_appendix, $unnullify_trigger, + $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values +) { + $j = 0; + foreach ($column_enum_values as $enum_value) { + $html_output = ' ' + . ''; + $html_output .= '' . "\n"; + $j++; + } + return $html_output; +} + +/** + * Get the HTML for 'set' pma type + * + * @param array $column + * @param array $extracted_columnspec + * @param string $backup_field + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param integer $tabindex + * @param integer $tabindex_for_value + * @param integer $idindex + * @return string + */ +function PMA_getPmaTypeSet($column,$extracted_columnspec, $backup_field, + $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex +) { + list($column_set_values, $select_size) = PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec); + $vset = array_flip(explode(',', $data)); + $html_output = $backup_field . "\n"; + $html_output .= ''; + $html_output .= ''; + return $html_output; +} + +/** + * Retrieve column 'set' value and select size + * + * @param array $column + * @param array $extracted_columnspec + * @return type + */ +function PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec) +{ + if (! isset($column['values'])) { + $column['values'] = array(); + foreach ($extracted_columnspec['enum_set_values'] as $val) { + $column['values'][] = array( + 'plain' => $val, + 'html' => htmlspecialchars($val), + ); + } + $column['select_size'] = min(4, count($column['values'])); + } + return array($column['values'], $column['select_size']); +} + +/** + * Get HTML for binary and blob column + * + * @param array $column + * @param array $data + * @param array $special_chars + * @param integer $biggest_max_file_size + * @param string $backup_field + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param integer $tabindex + * @param integer $tabindex_for_value + * @param integer $idindex + * @param string $text_dir + * @param string $special_chars_encoded + * @param string $vkey + * @param boolean $is_upload + * @return string + */ +function PMA_getBinaryAndBlobColumn($column, $data, $special_chars,$biggest_max_file_size, + $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, + $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,$vkey, $is_upload +) { + $html_output = ''; + if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob']) + || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $column['is_binary']) + || ($GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$column['is_blob']) + ) { + $html_output .= __('Binary - do not edit'); + if (isset($data)) { + $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1); + $html_output .= ' ('. $data_size [0] . ' ' . $data_size[1] . ')'; + unset($data_size); + } + + $html_output .= '' + . ''; + } elseif ($column['is_blob']) { + $html_output .= "\n"; + $html_output .= PMA_getTextarea($backup_field, $column_name_appendix, $unnullify_trigger, + $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded); + } else { + // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars'] + $columnsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']); + $html_output .= "\n"; + $html_output .= $backup_field . "\n"; + $html_output .= PMA_getHTMLinput($column, $column_name_appendix, $special_chars, $columnsize, + $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex); + } + + if ($is_upload && $column['is_blob']) { + $html_output .= '
'; + $html_output .= ' '; + list($html_out, $biggest_max_file_size) = PMA_getMaxUploadSize($column,$biggest_max_file_size); + $html_output .= $html_out; + } + + if (!empty($cfg['UploadDir'])) { + $html_output .= PMA_GetSelectOptionForUpload($vkey, $column); + } + + return $html_output; +} + +/** + * Get HTML input type + * + * @param array $column + * @param string $column_name_appendix + * @param array $special_chars + * @param integer $columnsize + * @param string $unnullify_trigger + * @param integer $tabindex + * @param integer $tabindex_for_value + * @param integer $idindex + * @return string + */ +function PMA_getHTMLinput($column, $column_name_appendix, $special_chars, + $columnsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex +) { + $the_class = 'textfield'; + if ($column['pma_type'] == 'date') { + $the_class .= ' datefield'; + } elseif ($column['pma_type'] == 'datetime' + || substr($column['pma_type'], 0, 9) == 'timestamp' + ) { + $the_class .= ' datetimefield'; + } + return ''; +} + +/** + * Get HTML select option for upload + * + * @param string $vkey + * @param array $column + * @return string + */ +function PMA_GetSelectOptionForUpload($vkey, $column) +{ + $files = PMA_getFileSelectOptions(PMA_userDir($GLOBALS['cfg']['UploadDir'])); + if ($files === false) { + return ' ' . __('Error') . '
' . "\n" + . ' ' . __('The directory you set for upload work cannot be reached') . "\n"; + } elseif (!empty($files)) { + return "
\n" + . ' ' . __('Or') . '' . ' ' . __('web server upload directory') . ':
' . "\n" + . ' ' . "\n"; + } +} + +/** + * Retrieve the maximum upload file size + * + * @param array $column + * @param integer $biggest_max_file_size + * @return array + */ +function PMA_getMaxUploadSize($column, $biggest_max_file_size) +{ + // find maximum upload size, based on field type + /** + * @todo with functions this is not so easy, as you can basically + * process any data with function like MD5 + */ + $max_field_sizes = array( + 'tinyblob' => '256', + 'blob' => '65536', + 'mediumblob' => '16777216', + 'longblob' => '4294967296'); // yeah, really + + $this_field_max_size = $max_upload_size; // from PHP max + if ($this_field_max_size > $max_field_sizes[$column['pma_type']]) { + $this_field_max_size = $max_field_sizes[$column['pma_type']]; + } + $html_output = PMA_displayMaximumUploadSize($this_field_max_size) . "\n"; + // do not generate here the MAX_FILE_SIZE, because we should + // put only one in the form to accommodate the biggest field + if ($this_field_max_size > $biggest_max_file_size) { + $biggest_max_file_size = $this_field_max_size; + } + return array($html_output, $biggest_max_file_size); +} + +/** + * Get HTML for pma no support types + * + * @param array $column + * @param string $default_char_editing + * @param string $backup_field + * @param string $column_name_appendix + * @param string $unnullify_trigger + * @param integer $tabindex + * @param array $special_chars + * @param integer $tabindex_for_value + * @param integer $idindex + * @param string $text_dir + * @param array $special_chars_encoded + * @return string + */ +function PMA_getNoSupportTypes($column, $default_char_editing,$backup_field, + $column_name_appendix, $unnullify_trigger,$tabindex,$special_chars, + $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded +) { + $columnSize = PMA_getColumnSize($column); + $html_output = $backup_field . "\n"; + if ($column['is_char'] + && ($GLOBALS['cfg']['CharEditing'] == 'textarea' + || strpos($data, "\n") !== false) + ) { + $html_output .= "\n"; + $GLOBALS['cfg']['CharEditing'] = $default_char_editing; + $html_output .= PMA_getTextarea($backup_field, $column_name_appendix, $unnullify_trigger, + $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, true); + } else { + $html_output .= PMA_getHTMLinput($column, $column_name_appendix, $special_chars, + $columnSize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex); + + if ($column['Extra'] == 'auto_increment') { + $html_output .= ''; + + } + if (substr($column['pma_type'], 0, 9) == 'timestamp') { + $html_output .= ''; + + } + if (substr($column['pma_type'], 0, 8) == 'datetime') { + $html_output .= ''; + + } + if ($column['True_Type'] == 'bit') { + $html_output .= ''; + + } + if ($column['pma_type'] == 'date' + || $column['pma_type'] == 'datetime' + || substr($column['pma_type'], 0, 9) == 'timestamp' + ) { + // the _3 suffix points to the date field + // the _2 suffix points to the corresponding NULL checkbox + // in dateFormat, 'yy' means the year with 4 digits + } + } + return $html_output; +} + +/** + * Get the column size + * + * @param array $column + * @return integer + */ +function PMA_getColumnSize($column) +{ + if ($column['is_char']) { + $columnSize = $extracted_columnspec['spec_in_brackets']; + if ($columnSize > $GLOBALS['cfg']['MaxSizeForInputField']) { + /** + * This case happens for CHAR or VARCHAR columns which have + * a size larger than the maximum size for input field. + */ + $GLOBALS['cfg']['CharEditing'] = 'textarea'; + } + } else { + /** + * This case happens for example for INT or DATE columns; + * in these situations, the value returned in $column['len'] + * seems appropriate. + */ + $columnsize = $column['len']; + } + return min(max($columnsize, $GLOBALS['cfg']['MinSizeForInputField']), $GLOBALS['cfg']['MaxSizeForInputField']); +} + +/** + * Get HTML for gis data types + * + * @param string $vrow + * @param array $column + * @return string + */ +function PMA_getHTMLforGisDataTypes($vrow, $column) +{ + $data_val = isset($vrow[$column['Field']]) ? $vrow[$column['Field']] : ''; + $_url_params = array( + 'field' => $column['Field_title'], + 'value' => $data_val, + ); + if ($column['pma_type'] != 'geometry') { + $_url_params = $_url_params + array('gis_data[gis_type]' => strtoupper($column['pma_type'])); + } + $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert')); + return '' + . PMA_linkOrButton('#', $edit_str, array(), false, false, '_blank') + . ''; +} ?> diff --git a/tbl_change.php b/tbl_change.php index d4292f889c..f097feff90 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -201,7 +201,7 @@ $titles['Browse'] = PMA_getIcon('b_browse.png', __('Browse foreign values')); // Set if we passed the first timestamp field $timestamp_seen = 0; -$fields_cnt = count($table_fields); +$columns_cnt = count($table_fields); $tabindex = 0; $tabindex_for_function = +3000; @@ -274,47 +274,47 @@ foreach ($rows as $row_id => $vrow) { $default_char_editing = $cfg['CharEditing']; $odd_row = true; - for ($i = 0; $i < $fields_cnt; $i++) { + for ($i = 0; $i < $columns_cnt; $i++) { if (! isset($table_fields[$i]['processed'])) { - $field = $table_fields[$i]; - $field = PMA_analyzeTableColumnsArray($field, $comments_map, $timestamp_seen); + $column = $table_fields[$i]; + $column = PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen); } - $extracted_columnspec = PMA_extractColumnSpec($field['Type']); + $extracted_columnspec = PMA_extractColumnSpec($column['Type']); - if (-1 === $field['len']) { - $field['len'] = PMA_DBI_field_len($vresult, $i); + if (-1 === $column['len']) { + $column['len'] = PMA_DBI_field_len($vresult, $i); // length is unknown for geometry fields, make enough space to edit very simple WKTs - if (-1 === $field['len']) { - $field['len'] = 30; + if (-1 === $column['len']) { + $column['len'] = 30; } } //Call validation when the form submited... $unnullify_trigger = $chg_evt_handler . "=\"return verificationsAfterFieldChange('" - . PMA_escapeJsString($field['Field_md5']) . "', '" - . PMA_escapeJsString($jsvkey) . "','".$field['pma_type']."')\""; + . PMA_escapeJsString($column['Field_md5']) . "', '" + . PMA_escapeJsString($jsvkey) . "','".$column['pma_type']."')\""; // Use an MD5 as an array index to avoid having special characters in the name atttibute (see bug #1746964 ) - $field_name_appendix = $vkey . '[' . $field['Field_md5'] . ']'; + $column_name_appendix = $vkey . '[' . $column['Field_md5'] . ']'; - if ($field['Type'] == 'datetime' - && ! isset($field['Default']) - && ! is_null($field['Default']) - && ($insert_mode || ! isset($vrow[$field['Field']])) + if ($column['Type'] == 'datetime' + && ! isset($column['Default']) + && ! is_null($column['Default']) + && ($insert_mode || ! isset($vrow[$column['Field']])) ) { // INSERT case or // UPDATE case with an NULL value - $vrow[$field['Field']] = date('Y-m-d H:i:s', time()); + $vrow[$column['Field']] = date('Y-m-d H:i:s', time()); } ?> - class="center"> - - + class="center"> + + - - + + $vrow) { $special_chars_encoded = ''; if (isset($vrow)) { // (we are editing) - if (is_null($vrow[$field['Field']])) { + if (is_null($vrow[$column['Field']])) { $real_null_value = true; - $vrow[$field['Field']] = ''; + $vrow[$column['Field']] = ''; $special_chars = ''; - $data = $vrow[$field['Field']]; - } elseif ($field['True_Type'] == 'bit') { + $data = $vrow[$column['Field']]; + } elseif ($column['True_Type'] == 'bit') { $special_chars = PMA_printable_bit_value( - $vrow[$field['Field']], $extracted_columnspec['spec_in_brackets'] + $vrow[$column['Field']], $extracted_columnspec['spec_in_brackets'] ); - } elseif (in_array($field['True_Type'], $gis_data_types)) { + } elseif (in_array($column['True_Type'], $gis_data_types)) { // Convert gis data to Well Know Text format - $vrow[$field['Field']] = PMA_asWKT($vrow[$field['Field']], true); - $special_chars = htmlspecialchars($vrow[$field['Field']]); + $vrow[$column['Field']] = PMA_asWKT($vrow[$column['Field']], true); + $special_chars = htmlspecialchars($vrow[$column['Field']]); } else { // special binary "characters" - if ($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) { + if ($column['is_binary'] || ($column['is_blob'] && ! $cfg['ProtectBinary'])) { if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $cfg['ShowFunctionFields']) { - $vrow[$field['Field']] = bin2hex($vrow[$field['Field']]); - $field['display_binary_as_hex'] = true; + $vrow[$column['Field']] = bin2hex($vrow[$column['Field']]); + $column['display_binary_as_hex'] = true; } else { - $vrow[$field['Field']] = PMA_replace_binary_contents($vrow[$field['Field']]); + $vrow[$column['Field']] = PMA_replace_binary_contents($vrow[$column['Field']]); } } // end if - $special_chars = htmlspecialchars($vrow[$field['Field']]); + $special_chars = htmlspecialchars($vrow[$column['Field']]); //We need to duplicate the first \n or otherwise we will lose //the first newline entered in a VARCHAR or TEXT column $special_chars_encoded = PMA_duplicateFirstNewline($special_chars); - $data = $vrow[$field['Field']]; + $data = $vrow[$column['Field']]; } // end if... else... //when copying row, it is useful to empty auto-increment column to prevent duplicate key error if (isset($default_action) && $default_action === 'insert') { - if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== false) { + if ($column['Key'] === 'PRI' && strpos($column['Extra'], 'auto_increment') !== false) { $data = $special_chars_encoded = $special_chars = null; } } @@ -370,64 +370,59 @@ foreach ($rows as $row_id => $vrow) { // however, things have changed since MySQL 4.1, so // it's better to set a fields_prev in this situation $backup_field = ''; + . $column_name_appendix . '" value="' + . htmlspecialchars($vrow[$column['Field']]) . '" />'; } else { // (we are inserting) // display default values - if (! isset($field['Default'])) { - $field['Default'] = ''; + if (! isset($column['Default'])) { + $column['Default'] = ''; $real_null_value = true; $data = ''; } else { - $data = $field['Default']; + $data = $column['Default']; } - if ($field['True_Type'] == 'bit') { - $special_chars = PMA_convert_bit_default_value($field['Default']); + if ($column['True_Type'] == 'bit') { + $special_chars = PMA_convert_bit_default_value($column['Default']); } else { - $special_chars = htmlspecialchars($field['Default']); + $special_chars = htmlspecialchars($column['Default']); } $backup_field = ''; $special_chars_encoded = PMA_duplicateFirstNewline($special_chars); // this will select the UNHEX function while inserting - if (($field['is_binary'] || ($field['is_blob'] && ! $cfg['ProtectBinary'])) + if (($column['is_binary'] || ($column['is_blob'] && ! $cfg['ProtectBinary'])) && (isset($_SESSION['tmp_user_values']['display_binary_as_hex']) && $_SESSION['tmp_user_values']['display_binary_as_hex']) && $cfg['ShowFunctionFields'] ) { - $field['display_binary_as_hex'] = true; + $column['display_binary_as_hex'] = true; } } - $idindex = ($o_rows * $fields_cnt) + $i + 1; + $idindex = ($o_rows * $columns_cnt) + $i + 1; $tabindex = $idindex; // Get a list of data types that are not yet supported. $no_support_types = PMA_unsupportedDatatypes(); - $params_for_function_column = array( - $field, $is_upload, $field_name_appendix, $unnullify_trigger, - $no_support_types, $tabindex, $tabindex_for_function, - $idindex, $insert_mode); // The function column // ------------------- if ($cfg['ShowFunctionFields']) { - echo PMA_getFunctionColumn($params_for_function_column); + echo PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, + $unnullify_trigger, $no_support_types, $tabindex_for_function, + $tabindex, $idindex, $insert_mode); } // The null column // --------------- - $foreignData = PMA_getForeignData($foreigners, $field['Field'], false, '', ''); - $params_for_null_column = array( - $field, $field_name_appendix, $real_null_value, $tabindex, $tabindex_for_null, - $idindex, $vkey, $foreigners, $foreignData); - echo PMA_getNullColumn($params_for_null_column); + $foreignData = PMA_getForeignData($foreigners, $column['Field'], false, '', ''); + echo PMA_getNullColumn($column, $column_name_appendix, $real_null_value, + $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData); // The value column (depends on type) // ---------------- // See bug #1667887 for the reason why we don't use the maxlength // HTML attribute - echo ' ' . "\n"; // Will be used by js/tbl_change.js to set the default value // for the "Continue insertion" feature @@ -435,21 +430,21 @@ foreach ($rows as $row_id => $vrow) { if ($foreignData['foreign_link'] == true) { echo $backup_field . "\n"; ?> - - tabindex="" id="field__3" value="" /> - + - - + > + - + > + 32000) { echo " \n"; echo ' ' . __('Because of its length,
this column might not be editable'); } - } elseif ($field['pma_type'] == 'enum') { + } elseif ($column['pma_type'] == 'enum') { if (! isset($table_fields[$i]['values'])) { $table_fields[$i]['values'] = array(); foreach ($extracted_columnspec['enum_set_values'] as $val) { @@ -504,17 +501,17 @@ foreach ($rows as $row_id => $vrow) { ); } } - $field_enum_values = $table_fields[$i]['values']; + $column_enum_values = $table_fields[$i]['values']; ?> - - + + 20) { + if (strlen($column['Type']) > 20) { ?> - - tabindex="" id="field__3"> ' . $field_set_value['html'] . '' . "\n"; + echo '>' . $column_set_value['html'] . '' . "\n"; } // end for ?> $vrow) { unset($data_size); } ?> - - + + -