Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-admin/includes/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2962,8 +2962,8 @@ function dbDelta( $queries = '', $execute = true ) { // phpcs:ignore WordPress.N
// Create a tablename index for an array ($cqueries) of recognized query types.
foreach ( $queries as $qry ) {
if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
$cqueries[ trim( $matches[1], '`' ) ] = $qry;
$for_update[ $matches[1] ] = 'Created table ' . $matches[1];
$cqueries[ trim( $matches[1], '`' ) ] = $qry;
$for_update[ trim( $matches[1], '`' ) ] = 'Created table ' . $matches[1];
continue;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/tests/db/dbDelta.php
Original file line number Diff line number Diff line change
Expand Up @@ -1090,4 +1090,26 @@ public function test_column_type_change_with_hyphens_in_name() {
$updates
);
}

public function test_no_update_reported_when_tablename_in_backticks() {
global $wpdb;

$updates = dbDelta(
"
CREATE TABLE `{$wpdb->prefix}dbdelta_test` (
id bigint(20) NOT NULL AUTO_INCREMENT,
column_1 varchar(255) NOT NULL,
column_2 text,
column_3 blob,
PRIMARY KEY (id),
KEY key_1 (column_1($this->max_index_length)),
KEY compound_key (id,column_1($this->max_index_length)),
FULLTEXT KEY fulltext_key (column_1)
) {$this->db_engine}
",
false
);

$this->assertEmpty( $updates );
}
}
Loading