r85906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85905‎ | r85906 | r85907 >
Date:18:54, 12 April 2011
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Change the duplicateTableStructure() to use the original names.
It is now duplicateTableStructure() duty to addIdentifierQuotes() them.
Fixed bug for mysql < 4.1 where the new name would be quoted twice.

Always quote identifier in Oracle, doing otherwise seems a bug (can someone confirm?)
Modified paths:
  • /trunk/phase3/includes/db/CloneDatabase.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -516,16 +516,18 @@
517517 # Note that we don't bother changing around the prefixes here be-
518518 # cause we know we're using MySQL anyway.
519519
520 - $res = $this->query( "SHOW CREATE TABLE $oldName" );
 520+ $res = $this->query( 'SHOW CREATE TABLE ' . $this->addIdentifierQuotes( $oldName ) );
521521 $row = $this->fetchRow( $res );
522522 $oldQuery = $row[1];
523523 $query = preg_replace( '/CREATE TABLE `(.*?)`/',
524 - "CREATE $tmp TABLE `$newName`", $oldQuery );
 524+ "CREATE $tmp TABLE " . $this->addIdentifierQuotes( $newName ), $oldQuery );
525525 if ($oldQuery === $query) {
526526 # Couldn't do replacement
527527 throw new MWException( "could not create temporary table $newName" );
528528 }
529529 } else {
 530+ $newName = $this->addIdentifierQuotes( $newName );
 531+ $oldName = $this->addIdentifierQuotes( $oldName );
530532 $query = "CREATE $tmp TABLE $newName (LIKE $oldName)";
531533 }
532534 $this->query( $query, $fname );
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -783,16 +783,19 @@
784784
785785 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseOracle::duplicateTableStructure' ) {
786786 global $wgDBprefix;
 787+ $this->setFlag( DBO_DDLMODE );
787788
788789 $temporary = $temporary ? 'TRUE' : 'FALSE';
789790
790 - $newName = trim( strtoupper( $newName ), '"');
791 - $oldName = trim( strtoupper( $oldName ), '"');
 791+ $newName = strtoupper( $newName );
 792+ $oldName = strtoupper( $oldName );
792793
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 );
795797
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;" );
797800 }
798801
799802 function listTables( $prefix = null, $fname = 'DatabaseOracle::listTables' ) {
@@ -1075,6 +1078,12 @@
10761079 }
10771080
10781081 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+ */
10791088 if ( !$this->mFlags & DBO_DDLMODE ) {
10801089 $s = '"' . str_replace( '"', '""', $s ) . '"';
10811090 }
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -748,6 +748,8 @@
749749 }
750750
751751 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabasePostgres::duplicateTableStructure' ) {
 752+ $newName = $this->addIdentifierQuotes( $newName );
 753+ $oldName = $this->addIdentifierQuotes( $oldName );
752754 return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname );
753755 }
754756
Index: trunk/phase3/includes/db/CloneDatabase.php
@@ -92,14 +92,14 @@
9393 # fix back and forth so tableName() works right.
9494
9595 self::changePrefix( $this->oldTablePrefix );
96 - $oldTableName = $this->db->tableName( $tbl );
 96+ $oldTableName = $this->db->tableName( $tbl, false );
9797
9898 self::changePrefix( $this->newTablePrefix );
99 - $newTableName = $this->db->tableName( $tbl );
 99+ $newTableName = $this->db->tableName( $tbl, false );
100100
101101 if( $this->dropCurrentTables && !in_array( $this->db->getType(), array( 'postgres' ) ) ) {
102102 $this->db->dropTable( $tbl, __METHOD__ );
103 - wfDebug( __METHOD__." dropping {$this->newTablePrefix}{$oldTableName}\n", true);
 103+ wfDebug( __METHOD__." dropping {$newTableName}\n", true);
104104 //Dropping the oldTable because the prefix was changed
105105 }
106106
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -254,10 +254,10 @@
255255 /**
256256 * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
257257 */
258 - function tableName( $name ) {
 258+ function tableName( $name, $quoted = true ) {
259259 // table names starting with sqlite_ are reserved
260260 if ( strpos( $name, 'sqlite_' ) === 0 ) return $name;
261 - return str_replace( '"', '', parent::tableName( $name ) );
 261+ return str_replace( '"', '', parent::tableName( $name, $quoted ) );
262262 }
263263
264264 /**
@@ -596,14 +596,13 @@
597597 }
598598
599599 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 );
602601 $obj = $this->fetchObject( $res );
603602 if ( !$obj ) {
604603 throw new MWException( "Couldn't retrieve structure for table $oldName" );
605604 }
606605 $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 );
608607 if ( $temporary ) {
609608 if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) {
610609 wfDebug( "Table $oldName is virtual, can't create a temporary duplicate.\n" );

Follow-up revisions

RevisionCommit summaryAuthorDate
r85919I forgot to commit this in r85906platonides20:48, 12 April 2011

Comments

#Comment by Freakolowsky (talk | contribs)   08:16, 15 April 2011

This will not fly!!!

You are reading documentation for Oracle 10g (10.2) ... the current state of Oracle code in MW is written for 9i (9.2) which has very limited (i.e. some but buggy) support for object naming in quotes and most of people i know use 9i for MW.

So could you please STOP trying to stuff these quotes in the code every 2 months.

#Comment by Freakolowsky (talk | contribs)   10:52, 15 April 2011

Quotes gone ... once again.

#Comment by Platonides (talk | contribs)   12:08, 16 April 2011

That was r86112

Status & tagging log