[wp-trac] [WordPress Trac] #59481: dbDelta do useless request when type case is not the same between query and describe result

WordPress Trac noreply at wordpress.org
Wed Sep 27 22:17:19 UTC 2023


#59481: dbDelta do useless request when type case is not the same between query and
describe result
---------------------------+-----------------------------
 Reporter:  tristanleboss  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Database       |    Version:  6.3
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 While debugging why a call to `dbDelta` was not working, I discovered in
 the function output  (an array of performed changes) that it was doing
 some useless changes: "Changed type of wp_table.field from varchar(255) to
 VARCHAR(255)".

 Indeed, on my MySQL 8.0.31 Windows x64 version (installed by Wampserver),
 if I do "DESCRIBE wp_table", the "Type" column of the result is always
 lowercase. If somehow, you wrote your "CREATE TABLE" statements with a
 different case for varchar columns, dbDelta will detect a change. It does
 it only for varchar. If I change my varchar to be lowercase in the SQL I
 use for dbDelta, it doesn't try to change the type.

 {{{#!php
 <?php

 $sql = 'CREATE TABLE `'.$wpdb->prefix.'table` (
                         `object_id` INT(10) NOT NULL,
                         `group_term_slug` VARCHAR(255) NOT NULL
 ) '.$wpdb->get_charset_collate().';';

 $result = dbDelta($sql); // Will contain both "Created table wp_table" and
 "Changed type of wp_table.field from varchar(255) to VARCHAR(255)"

 $sql = 'CREATE TABLE `'.$wpdb->prefix.'table` (
                         `object_id` INT(10) NOT NULL,
                         `group_term_slug` varchar(255) NOT NULL
 ) '.$wpdb->get_charset_collate().';';

 $result = dbDelta($sql); // Will NOT contain "Changed type of
 wp_table.field from varchar(255) to VARCHAR(255)", only "Created table
 wp_table"




 }}}

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


More information about the wp-trac mailing list