Make WordPress Core

Opened 3 months ago

Last modified 6 weeks ago

#61889 new defect (bug)

Function dbDelta() splits queries on semi-colon in column COMMENT and table COMMENT

Reported by: msolution's profile msolution Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 1.5
Component: Database Keywords: has-patch needs-testing
Focuses: Cc:

Description

When creating custom tables in Custom Plugins, the function dbDelta() is splitting the query with a semi-colon inside column comments and table comments and the query fails.

I suggest we use preg_split, instead of explode. I have attached a patch for the same.

For example the following query would fail:

<?php
dbDelta( 'CREATE TABLE `' . $wpdb->prefix . 'aividbox_chat` (
        `id` bigint(11) NOT NULL auto_increment,
        `user_id` int(11) NOT NULL DEFAULT 0,
        `chat_txt` varchar(5000) NOT NULL DEFAULT "Chat text;",
        `chat_from` int(11) NOT NULL DEFAULT 0 COMMENT "user_id:X;",
        `added_date` datetime NULL DEFAULT NULL,
        `status` int(11) NOT NULL DEFAULT 0 COMMENT "status => 0 = inactive; 1 = acttive; 2 = hidden by admin",
        `parent_id` int(11) NOT NULL DEFAULT 0,
        PRIMARY KEY  (`id`),
        KEY `k_user_id` (`user_id`)
) ENGINE=InnoDb  COMMENT "chat table;";

CREATE TABLE `' . $wpdb->prefix . 'aividbox_message` (
        `id` bigint(11) NOT NULL auto_increment,
        `user_id` int(11) NOT NULL DEFAULT 0,
        `message_txt` varchar(5000) NOT NULL DEFAULT "mesage text;",
        `message_from` int(11) NOT NULL DEFAULT 0 COMMENT "user_id:X;",
        `added_date` datetime NULL DEFAULT NULL,
        `status` int(11) NOT NULL DEFAULT 0 COMMENT "status => 0 = inactive; 1 = acttive; 2 = hidden by admin",
        PRIMARY KEY  (`id`),
        KEY `k_user_id` (`user_id`)
) ENGINE=InnoDb COMMENT "message table;";');

Attachments (1)

upgrade.php.patch (522 bytes) - added by msolution 3 months ago.

Download all attachments as: .zip

Change History (4)

#1 @hellofromTonya
7 weeks ago

  • Version changed from 6.6.1 to 1.5

Hello @msolution,

Welcome to WordPress Core's Trac.

I'm doing triage today for bugs reported on 6.6.1 or 6.6.2 (i.e. via Version) and then updating ticket information.

[1575] introduced the referenced code back in 2004. As I see the code in the 1.5 branch, setting the Version to 1.5 (though could have been an earlier release).

#2 @hellofromTonya
7 weeks ago

  • Component changed from Plugins to Database

Also updating the Component as the dbDelta() function is part of the Database component.

This ticket was mentioned in PR #7410 on WordPress/wordpress-develop by @msolution.


6 weeks ago
#3

wp-admin/includes/upgrade.php/dbDelta() updated for splitting individual queries with ; semicolons, and Not semi-colons inside column and table comments.

Note: See TracTickets for help on using tickets.