* @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' );
}
/**
}
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
$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 );
}
}