Make WordPress Core

#63976 closed defect (bug) (fixed)

dbDelta returns unnecessary update if tablename is in backticks

Reported by: leewillis77 Owned by: SergeyBiryukov
Priority: normal Milestone: 6.9
Component: Database Version: 6.8.2
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

If the SQL passed to dbDelta has backticks around the tablename, then dbDelta will always return an update implying that the table will be created, even if it already exists and no changes are required.

E.g. the following code:

<?php

require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$for_update = dbDelta('CREATE TABLE `foo` (id INT)');

will always return the following array, even when the table exists and no changes are required:

[`foo`] => Created table `foo`

Patch to follow

Attachments (1)

patch-63976.diff​ (1.6 KB ) - added by leewillis77 13 months ago.

Download all attachments as: .zip

Change History (5)

This ticket was mentioned in ​PR #9888 on ​WordPress/wordpress-develop by ​@leewillis77.


13 months ago
#1

  • Keywords has-patch has-unit-tests added

This change ensures that dbDelta does not erroneously return an apparent update to tables when the tablename contains backticks.

Trac ticket: https://core.trac.wordpress.org/ticket/63976

#2 @swissspidy
13 months ago

  • Milestone Awaiting Review → 6.9

Tip: adding a PR is enough, no need to upload a patch file as well :-)

#4 @SergeyBiryukov
13 months ago

  • Owner set to SergeyBiryukov
  • Resolution → fixed
  • Status new → closed

In 60782:

Database: Do not report an extra update in dbDelta() with backticks in table name.

Follow-up to [10948], [20704].

Props leewillis77, swissspidy, johnbillion, SergeyBiryukov.
Fixes #63976.

Note: See TracTickets for help on using tickets.