[wp-trac] [WordPress Trac] #46932: dbDelta does not account for MySQL keywords being used as key names
WordPress Trac
noreply at wordpress.org
Mon Apr 15 12:14:29 UTC 2019
#46932: dbDelta does not account for MySQL keywords being used as key names
----------------------------+-----------------------------
Reporter: CalEvans | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version:
Severity: minor | Keywords:
Focuses: administration |
----------------------------+-----------------------------
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=
--
Ticket URL: <https://core.trac.wordpress.org/ticket/46932>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list