[wp-trac] [WordPress Trac] #41335: dbDelta() does not recognize MySQL's IF NOT EXISTS statement
WordPress Trac
noreply at wordpress.org
Thu Jan 16 08:24:04 UTC 2020
#41335: dbDelta() does not recognize MySQL's IF NOT EXISTS statement
-----------------------------------------+------------------------------
Reporter: kmaxim | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Upgrade/Install | Version:
Severity: normal | Resolution:
Keywords: has-patch reporter-feedback | Focuses:
-----------------------------------------+------------------------------
Comment (by krut1):
@pento But the logik is broken. You try to get the name of the table here:
{{{#!php
<?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 regex pattern schould be:
{{{#!php
<?php
if ( preg_match( '|CREATE TABLE( IF NOT EXISTS)? ([^ ]*)|', $qry, $matches
) ) {
$cqueries[ trim( $matches[2], '`' ) ] = $qry;
$for_update[ $matches[2] ] = 'Created table ' .
$matches[2];
}
}}}
In this case you will have the table's name. In current version of code
you have **IF** instead of table's name.
I wrote about it already here:
https://core.trac.wordpress.org/ticket/49202
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41335#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list