[wp-trac] [WordPress Trac] #49202: dbDelta does not consider syntax CREATE TABLE IF NOT EXISTS
WordPress Trac
noreply at wordpress.org
Wed Jan 15 11:59:13 UTC 2020
#49202: dbDelta does not consider syntax CREATE TABLE IF NOT EXISTS
--------------------------+-----------------------------
Reporter: krut1 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hello people, you have this code part in **/wp-
admin/includes/upgrade.php:2553**
{{{#!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 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
<?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 ;)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49202>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list