Repair table query

Generates a platform-specific query so that a table can be repaired

@access public
@param string the table name
@return object
502160
public function repair($table = null)
        {
            $table = empty($table) ? $this->_tableName : $table;
            $this->_query("REPAIR TABLE " . $table);

            return $this;
        }
333681
public function table($table, /*# string */ $alias = '')
    {
        $tbl = $this->fixTable($table, $alias);
        $clone = [] === $this->tables ? $this : clone $this;
        $clone->tables = $tbl;
        return $clone;
    }
1091069
public function getTable($name, $refresh = false)
    {
        if (false === $refresh && isset($this->_tableScheams[$name])) {
            return $this->_tableScheams[$name];
        } else {
            if (null !== $this->tablePrefix && false !== strpos($name, '{{')) {
                $realName = preg_replace('/\{\{(.*?)\}\}/', $this->tablePrefix . '$1', $name);
            } else {
                $realName = $name;
            }

            $tableSchema = new TableSchema();
            // 构建表名
            $parts = explode('.', str_replace(['`', '"'], '', $realName));
            if (isset($parts[1])) {
                $tableSchema->schemaName = $parts[0];
                $tableSchema->name = $parts[1];
                $tableSchema->rawName = $this->quoteTableName($tableSchema->schemaName) . '.' . $this->quoteTableName($tableSchema->name);
            } else {
                $tableSchema->name = $parts[0];
                $tableSchema->rawName = $this->quoteTableName($tableSchema->name);
            }
            // 收集表信息
            $sql = 'SHOW FULL COLUMNS FROM ' . $tableSchema->rawName;
            try {
                $columns = $this->createCommand()
                    ->setText($sql)
                    ->queryAll();
            } catch (\Exception $e) {
                return false;
            }
            foreach ($columns as $column) {
                // 创建 table-column-schema
                $c = new ColumnSchema();
                $c->name = $column['Field'];
                $c->rawName = $this->quoteColumnName($column['Field']);
                $c->allowNull = $column['Null'] === 'YES';
                $c->isPrimaryKey = false !== strpos($column['Key'], 'PRI');
                $c->isForeignKey = false;
                $c->init($column['Type'], $column['Default']);
                $c->autoIncrement = false !== strpos(strtolower($column['Extra']), 'auto_increment');
                if (isset($column['Comment'])) {
                    $c->comment = $column['Comment'];
                }

                $tableSchema->columns[$c->name] = $c;
                if ($c->isPrimaryKey) {
                    if (null === $tableSchema->primaryKey) {
                        $tableSchema->primaryKey = $c->name;
                    } else if (is_string($tableSchema->primaryKey)) {
                        $tableSchema->primaryKey = [$tableSchema->primaryKey, $c->name];
                    } else {
                        $tableSchema->primaryKey[] = $c->name;
                    }
                    if ($c->autoIncrement) {
                        $tableSchema->sequenceName = '';
                    }
                }
            }

            return $this->_tableScheams[$name] = $tableSchema;
        }
    }
482064
public function resetSqlPart($name)
    {
        $this->sqlParts[$name] = is_array($this->sqlParts[$name]) ? array() : null;
        $this->state = self::STATE_DIRTY;
        return $this;
    }
661186
static function query($table = null)
    {
        $model = new static();
        return $model->newTable($table = null)->asModel(get_class($model));
    }
575700
public function getTable($name, $caseInsensitive = false)
    {
        if ($this->getSchema() && $this->getPlatform()->supportsSchemas()
            && false === strpos($name, $this->getPlatform()->getSchemaDelimiter())) {
            $name = $this->getSchema() . $this->getPlatform()->getSchemaDelimiter() . $name;
        }

        if (!$this->hasTable($name, $caseInsensitive)) {
            return null;
        }

        if ($caseInsensitive) {
            return $this->tablesByLowercaseName[strtolower($name)];
        }

        return $this->tablesByName[$name];
    }
634170
function exists($table) {
		$mode=$this->pdo->getAttribute(\PDO::ATTR_ERRMODE);
		$this->pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_SILENT);
		$out=$this->pdo->
			query('SELECT 1 FROM '.$this->quotekey($table).' LIMIT 1');
		$this->pdo->setAttribute(\PDO::ATTR_ERRMODE,$mode);
		return is_object($out);
	}
218870
protected function fix_tables(){
    $xp = new DOMXPath($this->_dom);
    
    // Move table caption before the table
    // FIXME find a better way to deal with it...
    $captions = $xp->query("//table/caption");
    foreach($captions as $caption) {
      $table = $caption->parentNode;
      $table->parentNode->insertBefore($caption, $table);
    }
    
    $rows = $xp->query("//table/tr");
    foreach($rows as $row) {
      $tbody = $this->_dom->createElement("tbody");
      $tbody = $row->parentNode->insertBefore($tbody, $row);
      $tbody->appendChild($row);
    }
  }
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;
    }
129991
public static function table($name)
    {
        Helpers\Validate::table($name)->exists();

        $self       = new self();
        $self->name = $name;

        $self->setFields();
        $self->setPending();

        return $self;
    }
1364804
public function table($table = null)
    {
        if ($table !== null) {
            $this->table = $table;
        }

        return $this->table;
    }
983203
public function table($table, $alias = null)
    {
        $database = null;

        // Check if the table is an object, this means
        // we have an subselect inside the table
        if (is_object($table) && ($table instanceof \Closure)) 
        {
            // we have to check if an alias isset 
            // otherwise throw an exception to prevent the 
            // "Every derived table must have its own alias" error
            if (is_null($alias))
            {
                throw new Exception('You must define an alias when working with subselects.');
            }

            $table = array($alias => $table);
        } 

        // Check if the $table is an array and the value is an closure
        // that we can pass a new query object as subquery 
        if (is_array($table) && is_object(reset($table)) && (reset($table) instanceof \Closure)) 
        {
            $alias = key($table);
            $table = reset($table);

            // create new query object
            $subquery = new Select;

            // run the closure callback on the sub query
            call_user_func_array($table, array(&$subquery));

            // set the table 
            // IMPORTANT: Only if we have a closure as table
            // we set the alias as key. This might cause some confusion
            // but only this way we can keep the normal ['table' => 'alias'] syntax
            $table = array($alias => $subquery);
        } 

        // other wise normally try to split the table and database name
        elseif (is_string($table) && strpos($table, '.') !== false)
        {
            $selection = explode('.', $table);

            if (count($selection) !== 2)
            {
                throw new Exception( 'Invalid argument given. You can only define one seperator.' );
            }

            list($database, $table) = $selection;
        }

        // the table might include an alias we need to parse that one out 
        if (is_string($table) && strpos($table, ' as ') !== false)
        {
            $tableParts = explode(' as ', $table);
            $table = array($tableParts[0] => $tableParts[1]);
        }

        // assing the result
        $this->database = $database;
        $this->table = $table;

        // return self
        return $this;
    }
668726
function replace($table, $data, $stmt_key = null)
    {
        return $this->executeBySyntax(self::REPLACE, $table, $data, null, array(), $stmt_key);
    }
744310
public function getCompiledSelect(string $table='', bool $reset=TRUE): string
	{
		// Set the table
		if ( ! empty($table))
		{
			$this->from($table);
		}

		return $this->_getCompile('select', $table, $reset);
	}
1100593
public static function table($name)
    {
        Validate::table($name)->exists();

        $self                  = new self();
        $self->tables['local'] = $name;

        return $self;
    }
710121
public function unlockTable()
    {
        $query = 'UNLOCK TABLES';

        // Create commandchain context.
        $context = $this->getCommandContext();
        $context->table = $base;
        $context->query = $query;

        if ($this->getCommandChain()->run('before.unlocktable', $context) !== false) {
            $context->result = $this->execute($context->query, AnDatabase::RESULT_USE);
            $this->getCommandChain()->run('after.unlocktable', $context);
        }

        return $context->result;
    }
670760
public static function table($table)
    {
        static::verifyConnection();

        $table = static::$adapter->getTablePrefix().$table;

        return new QueryBuilder(
            $table,
            static::$adapter->getConnection()
        );
    }