Page MenuHomePhabricator

When creating a table via 'LoadExtensionSchemaUpdates' a missing semicolon in the sql file silently fails
Open, MediumPublicBUG REPORT

Description

Author: howardsmiller

Description:
To reproduce, follow the instructions in http://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates in order to create a new table. However, in the sql file do not put a semicolon on the end of the CREATE TABLE text.

Then run update.php and it will claim to have created the table but has not. Even with debugging turned up it doesn't complain.

Analysis:
The problem is in includes/db/Database.php function sourceStream(). This tries to recognise the end of a command either by feof becoming true or streamStatementEnd() finding the semicolon. However, an actual end of file will never end up in the block that executes $cmd, as an end-of-file will exit the while loop long before it gets to that if statement. Therefore, a missing semicolon causes the loop to drop through and return TRUE as if the file was empty.

The underlying issue is that the code to process $cmd should not be inside the loop. That's a bit weird!


Version: 1.21.x
Severity: major

Details

Reference
bz40979

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 12:45 AM
bzimport set Reference to bz40979.
bzimport added a subscriber: Unknown Object (MLST).

sumanah wrote:

Thanks for the bug report, Howard. Good catch.

Have you been able to check whether this same problem happens in the most current version of MediaWiki (the code in git master)?

howardsmiller wrote:

Hi,

This was with version 1.21alpha (3cf0ce4) pulled from git in the last couple of days

sumanah wrote:

Thanks for that update, Howard. CC'ing a couple people who could potentially fix.

freak wrote:

I'm a bit puzzeled ... why shouldn't you put a semicolon at the end of the CREATE statement?

I think the rationale is that semicolon is only a separator of multiple SQL statements, not a mandatory syntax item.

Aklapper lowered the priority of this task from High to Medium.Mar 3 2015, 5:33 PM
Aklapper subscribed.
Aklapper changed the subtype of this task from "Task" to "Bug Report".Feb 15 2022, 9:39 PM