Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -516,16 +516,18 @@ |
517 | 517 | # Note that we don't bother changing around the prefixes here be- |
518 | 518 | # cause we know we're using MySQL anyway. |
519 | 519 | |
520 | | - $res = $this->query( "SHOW CREATE TABLE $oldName" ); |
| 520 | + $res = $this->query( 'SHOW CREATE TABLE ' . $this->addIdentifierQuotes( $oldName ) ); |
521 | 521 | $row = $this->fetchRow( $res ); |
522 | 522 | $oldQuery = $row[1]; |
523 | 523 | $query = preg_replace( '/CREATE TABLE `(.*?)`/', |
524 | | - "CREATE $tmp TABLE `$newName`", $oldQuery ); |
| 524 | + "CREATE $tmp TABLE " . $this->addIdentifierQuotes( $newName ), $oldQuery ); |
525 | 525 | if ($oldQuery === $query) { |
526 | 526 | # Couldn't do replacement |
527 | 527 | throw new MWException( "could not create temporary table $newName" ); |
528 | 528 | } |
529 | 529 | } else { |
| 530 | + $newName = $this->addIdentifierQuotes( $newName ); |
| 531 | + $oldName = $this->addIdentifierQuotes( $oldName ); |
530 | 532 | $query = "CREATE $tmp TABLE $newName (LIKE $oldName)"; |
531 | 533 | } |
532 | 534 | $this->query( $query, $fname ); |
Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -783,16 +783,19 @@ |
784 | 784 | |
785 | 785 | function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseOracle::duplicateTableStructure' ) { |
786 | 786 | global $wgDBprefix; |
| 787 | + $this->setFlag( DBO_DDLMODE ); |
787 | 788 | |
788 | 789 | $temporary = $temporary ? 'TRUE' : 'FALSE'; |
789 | 790 | |
790 | | - $newName = trim( strtoupper( $newName ), '"'); |
791 | | - $oldName = trim( strtoupper( $oldName ), '"'); |
| 791 | + $newName = strtoupper( $newName ); |
| 792 | + $oldName = strtoupper( $oldName ); |
792 | 793 | |
793 | | - $tabName = substr( $newName, strlen( $wgDBprefix ) ); |
794 | | - $oldPrefix = substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) ); |
| 794 | + $tabName = $this->addIdentifierQuotes( substr( $newName, strlen( $wgDBprefix ) ) ); |
| 795 | + $oldPrefix = $this->addIdentifierQuotes( substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) ) ); |
| 796 | + $newPrefix = $this->addIdentifierQuotes( $wgDBprefix ); |
795 | 797 | |
796 | | - return $this->doQuery( 'BEGIN DUPLICATE_TABLE(\'' . $tabName . '\', \'' . $oldPrefix . '\', \'' . strtoupper( $wgDBprefix ) . '\', ' . $temporary . '); END;' ); |
| 798 | + $this->clearFlag( DBO_DDLMODE ); |
| 799 | + return $this->doQuery( "BEGIN DUPLICATE_TABLE( $tabName, $oldPrefix, $newPrefix, $temporary ); END;" ); |
797 | 800 | } |
798 | 801 | |
799 | 802 | function listTables( $prefix = null, $fname = 'DatabaseOracle::listTables' ) { |
— | — | @@ -1075,6 +1078,12 @@ |
1076 | 1079 | } |
1077 | 1080 | |
1078 | 1081 | public function addIdentifierQuotes( $s ) { |
| 1082 | + return parent::addIdentifierQuotes( $s ); |
| 1083 | + |
| 1084 | + /* Does this old code make any sense? |
| 1085 | + * We could always use quoted identifier. |
| 1086 | + * See http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements008.htm |
| 1087 | + */ |
1079 | 1088 | if ( !$this->mFlags & DBO_DDLMODE ) { |
1080 | 1089 | $s = '"' . str_replace( '"', '""', $s ) . '"'; |
1081 | 1090 | } |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -748,6 +748,8 @@ |
749 | 749 | } |
750 | 750 | |
751 | 751 | function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabasePostgres::duplicateTableStructure' ) { |
| 752 | + $newName = $this->addIdentifierQuotes( $newName ); |
| 753 | + $oldName = $this->addIdentifierQuotes( $oldName ); |
752 | 754 | return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname ); |
753 | 755 | } |
754 | 756 | |
Index: trunk/phase3/includes/db/CloneDatabase.php |
— | — | @@ -92,14 +92,14 @@ |
93 | 93 | # fix back and forth so tableName() works right. |
94 | 94 | |
95 | 95 | self::changePrefix( $this->oldTablePrefix ); |
96 | | - $oldTableName = $this->db->tableName( $tbl ); |
| 96 | + $oldTableName = $this->db->tableName( $tbl, false ); |
97 | 97 | |
98 | 98 | self::changePrefix( $this->newTablePrefix ); |
99 | | - $newTableName = $this->db->tableName( $tbl ); |
| 99 | + $newTableName = $this->db->tableName( $tbl, false ); |
100 | 100 | |
101 | 101 | if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres' ) ) ) { |
102 | 102 | $this->db->dropTable( $tbl, __METHOD__ ); |
103 | | - wfDebug( __METHOD__." dropping {$this->newTablePrefix}{$oldTableName}\n", true); |
| 103 | + wfDebug( __METHOD__." dropping {$newTableName}\n", true); |
104 | 104 | //Dropping the oldTable because the prefix was changed |
105 | 105 | } |
106 | 106 | |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -254,10 +254,10 @@ |
255 | 255 | /** |
256 | 256 | * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks |
257 | 257 | */ |
258 | | - function tableName( $name ) { |
| 258 | + function tableName( $name, $quoted = true ) { |
259 | 259 | // table names starting with sqlite_ are reserved |
260 | 260 | if ( strpos( $name, 'sqlite_' ) === 0 ) return $name; |
261 | | - return str_replace( '"', '', parent::tableName( $name ) ); |
| 261 | + return str_replace( '"', '', parent::tableName( $name, $quoted ) ); |
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
— | — | @@ -596,14 +596,13 @@ |
597 | 597 | } |
598 | 598 | |
599 | 599 | function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseSqlite::duplicateTableStructure' ) { |
600 | | - |
601 | | - $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name='$oldName' AND type='table'", $fname ); |
| 600 | + $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" . $this->addQuotes( $oldName ) . " AND type='table'", $fname ); |
602 | 601 | $obj = $this->fetchObject( $res ); |
603 | 602 | if ( !$obj ) { |
604 | 603 | throw new MWException( "Couldn't retrieve structure for table $oldName" ); |
605 | 604 | } |
606 | 605 | $sql = $obj->sql; |
607 | | - $sql = preg_replace( '/\b' . preg_quote( $oldName ) . '\b/', $newName, $sql, 1 ); |
| 606 | + $sql = preg_replace( '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/', $this->addIdentifierQuotes( $newName ), $sql, 1 ); |
608 | 607 | if ( $temporary ) { |
609 | 608 | if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) { |
610 | 609 | wfDebug( "Table $oldName is virtual, can't create a temporary duplicate.\n" ); |