[wp-trac] [WordPress Trac] #61889: Function dbDelta() splits queries on semi-colon in column COMMENT and table COMMENT

WordPress Trac noreply at wordpress.org
Fri Aug 16 19:06:04 UTC 2024


#61889: Function dbDelta() splits queries on semi-colon in column COMMENT and table
COMMENT
--------------------------+-------------------------------------
 Reporter:  msolution     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Plugins       |    Version:  6.6.1
 Severity:  normal        |   Keywords:  has-patch needs-testing
  Focuses:                |
--------------------------+-------------------------------------
 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
 <?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;";');
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61889>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list