Make WordPress Core

Changeset 37538


Ignore:
Timestamp:
05/23/2016 06:11:32 PM (9 years ago)
Author:
ocean90
Message:

Database: Support backticks around field names when parsing a query for the field type.

Avoids an undefined index PHP warning by dbDelta().

Props davidmosterd, ocean90.
See #20263.

Location:
trunk
Files:
2 edited

Legend:

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

    r37533 r37538  
    22222222
    22232223                // Get the field type from the query.
    2224                 preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[ $tablefield_field_lowercased ], $matches);
     2224                preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
    22252225                $fieldtype = $matches[1];
    22262226                $fieldtype_lowercased = strtolower( $fieldtype );
  • trunk/tests/phpunit/tests/dbdelta.php

    r37525 r37538  
    465465            ), $result );
    466466    }
     467
     468    /**
     469     * @ticket 20263
     470     */
     471    function test_query_with_backticks_does_not_throw_an_undefined_index_warning() {
     472        global $wpdb;
     473
     474        $schema = "
     475            CREATE TABLE {$wpdb->prefix}dbdelta_test2 (
     476                `id` bigint(20) NOT NULL AUTO_INCREMENT,
     477                `column_1` varchar(255) NOT NULL,
     478                PRIMARY KEY  (id),
     479                KEY compound_key (id,column_1)
     480            )
     481        ";
     482
     483        $wpdb->query( $schema );
     484
     485        $updates = dbDelta( $schema, false );
     486
     487        $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test2" );
     488
     489        $this->assertEmpty( $updates );
     490    }
    467491}
Note: See TracChangeset for help on using the changeset viewer.