Make WordPress Core

Opened 6 years ago

Last modified 6 years ago

#46932 new defect (bug)

dbDelta does not account for MySQL keywords being used as key names

Reported by: calevans's profile CalEvans Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Database Keywords:
Focuses: administration Cc:

Description

This, is a bug, but it is an edge case. I realize that.

In processing data coming from a third party, my plugin sets up a table in MySQL that uses the field name key. MySQL allows this because it is wrapped in back-ticks.

The field does not cause a problem in the WordPress code, but I also index on that field and that does cause a problem.

KEY `i_key` (`key`)

This causes a small problem with dbDelta(). The regex starting at line 2650 will not properly identify the index. Thus, the next line, 2676, will try to use the array element $index_type['index_type'] which does not exist. This throws a warning in PHP.

There are two possible solutions I see.

  1. The simple solution is to add a check for an empty array above 2767. This won't solve the problem but it will stop the warning.
  2. The more complete solution would be to change the regex to exclude the keyword matches if they are inside of backticks. This will solve the problem properly.

There may be other solutions, those are just the ones I have identified.

Cheers! :)
=C=

Change History (1)

#1 @SergeyBiryukov
6 years ago

  • Component changed from Plugins to Database
Note: See TracTickets for help on using tickets.