Page MenuHomePhabricator

update.php fails with SQL error because database name is not properly quoted.
Closed, ResolvedPublic

Description

Author: van.de.bugger

Description:
I am upgrading MediaWiki from 1.18.4 to 1.19.1, and running maintenance/update.php script. It fails with error:

A database query syntax error has occurred.
The last attempted database query was:
"SHOW INDEX FROM opencaching-su.shar_user"
from within function "UserDupes::hasUniqueIndex".
Database returned error "1064: You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right syntax to
use near '-su.shar_user' at line 1 (localhost)"

"opencaching-su" is the name of my database; "shar_" is the table prefix for shared tables.

I guess the problem is in not properly quoted database name (it contains dash). I looks the bug is in file Database.php, line ~1975, function tableName:

if ( isset( $database ) ) {

$database = ( $format == 'quoted' || $this->isQuotedIdentifier( $database ) ? $database : $this->addIdentifierQuotes( $database ) );

}

I am not sure about PHP priorities of || and ? operators, but I have added "echo" statement and saw that $database is set and remains unchanged after this piece of code. Then I fixed it to:

if ( isset( $database ) ) {

if ( $format == 'quoted' ) {
    $database = ( $this->isQuotedIdentifier( $database ) ? $database : $this->addIdentifierQuotes( $database ) );
}

}

This variant works well to me.


Version: 1.19
Severity: normal

Details

Reference
bz38406

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 1:12 AM
bzimport set Reference to bz38406.
bzimport added a subscriber: Unknown Object (MLST).

Fix pending review in Gerrit change #15867.