See {@link ReplaceColumnNames}.

@param DataTable $table
342744
public function filter($table)
    {
        if (!isset($this->nameToAppend) || '' === $this->nameToAppend || false === $this->nameToAppend) {
            return;
        }

        foreach ($table->getRows() as $row) {
            $columns = $row->getColumns();

            foreach ($columns as $column => $value) {
                $row->deleteColumn($column);
                $row->setColumn($column . $this->nameToAppend, $value);
            }

            $this->filterSubTable($row);
        }
    }
366507
private function recreateTable($table, $params)
    {
        // Bug by the PDO driver?
        // If the INSERT statement is incorrect and the transaction is running, the app is constantly called again !!
        // At some point, the browser says "Server does not respond".

        //$this->transaction(function() use($table, $params) {
            $quotedTable = $this->db->quoteName($table);
            $columns = $this->columns($table);
            $indexes = $this->indexes($table);
            $column  = $params['column'];
            $options = $params['options'];
            $oldColumns = '"' . str_replace(',', '","', str_replace('"', '""', implode(',', array_keys($columns)))) . '"';

            // 1. rename the old table
            $oldTable = 't' . uniqid();
            $this->renameTable($table, $oldTable);

            // 2. create the new table with the new column
            $columns[$column] = $options;
            $this->createTable($table, $columns);
            $newColumns = '"' . str_replace(',', '","', str_replace('"', '""', implode(',', array_keys($columns)))) . '"';

            // 3. copy the contents across from the original table
            /** @noinspection SqlNoDataSourceInspection */
            $quotedColumn = $this->db->quoteName($column);
            $zero = $this->zero($options['type']);
            $this->db->exec("INSERT INTO {$quotedTable} ({$newColumns}) SELECT {$oldColumns}, ? AS {$quotedColumn} FROM {$oldTable}", [$zero]);

            // 4. drop the old table
            /** @noinspection SqlNoDataSourceInspection */
            $this->db->exec("DROP TABLE {$oldTable}");

            // 5. Create the indexes
            foreach ($indexes as $attr) {
                $this->addIndex($table, $attr['columns'], $attr);
            }
        //});
    }
6263
public function replace($table, $data) {

        $_fileds = '';
        $_values = '';
        $_T_fields = $this->getTableFields($table);
        foreach ( $data as $_key => $_val ) {

            //自动过滤掉不存在的字段
            if ( !in_array( $_key, $_T_fields ) ) continue;

            $_fileds .= ( $_fileds=='' ) ? "`{$_key}`" : ", `{$_key}`";
            if ( is_null($_val) ) {
                $_val = 'NULL';
            } else {
                $_val = "'{$_val}'";
            }
            $_values .= ( $_values=='' ) ? "{$_val}" : ",{$_val}";
        }

        if ( $_fileds != '' ) {
            $_query = "REPLACE INTO {$table}(" . $_fileds . ") VALUES(" . $_values . ")";
            if ( $this->execute($_query) != false ) {
                return true;
            }

        }
        return false;
    }
314272
protected function addColumns(Table $table)
    {
        $stmt = $this->dbh->query(sprintf('SHOW COLUMNS FROM %s', $this->getPlatform()->doQuoting($table->getName())));

        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            $column = $this->getColumnFromRow($row, $table);
            $table->addColumn($column);
        }
    }
1329952
protected function updateColumn($table, $primary, $column)
    {
        $columns = $this->mergeColumns($primary, $column['name']);
        $where = $column['where'];

        foreach ($this->database->getRows($table, $columns, $where) as $rowNum => $row) {
            $this->database->updateByPrimary(
                $table,
                Helpers::arrayOnly($row, $primary),
                $column['name'],
                $this->calculateNewValue($column['replace'], $rowNum)
            );
        }
    }
226785
protected function fixTable(
        $table,
        /*# string */ $alias = ''
    )/*# : array */ {
        if (empty($table)) {
            $table = [];
        } elseif (!is_array($table)) {
            $table = empty($alias) ? [$table] : [$table => $alias];
        }
        return $table;
    }
905430
private function _insert_replace( $table, $data, $method ) {
		if ( ! isset( $this->table_defines[ $table ] ) ) {
			return false;
		}
		if ( $method !== 'insert' && $method !== 'replace' ) {
			return false;
		}
		if ( $method === 'replace' && ! isset( $data['id'] ) ) {
			return false;
		}

		/** @var \wpdb $wpdb */
		global $wpdb;
		$columns = $this->table_defines[ $table ]['columns'];

		$data = $this->set_update_params( $data, $method === 'insert', true, false );
		list ( $_data, $_format ) = $this->filter( $data, $columns );

		return $wpdb->$method( $this->get_table( $table ), $_data, $_format );
	}
194534
public function filter($table)
    {
        if (empty($this->metadataColumn) || empty($this->valueToPrepend)) {
            return;
        }

        $metadataColumn = $this->metadataColumn;
        $valueToPrepend = $this->valueToPrepend;

        $table->filter(function (DataTable $dataTable) use ($metadataColumn, $valueToPrepend) {
            foreach ($dataTable->getRows() as $row) {
                $filter = $row->getMetadata($metadataColumn);
                if ($filter !== false) {
                    $row->setMetadata($metadataColumn, $valueToPrepend . $filter);
                }
            }
        });
    }
205835
public function update( $table )
    {
        $table = $this->getIdentifier( $table );
        $table = $this->getPrefixedTableNames($table);
        $this->table = $table;
        return $this;
    }
1042754
public function dontRequireTable($table)
    {
        if (!isset($this->tableList[strtolower($table)])) {
            return;
        }
        $prefix = "_obsolete_{$table}";
        $suffix = '';
        $renameTo = $prefix . $suffix;
        while (isset($this->tableList[strtolower($renameTo)])) {
            $suffix = $suffix
                    ? ((int)$suffix + 1)
                    : 2;
            $renameTo = $prefix . $suffix;
        }
        $renameFrom = $this->tableList[strtolower($table)];
        $this->renameTable($renameFrom, $renameTo);
        $this->alterationMessage("Table $table: renamed to $renameTo", "obsolete");
    }
355658
public function filter($table)
    {
        foreach ($table->getRows() as $row) {
            $value = $row->getColumn($this->columnToDecode);
            if ($value !== false) {
                $value = self::decodeLabelSafe($value);
                $row->setColumn($this->columnToDecode, $value);

                $this->filterSubTable($row);
            }
        }
    }
1030912
public function renameTable($table, $newName)
	{
		echo "    > rename table $table to $newName ...";
		$time=microtime(true);
		$this->getDbConnection()->createCommand()->renameTable($table, $newName);
		echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
	}
1217006
public function filter($table)
    {
        if ($this->applyToSummaryRow) {
            $rows = $table->getRows();
        } else {
            $rows = $table->getRowsWithoutSummaryRow();
        }

        foreach ($rows as $key => $row) {
            $parameters = array();
            foreach ($this->columnsToRead as $columnsToRead) {
                $parameters[] = $row->getColumn($columnsToRead);
            }

            if (!is_null($this->functionParameters)) {
                $parameters = array_merge($parameters, $this->functionParameters);
            }
            if (!is_null($this->functionToApply)) {
                $newValue = call_user_func_array($this->functionToApply, $parameters);
            } else {
                $newValue = $parameters[0];
            }
            if ($newValue !== false) {
                $row->addMetadata($this->metadataToAdd, $newValue);
            }
        }
    }
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);
    }
836722
public function replaceTable($oldTable, $newTable) {
		$this->where = $this->replaceTableInConditions($this->where, $oldTable, $newTable);
		$this->joins = $this->replaceTableInConditions($this->joins, $oldTable, $newTable);
		#using regex to replace table names not preceded by one of the following character
		if($this->groupBy)
			$this->groupBy[0] = preg_replace('/(?<![a-zA-Z0-9_])'.$oldTable.'\./', $newTable.'.', $this->groupBy[0]);
	}
501713
private function updateTable(array $columns, Table &$table) {
        $this->updateReferences($table);
        $canUpdate = false;
        foreach ($columns['remove'] as $columnName) {
            $canUpdate = true;
            $table->dropColumn(Util::camelTo_($columnName));
        }

        foreach ($columns['update'] as $columnName => &$desc) {
            $canUpdate = true;
            $dbColumnName = Util::camelTo_($columnName);

            $this->checkIndexes($dbColumnName, $desc, $table);

            if (isset($desc['attrs']['reference'])) {
                $onDelete = (isset($desc['attrs']['reference']['onDelete'])) ?
                        $desc['attrs']['reference']['onDelete'] : 'RESTRICT';
                $onUpdate = (isset($desc['attrs']['reference']['onUpdate'])) ?
                        $desc['attrs']['reference']['onUpdate'] : 'RESTRICT';
                $table->alterReference($dbColumnName, $desc['attrs']['reference']['table'], $desc['attrs']['reference']['column'], $onDelete, $onUpdate);
                unset($desc['attrs']['reference']['table']);
                unset($desc['attrs']['reference']['column']);
                unset($desc['attrs']['reference']['model']);

                if (isset($desc['attrs']['reference']['onUpdate']))
                    unset($desc['attrs']['reference']['onUpdate']);
                if (isset($desc['attrs']['reference']['onDelete']))
                    unset($desc['attrs']['reference']['onDelete']);

                if (!empty($desc['attrs']['reference'])) {
                    $desc['attrs'] = array_merge($desc['attrs'], $desc['attrs']['reference']);
                    unset($desc['attrs']['reference']);
                }
            }

            $table->alterColumn($dbColumnName, $this->parseAttributes($columnName, $desc, false));

            if (isset($desc['attrs']['primary']) && $desc['attrs']['primary'])
                $table->setPrimaryKey($dbColumnName);
        }

        foreach ($columns['new'] as $columnName => $desc) {
            $canUpdate = true;
            $dbColumnName = Util::camelTo_($columnName);

            if (isset($desc['attrs']['reference'])) {
                $onDelete = (isset($desc['attrs']['reference']['onDelete'])) ?
                        $desc['attrs']['reference']['onDelete'] : 'RESTRICT';
                $onUpdate = (isset($desc['attrs']['reference']['onUpdate'])) ?
                        $desc['attrs']['reference']['onUpdate'] : 'RESTRICT';
                $table->addReference($dbColumnName, $desc['attrs']['reference']['table'], $desc['attrs']['reference']['column'], $onDelete, $onUpdate);
                unset($desc['attrs']['reference']['table']);
                unset($desc['attrs']['reference']['column']);
                unset($desc['attrs']['reference']['model']);

                if (isset($desc['attrs']['reference']['onUpdate']))
                    unset($desc['attrs']['reference']['onUpdate']);
                if (isset($desc['attrs']['reference']['onDelete']))
                    unset($desc['attrs']['reference']['onDelete']);

                if (!empty($desc['attrs']['reference'])) {
                    $desc['attrs'] = array_merge($desc['attrs'], $desc['attrs']['reference']);
                    unset($desc['attrs']['reference']);
                }
            }

            $table->addColumn($dbColumnName, $this->parseAttributes($columnName, $desc, false));

            $this->checkIndexes($dbColumnName, $desc, $table);

            if (isset($desc['attrs']['primary']) && $desc['attrs']['primary'])
                $table->setPrimaryKey($dbColumnName);
        }

        if ($canUpdate) {
            $droppedRefs = array();
            foreach ($table->getBackReferences() as $refArray) {
                foreach ($refArray as $ref) {
                    $refTable = new Table($ref['refTable'], $table->getConnection());
                    foreach ($refTable->getReferences() as $col => $array) {
                        if ($refTable->getName() !== $table->getName() && $array['refTable'] === $table->getName()) {
                            $refTable->dropReference($col);
                            $droppedRefs[$col][] = array_merge(array(
                                'table' => $refTable,
                                    ), $array);

                            $table->getConnection()->alterTable($refTable);
                        }
                    }
                }
            }
            $return = $table->getConnection()->alterTable($table);

            foreach ($droppedRefs as $col => $array) {
                foreach ($array as $ref) {
                    $onDelete = (!empty($ref['onDelete'])) ? $ref['onDelete'] : 'RESTRICT';
                    $onUpdate = (!empty($ref['onUpdate'])) ? $ref['onUpdate'] : 'RESTRICT';
                    $ref['table']->addReference($col, $ref['refTable'], $ref['refColumn'], $onDelete, $onUpdate);

                    $table->getConnection()->alterTable($ref['table']);
                }
            }
            if ($return) {
                $table->getConnection()->flush();
                return true;
            }
        }

        return false;
    }
468362
public function setWidth(TcTable $table) {
        if (!$this->width) {
            $widths = [];
            foreach ($table->getColumns() as $key => $column) {
                $widths[$key] = $column['width'];
            }
            unset($widths[$this->columnIndex]);
            $this->width = $this->getRemainingColumnWidth($table, $widths);
        }
        $width = $this->width;
        $table->setColumnDefinition($this->columnIndex, 'width', $width);
    }