Per CR for r58631, moved default duplicateTableStructure() implementation to Database...
authorMax Semenik <maxsem@users.mediawiki.org>
Fri, 11 Dec 2009 19:53:10 +0000 (19:53 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Fri, 11 Dec 2009 19:53:10 +0000 (19:53 +0000)
includes/db/Database.php
includes/db/DatabaseMysql.php

index 21049b6..a5f85c0 100644 (file)
@@ -2002,7 +2002,7 @@ abstract class DatabaseBase {
         * @return Boolean: true if operation was successful
         */
        function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'Database::duplicateTableStructure' ) {
-               return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName)", $fname );
+               throw new MWException( 'DatabaseBase::duplicateTableStructure is not implemented in descendant class' );
        }
 
        /**
index f2c8508..7087220 100644 (file)
@@ -403,6 +403,7 @@ class DatabaseMysql extends DatabaseBase {
        }
 
        function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseMysql::duplicateTableStructure' ) {
+               $tmp = $temporary ? 'TEMPORARY ' : '';
                if ( strcmp( $this->getServerVersion(), '4.1' ) < 0 ) {
                        # Hack for MySQL versions < 4.1, which don't support
                        # "CREATE TABLE ... LIKE". Note that
@@ -414,17 +415,17 @@ class DatabaseMysql extends DatabaseBase {
 
                        $res = $this->query( "SHOW CREATE TABLE $oldName" );
                        $row = $this->fetchRow( $res );
-                       $create = $row[1];
-                       $create_tmp = preg_replace( '/CREATE TABLE `(.*?)`/', 
-                               'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . "TABLE `$newName`", $create );
-                       if ($create === $create_tmp) {
+                       $oldQuery = $row[1];
+                       $query = preg_replace( '/CREATE TABLE `(.*?)`/', 
+                               "CREATE $tmp TABLE `$newName`", $oldQuery );
+                       if ($oldQuery === $query) {
                                # Couldn't do replacement
                                throw new MWException( "could not create temporary table $newName" );
                        }
-                       $this->query( $create_tmp, $fname );
                } else {
-                       return parent::duplicateTableStructure( $oldName, $newName, $temporary );
+                       $query = "CREATE $tmp TABLE $newName (LIKE $oldName)";
                }
+               $this->query( $query, $fname );
        }
 
 }