WordPress.org

Make WordPress Core

Changeset 38591


Ignore:
Timestamp:
09/12/2016 05:08:17 AM (21 months ago)
Author:
pento
Message:

Database: Normalise index names in dbDelta().

When comparing index definitions, normalise the index names to lower case, as they are not case sensitive within MySQL.

Fixes #34874.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/upgrade.php

    r38109 r38591  
    22842284
    22852285                    // Escape the index name with backticks. An index for a primary key has no name.
    2286                     $index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . $index_matches['index_name'] . '`';
     2286                    $index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . strtolower( $index_matches['index_name'] ) . '`';
    22872287
    22882288                    // Parse the columns. Multiple columns are separated by a comma.
     
    24082408
    24092409                // Add the index to the index data array.
    2410                 $keyname = $tableindex->Key_name;
     2410                $keyname = strtolower( $tableindex->Key_name );
    24112411                $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
    24122412                $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
     
    24192419                // Build a create string to compare to the query.
    24202420                $index_string = '';
    2421                 if ($index_name == 'PRIMARY') {
     2421                if ($index_name == 'primary') {
    24222422                    $index_string .= 'PRIMARY ';
    24232423                } elseif ( $index_data['unique'] ) {
     
    24312431                }
    24322432                $index_string .= 'KEY ';
    2433                 if ( 'PRIMARY' !== $index_name  ) {
     2433                if ( 'primary' !== $index_name  ) {
    24342434                    $index_string .= '`' . $index_name . '`';
    24352435                }
  • trunk/tests/phpunit/tests/dbdelta.php

    r38044 r38591  
    804804
    805805    /**
     806     * @ticket 34874
     807     */
     808    function test_key_names_are_not_case_sensitive_and_do_not_recreate_indices() {
     809        global $wpdb;
     810
     811        $updates = dbDelta(
     812            "
     813            CREATE TABLE {$wpdb->prefix}dbdelta_test (
     814                id bigint(20) NOT NULL AUTO_INCREMENT,
     815                column_1 varchar(255) NOT NULL,
     816                column_2 text,
     817                column_3 blob,
     818                PRIMARY KEY  (id),
     819                KEY KEY_1 (column_1),
     820                KEY compOUND_key (id,column_1),
     821                FULLTEXT KEY FULLtext_kEY (column_1)
     822            ) ENGINE=MyISAM
     823            ", false );
     824
     825        $this->assertEmpty( $updates );
     826    }
     827
     828    /**
    806829     * @ticket 31679
    807830     */
Note: See TracChangeset for help on using the changeset viewer.