Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#63976 closed defect (bug) (fixed)

dbDelta returns unnecessary update if tablename is in backticks

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

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 7 months ago.

Download all attachments as: .zip

Change History (5)

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


7 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
7 months ago

  • Milestone changed from Awaiting Review to 6.9

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

#4 @SergeyBiryukov
7 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to 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.