WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#41335 new enhancement

dbDelta() does not recognize MySQL's IF NOT EXISTS statement

Reported by: kmaxim Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Upgrade/Install Keywords: has-patch reporter-feedback
Focuses: Cc:
PR Number:

Description

When a new table is creating with IF NOT EXISTS MySQL statement in query then array $cqueries(creational queries) will have invalid table names as keys.

The keys of the array use below in the function's code for fetch the table column structure in DESCRIBE statement.

Example query: CREATE TABLE wp_delta_table...
The extracted table name: wp_delta_table

Example query: CREATE TABLE IF NOT EXISTS wp_delta_table...
The extracted table name: IF

Attachments (2)

update.php (25.3 KB) - added by kmaxim 2 years ago.
Added IF NOT EXISTS statement when tablename index is created from a query
upgrade.diff (1.2 KB) - added by kmaxim 2 years ago.

Download all attachments as: .zip

Change History (4)

@kmaxim
2 years ago

Added IF NOT EXISTS statement when tablename index is created from a query

#1 @kmaxim
2 years ago

  • Keywords has-patch added

@kmaxim
2 years ago

#2 @pento
2 years ago

  • Keywords reporter-feedback added
  • Type changed from defect (bug) to enhancement
  • Version 4.8 deleted

Thank you for the feature request, @kmaxim!

Do you have a particular use case for this? dbDelta() generally doesn't need to support IF NOT EXISTS, because the function checks to see if the table exists, then decides whether it needs to create the table, or modify it to match the CREATE TABLE statement passed to it.

If you pass dbDelta() the same CREATE TABLE statement twice, it will do nothing the second time, as the table exists, and there are no changes to be made.

Note: See TracTickets for help on using tickets.