diff --git a/htdocs/sql/tbl_indexes.php b/htdocs/sql/tbl_indexes.php new file mode 100755 --- /dev/null +++ b/htdocs/sql/tbl_indexes.php @@ -0,0 +1,477 @@ + back to the welcome page + if (strlen($db)) { + $is_db = PMA_DBI_select_db($db); + } + if (!strlen($db) || !$is_db) { + $uri_params = array('reload' => '1'); + if (isset($message)) { + $uri_params['message'] = $message; + } + PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'main.php' + . PMA_generate_common_url($uri_params, '&')); + exit; + } + // Not a valid table name -> back to the default db sub-page + if (strlen($table)) { + $is_table = PMA_DBI_query('SHOW TABLES LIKE \'' + . PMA_sqlAddslashes($table, TRUE) . '\'', null, PMA_DBI_QUERY_STORE); + } + if (! strlen($table) + || !($is_table && PMA_DBI_num_rows($is_table))) { + $uri_params = array('reload' => '1', 'db' => $db); + if (isset($message)) { + $uri_params['message'] = $message; + } + PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] + . $cfg['DefaultTabDatabase'] + . PMA_generate_common_url($uri_params, '&')); + exit; + } elseif (isset($is_table)) { + PMA_DBI_free_result($is_table); + } + + // Displays headers (if needed) + $js_to_run = isset($index) && isset($do_save_data) + ? 'functions.js' + : 'indexes.js'; + require_once './libraries/header.inc.php'; +} // end if + + +/** + * Gets fields and indexes informations + */ +if (!defined('PMA_IDX_INCLUDED')) { + $err_url_0 = 'db_sql.php?' . PMA_generate_common_url($db); +} + +// Gets table keys and store them in arrays +$indexes = array(); +$indexes_info = array(); +$indexes_data = array(); +// keys had already been grabbed in "tbl_sql.php" +if (!defined('PMA_IDX_INCLUDED')) { + $ret_keys = PMA_get_indexes($table, $err_url_0); +} + +PMA_extract_indexes($ret_keys, $indexes, $indexes_info, $indexes_data); + +// Get fields and stores their name/type +// fields had already been grabbed in "tbl_sql.php" +if (!defined('PMA_IDX_INCLUDED')) { + $fields_rs = PMA_DBI_query('SHOW FIELDS FROM ' + . PMA_backquote($table) . ';'); + $save_row = array(); + while ($row = PMA_DBI_fetch_assoc($fields_rs)) { + $save_row[] = $row; + } +} + +$fields_names = array(); +$fields_types = array(); +foreach ($save_row AS $saved_row_key => $row) { + $fields_names[] = $row['Field']; + // loic1: set or enum types: slashes single quotes inside options + if (preg_match('@^(set|enum)\((.+)\)$@i', $row['Type'], $tmp)) { + $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', + ',' . $tmp[2]), 1); + $fields_types[] = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; + } else { + $fields_types[] = $row['Type']; + } +} // end while + +if ($fields_rs) { + PMA_DBI_free_result($fields_rs); +} + + +/** + * Do run the query to build the new index and moves back to + * "tbl_sql.php" + */ +if (!defined('PMA_IDX_INCLUDED') + && (isset($index) && isset($do_save_data))) { + + $err_url = 'tbl_indexes.php?' . PMA_generate_common_url($db, $table); + if (empty($old_index)) { + $err_url .= '&create_index=1&idx_num_fields=' . $idx_num_fields; + } else { + $err_url .= '&index=' . urlencode($old_index); + } + + if ($index_type == 'PRIMARY') { + if ($index == '') { + $index = 'PRIMARY'; + } elseif ($index != 'PRIMARY') { + PMA_mysqlDie($strPrimaryKeyName, '', FALSE, $err_url); + } + } elseif ($index == 'PRIMARY') { + PMA_mysqlDie($strCantRenameIdxToPrimary, '', FALSE, $err_url); + } + + + // $sql_query is the one displayed in the query box + $sql_query = 'ALTER TABLE ' . PMA_backquote($table); + + // Drops the old index + if (!empty($old_index)) { + if ($old_index == 'PRIMARY') { + $sql_query .= ' DROP PRIMARY KEY,'; + } else { + $sql_query .= ' DROP INDEX ' . PMA_backquote($old_index) .','; + } + } // end if + + // Builds the new one + switch ($index_type) { + case 'PRIMARY': + $sql_query .= ' ADD PRIMARY KEY ('; + break; + case 'FULLTEXT': + $sql_query .= ' ADD FULLTEXT ' + . (empty($index) ? '' : PMA_backquote($index)) . ' ('; + break; + case 'UNIQUE': + $sql_query .= ' ADD UNIQUE ' + . (empty($index) ? '' : PMA_backquote($index)) . ' ('; + break; + case 'INDEX': + $sql_query .= ' ADD INDEX ' + . (empty($index) ? '' : PMA_backquote($index)) . ' ('; + break; + } // end switch + $index_fields = ''; + foreach ($column AS $i => $name) { + if ($name != '--ignore--') { + $index_fields .= (empty($index_fields) ? '' : ',') + . PMA_backquote($name) + . (empty($sub_part[$i]) + ? '' + : '(' . $sub_part[$i] . ')'); + } + } // end while + if (empty($index_fields)){ + PMA_mysqlDie($strNoIndexPartsDefined, '', FALSE, $err_url); + } else { + $sql_query .= $index_fields . ')'; + } + + $result = PMA_DBI_query($sql_query); + $message = $strTable . ' ' . htmlspecialchars($table) . ' ' + . $strHasBeenAltered; + + $active_page = 'tbl_structure.php'; + require './tbl_structure.php'; +} // end builds the new index + + +/** + * Edits an index or defines a new one + */ +elseif (!defined('PMA_IDX_INCLUDED') + && (isset($index) || isset($create_index))) { + + // Prepares the form values + if (!isset($index)) { + $index = ''; + } + if (!isset($old_index)){ + $old_index = $index; + } + if (!isset($index_type)) { + $index_type = ''; + } + if ($old_index == '' || !isset($indexes_info[$old_index])) { + $edited_index_info['Sequences'] = array(); + $edited_index_data = array(); + for ($i = 1; $i <= $idx_num_fields; $i++) { + $edited_index_info['Sequences'][] = $i; + $edited_index_data[$i] = array('Column_name' => '', + 'Sub_part' => ''); + } // end for + if ($old_index == '' + && !isset($indexes_info['PRIMARY']) + && ($index_type == '' || $index_type == 'PRIMARY')) { + $old_index = 'PRIMARY'; + } + } else { + $edited_index_info = $indexes_info[$old_index]; + $edited_index_data = $indexes_data[$old_index]; + + + if ((PMA_MYSQL_INT_VERSION < 40002 + && $edited_index_info['Comment'] == 'FULLTEXT') + || (PMA_MYSQL_INT_VERSION >= 40002 + && $edited_index_info['Index_type'] == 'FULLTEXT')) { + $index_type = 'FULLTEXT'; + } elseif ($index == 'PRIMARY') { + $index_type = 'PRIMARY'; + } elseif ($edited_index_info['Non_unique'] == '0') { + $index_type = 'UNIQUE'; + } else { + $index_type = 'INDEX'; + } + } // end if... else... + + if (isset($add_fields)) { + if (isset($prev_add_fields)) { + $added_fields += $prev_add_fields; + } + $field_cnt = count($edited_index_info['Sequences']) + 1; + for ($i = $field_cnt; $i < ($added_fields + $field_cnt); $i++) { + $edited_index_info['Sequences'][] = $i; + $edited_index_data[$i] = array('Column_name' => '', + 'Sub_part' => ''); + } // end for + + // Restore entered values + foreach ($column AS $i => $name) { + if ($name != '--ignore--'){ + $edited_index_data[$i+1]['Column_name'] = $name; + $edited_index_data[$i+1]['Sub_part'] = $sub_part[$i]; + } + } // end while + } // end if + // end preparing form values + ?> + +
+
+ + ' . "\n"; + } + if (isset($added_fields)) { + echo ' ' . "\n"; + } + if (isset($idx_num_fields)) { + echo ' ' . "\n"; + } + ?> + + +
+ + + + +
+ + +
+ +
+ + + +
+ + +
+
+ + + + + + + + + + + + + + + + +
+ /> +
+
+ +
+ + ') . "\n"; + echo ' ' . "\n"; + ?> +
+
+
+ +
+ + + + 0) { + $edit_link_text = ''; + $drop_link_text = ''; + + if ($cfg['PropertiesIconic'] === true || $cfg['PropertiesIconic'] === 'both') { + $edit_link_text = '' . $strEdit . ''; + $drop_link_text = '' . $strDrop . ''; + } + if ($cfg['PropertiesIconic'] === false || $cfg['PropertiesIconic'] === 'both') { + $edit_link_text .= $strEdit; + $drop_link_text .= $strDrop; + } + if ($cfg['PropertiesIconic'] === 'both') { + $edit_link_text = '' . $edit_link_text . ''; + $drop_link_text = '' . $drop_link_text . ''; + } + ?> + + + + + + + + + + + ' + .'' . "\n"; + } + ?> + + + +
+ + +
' . $strNoIndex + .'
+ '); ?> + +
+
+