From 25009de08038b87d0e506f5ccb0b720fcb4f3847 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Fri, 11 Dec 2009 19:53:10 +0000 Subject: [PATCH] Per CR for r58631, moved default duplicateTableStructure() implementation to DatabaseMysql, replacing it with 'not implemented' exception throw --- includes/db/Database.php | 2 +- includes/db/DatabaseMysql.php | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 21049b6f55..a5f85c0828 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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' ); } /** diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index f2c8508ff7..7087220f32 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -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 ); } } -- 2.20.1