/**
 * Create relevant index statements
 *
 * @param array   $index         an array of index columns
 * @param string  $index_type    index type that which represents
 *                               the index type of $indexed_fields
 * @param boolean $is_create_tbl true if requirement is to get the statement
 *                               for table creation
 *
 * @return array an array of sql statements for indexes
 */
function PMA_buildIndexStatements($index, $index_type, $is_create_tbl = true)
{
    $statement = array();
    if (!count($index)) {
        return $statement;
    }
    $fields = array();
    foreach ($index['columns'] as $field) {
        $fields[] = PMA_Util::backquote($_REQUEST['field_name'][$field['col_index']]) . (!empty($field['size']) ? '(' . $field['size'] . ')' : '');
    }
    $statement[] = PMA_getStatementPrefix($is_create_tbl) . ' ' . $index_type . (!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);
    return $statement;
}
/**
 * Create relevant index statements
 *
 * @param array   $index         an array of index columns
 * @param string  $index_choice  index choice that which represents
 *                               the index type of $indexed_fields
 * @param boolean $is_create_tbl true if requirement is to get the statement
 *                               for table creation
 *
 * @return array an array of sql statements for indexes
 */
function PMA_buildIndexStatements($index, $index_choice, $is_create_tbl = true)
{
    $statement = array();
    if (!count($index)) {
        return $statement;
    }
    $sql_query = PMA_getStatementPrefix($is_create_tbl) . ' ' . $index_choice;
    if (!empty($index['Key_name']) && $index['Key_name'] != 'PRIMARY') {
        $sql_query .= ' ' . PMA\libraries\Util::backquote($index['Key_name']);
    }
    $index_fields = array();
    foreach ($index['columns'] as $key => $column) {
        $index_fields[$key] = PMA\libraries\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\libraries\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\libraries\Index::getIndexTypes())) {
        $sql_query .= ' USING ' . $type;
    }
    $parser = $index['Parser'];
    if ($index['Index_choice'] == 'FULLTEXT' && !empty($parser)) {
        $sql_query .= " WITH PARSER " . PMA\libraries\Util::sqlAddSlashes($parser);
    }
    $comment = $index['Index_comment'];
    if (!empty($comment)) {
        $sql_query .= " COMMENT '" . PMA\libraries\Util::sqlAddSlashes($comment) . "'";
    }
    $statement[] = $sql_query;
    return $statement;
}
Esempio n. 3
0
/**
 * Create relevant index statements
 *
 * @param array   $indexed_fields an array of index columns
 * @param string  $index_type     index type that which represents
 *                                the index type of $indexed_fields
 * @param boolean $is_create_tbl  true if requirement is to get the statement
 *                                for table creation
 *
 * @return array an array of sql statements for indexes
 */
function PMA_buildIndexStatements($indexed_fields, $index_type, $is_create_tbl = true)
{
    $statement = array();
    if (!count($indexed_fields)) {
        return $statement;
    }
    $fields = array();
    foreach ($indexed_fields as $field_nr) {
        $fields[] = PMA_Util::backquote($_REQUEST['field_name'][$field_nr]);
    }
    $statement[] = PMA_getStatementPrefix($is_create_tbl) . ' ' . $index_type . ' (' . implode(', ', $fields) . ') ';
    unset($fields);
    return $statement;
}