Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#8768 closed defect (bug) (duplicate)

dbDelta() queries fails with the ` char

Reported by: binnyva's profile binnyva Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: Plugins Keywords:
Focuses: Cc:


If I use the while creating a SQL query in a WP Plugin(if the SQL is created using phpMyAdmin export feature, it will have the quoting), dbDelta will not work. An example...

$sql = "CREATE TABLE `{$wpdb->prefix}eventr_event_attendee` (
		`event_ID` int(11) unsigned NOT NULL,
		`attendee_ID` int(11) unsigned NOT NULL,
		`added_on` datetime NOT NULL,
		`guests` int(2) NOT NULL default '0',
		KEY `event_ID` (`event_ID`,`attendee_ID`)

Will not work - but this will...

$sql = "CREATE TABLE {$wpdb->prefix}eventr_event_attendee (
		event_ID int(11) unsigned NOT NULL,
		attendee_ID int(11) unsigned NOT NULL,
		added_on datetime NOT NULL,
		guests int(2) NOT NULL default '0',
		KEY event_ID (event_ID,attendee_ID)

The easiest way to fix this is to replace all ` chars with an empty string in the dbDelta() function. But I think it is a bit too 'hacky'. I have created an alternative solution - the patch is attached.

I have tested it with WordPress 2.7 - with one of my plugins.

Attachments (1)

patch.txt (1.2 KB) - added by binnyva 15 years ago.
Patch for wp-admin/includes/upgrade.php

Download all attachments as: .zip

Change History (4)

15 years ago

Patch for wp-admin/includes/upgrade.php

#1 @mrmist
15 years ago

  • Version set to 2.7

I'm not sure that I get the point. Why not just code the plugin as in example 2 if that already works?...

#2 @jacobsantos
15 years ago

  • Keywords needs-patch needs-unittests added; has-patch removed

I would have to say that the culprit is in the preg_match() and your patch will only mask that issue (while being a huge WTF). More debugging is required.

#3 @mrmist
15 years ago

  • Keywords needs-patch needs-unittests removed
  • Milestone 2.8 deleted
  • Resolution set to duplicate
  • Status changed from new to closed


Note: See TracTickets for help on using tickets.