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. git-svn-id: https://develop.svn.wordpress.org/trunk@37538 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2111185ab9
commit
52caa1f06a
@ -2221,7 +2221,7 @@ function dbDelta( $queries = '', $execute = true ) {
|
||||
if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
|
||||
|
||||
// Get the field type from the query.
|
||||
preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[ $tablefield_field_lowercased ], $matches);
|
||||
preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches );
|
||||
$fieldtype = $matches[1];
|
||||
$fieldtype_lowercased = strtolower( $fieldtype );
|
||||
|
||||
|
@ -464,4 +464,28 @@ class Tests_dbDelta extends WP_UnitTestCase {
|
||||
=> "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob"
|
||||
), $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 20263
|
||||
*/
|
||||
function test_query_with_backticks_does_not_throw_an_undefined_index_warning() {
|
||||
global $wpdb;
|
||||
|
||||
$schema = "
|
||||
CREATE TABLE {$wpdb->prefix}dbdelta_test2 (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`column_1` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY compound_key (id,column_1)
|
||||
)
|
||||
";
|
||||
|
||||
$wpdb->query( $schema );
|
||||
|
||||
$updates = dbDelta( $schema, false );
|
||||
|
||||
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test2" );
|
||||
|
||||
$this->assertEmpty( $updates );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user