Builds the DDL SQL to rename a table
@return string
975317
public function getRenameTableDDL($fromTableName, $toTableName)
    {
        $pattern = "
RENAME TABLE %s TO %s;
";

        return sprintf($pattern,
            $this->quoteIdentifier($fromTableName),
            $this->quoteIdentifier($toTableName)
        );
    }
25952
private function getRenamedColumns($tableName, TableDiff $diff)
    {
        foreach (array_keys($diff->renamedColumns) as $colName) {
            $this->addMessage($tableName, sprintf('renamed column `%s`', $colName));
        }
    }
1098740
final function Table($alias = '', array $fieldAliases = array())
    {
        $sql = $this->SqlBuilder();
        return $sql->Table($this->TableName(), $this->FieldNames($fieldAliases), $alias);
    }
1373380
public function getTableName()
    {
        if (!$this->through) {
            $parts = [
                TableNameResolver::getTableName($this->getTable()),
                TableNameResolver::getTableName($this->getRelatedTable()),
            ];
            sort($parts);

            return '{{%'.implode('_', $parts).'}}';
        }

        return call_user_func([$this->through, 'tableName']);
    }
692454
public function rename($newName, $returnNew = true)
    {
        // Mysql 5.1.7 do not have RENAME DATABASE syntax anymore, so we use rename tables to do that.
        // @see: http://stackoverflow.com/questions/67093/how-do-i-quickly-rename-a-mysql-database-change-schema-name?page=1&tab=votes#tab-top
        $newDatabase = $this->db->getDatabase($newName)->create();

        $tables = $this->db->getReader(MysqlGrammar::showDbTables($this->name))->loadObjectList();

        foreach ($tables as $table) {
            $name = $table->Name;

            $this->db->setQuery(
                sprintf(
                    'RENAME TABLE %s.%s TO %s.%s',
                    $this->db->quoteName($this->name),
                    $this->db->quoteName($name),
                    $this->db->quoteName($newName),
                    $this->db->quoteName($name)
                )
            )->execute();
        }

        $this->drop(true);

        if ($returnNew) {
            return $newDatabase;
        }

        return $this;
    }
213215
public function setNameFromTable()
    {
        $fullName = '';
        $upperCase = true;
        for ($i = 0; $i < strlen($this->table); $i++) {
            $character = $this->table[$i];

            if ($character === '_') {
                $upperCase = true;
            } else {
                $fullName .= $upperCase ? strtoupper($character) : $character;
                $upperCase = false;
            }
        }

        if (substr($fullName, -3) === 'ies') {
            $fullName = substr($fullName, 0, -3) . 'y';
        } elseif (substr($fullName, -3) === 'ses') {
            $fullName = substr($fullName, 0, -3) . 's';
        } elseif (substr($fullName, -1) === 's') {
            $fullName = substr($fullName, 0, -1);
        }

        $this->name = $fullName;
        return $this;
    }
113434
public function rename($newName, $returnNew = true)
    {
        $this->db->setQuery(
            'RENAME TABLE ' . $this->db->quoteName($this->getName()) . ' TO ' . $this->db->quoteName($newName)
        );

        $this->db->execute();

        if ($returnNew) {
            return $this->db->getTable($newName);
        }

        return $this->reset();
    }
637914
public function tableNames()
    {
        $names          = [];
        $query          = $this->getQueryBuilder();
        $names[]        = $query->from;
        $joins          = $query->joins ?: [];
        $databasePrefix = $this->prefix;
        foreach ($joins as $join) {
            $table   = preg_split('/ as /i', $join->table);
            $names[] = $table[0];
            if (isset($table[1]) && !empty($databasePrefix) && strpos($table[1], $databasePrefix) == 0) {
                $names[] = preg_replace('/^' . $databasePrefix . '/', '', $table[1]);
            }
        }

        return $names;
    }
115330
public function dbgSelect() {
		$sql = $this->buildSQL();
		$params = $this->getParameters();

		return $this->replaceParams($sql, $params);
	}
822728
public function getModifyTableIndicesDDL(TableDiff $tableDiff)
    {
        $ret = '';

        foreach ($tableDiff->getRemovedIndices() as $index) {
            $ret .= $this->getDropIndexDDL($index);
        }

        foreach ($tableDiff->getAddedIndices() as $index) {
            $ret .= $this->getAddIndexDDL($index);
        }

        foreach ($tableDiff->getModifiedIndices() as $indexModification) {
            list($fromIndex, $toIndex) = $indexModification;
            $ret .= $this->getDropIndexDDL($fromIndex);
            $ret .= $this->getAddIndexDDL($toIndex);
        }

        return $ret;
    }
397140
public function generate()
    {
        $result = '';

        $table  = $this->buildTable();
        $fields = $this->buildFields();
        $where  = $this->buildWhere();

        $result.='UPDATE '.$table.' SET '.$fields;

        if ($where != '') {
            $result.=' '.$where;
        }

        return $result;
    }
931198
public function renameTable($table, $name)
    {
        //Argument 1 must be a string, 2 must be string
        Argument::i()->test(1, 'string')->argument(2, 'string');
        
        $this->query = 'RENAME TABLE `' . $table . '` TO `' . $name . '`';
        return $this;
    }
1194163
public function getExtrasDDLWithDelimiter()
    {
        $ddls = $this->getExtrasDDL();
        $start = "DELIMITER {$this->delimiter}";
        $end = 'DELIMITER ;';

        $newDdls = [];

        foreach ($ddls as $idx => $ddl) {
            $newDdls[] = $start;
            if (!preg_match('/;$/', $ddl)) {
                $newDdls[] = $ddl . ' ' . $this->delimiter;
            } else {
                $newDdls[] = preg_replace('/;$/', $this->delimiter, $ddl);
            }
            $newDdls[] = $end;
        }

        return implode(PHP_EOL, $newDdls) . PHP_EOL . $end . PHP_EOL;
    }
742410
public function getUpdatedFieldName()
    {
        if (!isset($this->data['fields']) || empty($this->data['fields'])) {
            return false;
        }

        $table = $this->data['name'];
        foreach ($this->data['fields'] as $field) {
            if ($field['name'] === 'updated') {
                return $table . '_' . $field['name'];
            }
        }

        return false;
    }
15328
public function rename_table(xmldb_table $xmldb_table, $newname) {
        // Check newname isn't empty
        if (!$newname) {
            throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');
        }

        $check = new xmldb_table($newname);

        // Check table already renamed
        if (!$this->table_exists($xmldb_table)) {
            if ($this->table_exists($check)) {
                throw new ddl_exception('ddlunknownerror', null, 'table probably already renamed');
            } else {
                throw new ddl_table_missing_exception($xmldb_table->getName());
            }
        }

        // Check new table doesn't exist
        if ($this->table_exists($check)) {
            throw new ddl_exception('ddltablealreadyexists', $check->getName(), 'can not rename table');
        }

        if (!$sqlarr = $this->generator->getRenameTableSQL($xmldb_table, $newname)) {
            throw new ddl_exception('ddlunknownerror', null, 'table rename sql not generated');
        }

        $this->execute_sql_arr($sqlarr);
    }
1371376
public function getRenameColumnDDL($fromColumn, $toColumn)
    {
        $pattern = "
ALTER TABLE %s RENAME COLUMN %s TO %s;
";

        return sprintf($pattern,
            $this->quoteIdentifier($fromColumn->getTable()->getName()),
            $this->quoteIdentifier($fromColumn->getName()),
            $this->quoteIdentifier($toColumn->getName())
        );
    }
1138634
final public function renameTable($table, $to)
    {
        if ($this->adapter->getName() == 'mysql') {
            $command = 'RENAME';
        } else {
            $command = 'ALTER TABLE';
        }

        $sql = sprintf('%s %s TO %s', $command, $table, $to);

        return $this->executeSqlQuery($sql);
    }