Opened 5 years ago
Closed 5 years ago
#49202 closed defect (bug) (duplicate)
dbDelta does not consider syntax CREATE TABLE IF NOT EXISTS
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Database | Keywords: | |
Focuses: | Cc: |
Description
Hello people, you have this code part in /wp-admin/includes/upgrade.php:2553
<?php // Create a tablename index for an array ($cqueries) of queries foreach ( $queries as $qry ) { if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) { $cqueries[ trim( $matches[1], '`' ) ] = $qry; $for_update[ $matches[1] ] = 'Created table ' . $matches[1]; } elseif ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) { array_unshift( $cqueries, $qry ); } elseif ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) { $iqueries[] = $qry; } elseif ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) { $iqueries[] = $qry; } else { // Unrecognized query type } }
But if we create a new table with such syntax:
CREATE TABLE IF NOT EXISTS wp_test_table...;
we have always table name IF instead of wp_test_table.
Can you plase change regex pattern to this?
<?php if ( preg_match( '|CREATE TABLE( IF NOT EXISTS)? ([^ ]*)|', $qry, $matches ) ) { $cqueries[ trim( $matches[2], '`' ) ] = $qry; $for_update[ $matches[2] ] = 'Created table ' . $matches[2]; }
Thank you ;)
Change History (1)
Note: See
TracTickets for help on using
tickets.
Hi there, welcome to WordPress Trac! Thanks for the report, we're already tracking this enhancement in #41335.