diff --git a/js/indexes.js b/js/indexes.js index 1e997a5edc..a2f0f5e8f5 100644 --- a/js/indexes.js +++ b/js/indexes.js @@ -175,6 +175,9 @@ function PMA_addColumnToIndex(source_array, array_index, index_choice, col_index PMA_removeColumnFromIndex(col_index); var index_name = $('input[name="index[Key_name]"]').val(); var index_comment = $('input[name="index[Index_comment]"]').val(); + var key_block_size = $('input[name="index[Key_block_size]"]').val(); + var parser = $('input[name="index[Parser]"]').val(); + var index_type = $('select[name="index[Index_type]"]').val(); var columns = []; $('#index_columns tbody').find('tr').each(function () { // Get columns in particular order. @@ -191,6 +194,9 @@ function PMA_addColumnToIndex(source_array, array_index, index_choice, col_index 'Key_name': index_name, 'Index_comment': index_comment, 'Index_choice': index_choice.toUpperCase(), + 'Key_block_size': key_block_size, + 'Parser': parser, + 'Index_type': index_type, 'columns': columns }; @@ -631,7 +637,7 @@ AJAX.registerOnload('indexes.js', function () { */ $('body').on('change', 'select[name*="field_key"]', function () { // Index of column on Table edit and create page. - var col_index = /\d/.exec($(this).attr('name')); + var col_index = /\d+/.exec($(this).attr('name')); col_index = col_index[0]; // Choice of selected index. var index_choice = /[a-z]+/.exec($(this).val()); diff --git a/libraries/create_addfield.lib.php b/libraries/create_addfield.lib.php index 5724029dc2..cabb3af9ea 100644 --- a/libraries/create_addfield.lib.php +++ b/libraries/create_addfield.lib.php @@ -136,21 +136,51 @@ function PMA_buildIndexStatements($index, $index_choice, return $statement; } - $fields = array(); - foreach ($index['columns'] as $field) { - $fields[] - = PMA_Util::backquote($_REQUEST['field_name'][$field['col_index']]) - . (! empty($field['size']) ? '(' . $field['size'] . ')' : ''); + $sql_query = PMA_getStatementPrefix($is_create_tbl) + . ' ' . $index_choice; + + if (! empty($index['Key_name']) && $index['Key_name'] != 'PRIMARY') { + $sql_query .= ' ' . PMA_Util::backquote($index['Key_name']); } - $statement[] = PMA_getStatementPrefix($is_create_tbl) - . ' ' . $index_choice - . (! empty($index['Key_name']) && $index['Key_name'] != 'PRIMARY' ? - PMA_Util::backquote($index['Key_name']) - : '') - . ' (' . implode(', ', $fields) . ') ' - . (! empty($index['Index_comment']) ? 'COMMENT ' - . "'" . $index['Index_comment'] . "' " : ''); - unset($fields); + + $index_fields = array(); + foreach ($index['columns'] as $key => $column) { + $index_fields[$key] = PMA_Util::backquote( + $_REQUEST['field_name'][$column['col_index']] + ); + if ($column['size']) { + $index_fields[$key] .= '(' . $column['size'] . ')'; + } + } // end while + + $sql_query .= ' (' . implode(', ', $index_fields) . ')'; + + $keyBlockSizes = $index['Key_block_size']; + if (! empty($keyBlockSizes)) { + $sql_query .= " KEY_BLOCK_SIZE = " + . PMA_Util::sqlAddSlashes($keyBlockSizes); + } + + // specifying index type is allowed only for primary, unique and index only + $type = $index['Index_type']; + if ($index['Index_choice'] != 'SPATIAL' + && $index['Index_choice'] != 'FULLTEXT' + && in_array($type, PMA_Index::getIndexTypes()) + ) { + $sql_query .= ' USING ' . $type; + } + + $parser = $index['Parser']; + if ($index['Index_choice'] == 'FULLTEXT' && ! empty($parser)) { + $sql_query .= " WITH PARSER " . PMA_Util::sqlAddSlashes($parser); + } + + $comment = $index['Index_comment']; + if (! empty($comment)) { + $sql_query .= " COMMENT '" . PMA_Util::sqlAddSlashes($comment) . "'"; + } + + $statement[] = $sql_query; return $statement; } diff --git a/libraries/tbl_indexes.lib.php b/libraries/tbl_indexes.lib.php index 2265a8814a..fc03e4c6bd 100644 --- a/libraries/tbl_indexes.lib.php +++ b/libraries/tbl_indexes.lib.php @@ -323,7 +323,8 @@ function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields) . '' . '' . '' + . 'id="input_key_block_size" size="30" value="' + . htmlspecialchars($index->getKeyBlockSize()) . '" />' . ''; $html .= '
' @@ -347,7 +348,7 @@ function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields) . '' . '
' . '' + . 'id="input_parse" size="30" value="' . htmlspecialchars($index->getParser()) . '" />' . ''; $html .= '
'