Make WordPress Core

Opened 2 years ago

Closed 12 months ago

#21272 closed defect (bug) (fixed)

reporting typo in dbDelta

Reported by: apimlott Owned by: nacin
Milestone: 3.6 Priority: normal
Severity: minor Version: 3.4.1
Component: Database Keywords: has-patch
Focuses: Cc:


In dbDelta, there is the section:

                // For every remaining index specified for the table
                foreach ( (array) $indices as $index ) {
                        // Push a query line into $cqueries that adds the index to that table
                        $cqueries[] = "ALTER TABLE {$table} ADD $index";
                        $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;

Note that $for_update is updated with the wrong array index. This causes some updates not to be returned in $for_update. Better would be:

                        $for_update[$table.'.'.$index] = 'Added index '.$table.' '.$index;

Even this is not really right, since indexes and columns may have the same names. Given that the users of dbDelta don't even seem to care about the keys, it might be simpler just to change all the $for_update lines to

                        $for_update[] = ...

except for the first one that must be keyed on table name.

Attachments (2)

for-update-keys.diff (597 bytes) - added by wonderboymusic 23 months ago.
21272.diff (603 bytes) - added by wonderboymusic 18 months ago.

Download all attachments as: .zip

Change History (6)

comment:1 coffee2code2 years ago

  • Keywords needs-patch added
  • Version set to 3.4.1

comment:2 wonderboymusic23 months ago

  • Keywords has-patch added; needs-patch removed

Now arbitrarily adds items to array, rather than clobbering the key in the loop. Patch added.

wonderboymusic18 months ago

comment:3 wonderboymusic18 months ago

  • Milestone changed from Awaiting Review to 3.6

Updated patch applies cleanly against trunk

comment:4 nacin12 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 24584:

Avoid possible array collision in dbDelta when recording index adds. props apimlott, wonderboymusic. fixes #21272.

Note: See TracTickets for help on using tickets.