Make WordPress Core

Opened 9 years ago

Closed 8 years 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 9 years ago.
21272.diff (603 bytes) - added by wonderboymusic 9 years ago.

Download all attachments as: .zip

Change History (6)

#1 @coffee2code
9 years ago

  • Keywords needs-patch added
  • Version set to 3.4.1

#2 @wonderboymusic
9 years ago

  • Keywords has-patch added; needs-patch removed

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

9 years ago

#3 @wonderboymusic
9 years ago

  • Milestone changed from Awaiting Review to 3.6

Updated patch applies cleanly against trunk

#4 @nacin
8 years 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.