only a single data row
@param $table
@param $cols
@param array $options
@param int $start
@return array
4126
public function getRow($table, $cols, $options = array(), $start = 0)
    {
        // Set Limit
        $options['L'] = $start . ",1";

        // Get Result
        $result = $this->get($table, $cols, $options);
        if (count($result['data']) >= 1) {
            return $result['data'][0];
        } else {
            return array();
        }
    }
854373
public function index($columns, $name = null, $flags = [], $options = [])
    {
        $columns = is_array($columns) ? $columns : [$columns];

        return $this->table->addIndex($columns, $name, $flags, $options);
    }
28215
private function sql_handle_col( $col, $table ) {
		global $wpdb;

		$table_sql = $this->esc_sql_ident( $table );
		$col_sql   = $this->esc_sql_ident( $col );

		$count = $wpdb->query( $wpdb->prepare( "UPDATE $table_sql SET $col_sql = REPLACE($col_sql, %s, %s);", $this->old, $this->new ) );

		return $count;
	}
34918
private function select($table, $cols, $options = array(), $distinct = false, $total_rows = false)
    {
        // empty cols
        if (empty($cols))
            Throw new \ErrorException('SQL Error: Can\'t select nothing.');
        if (is_array($table) && count($table) <= 0)
            Throw new \ErrorException('SQL Error: Can\'t select from nothing.');


        // Table list
        if (is_array($table)) {
            // Computes to FROM `table1` ONE, `table2` TWO ...
            $table_list = array();
            foreach ($table as $as => $name) {
                $table_list[] = '`' . $this->pref . $name . '` ' . $as;
            }
            $table_list = implode(', ', $table_list);
        } else {
            $table_list = '`' . $this->pref . $table . '`';
        }

        // prepare data
        if (is_array($cols)) {
            $cols_list = array();
            foreach ($cols as $col) {
                if (is_array($col)) {
                    $cols_list[] = $this->select_expr($col);
                } else {
                    $cols_list[] = '`' . $col . '`';
                }
            }

            $cols_list = implode(', ', $cols_list);

            // error
        } elseif ($cols == '*') {
            $cols_list = $cols;
        } else {
            Throw new \ErrorException('SQL Error: Cannot select because of bad data.');
        }

        // DISTINCT or not
        $select = ($distinct) ? 'SELECT DISTINCT ' : 'SELECT ';
        // Total Rows?
        $select .= ($total_rows) ? ' SQL_CALC_FOUND_ROWS' : '';

        // build query string...
        $qrystr = $select . $cols_list . ' FROM ' . $table_list . $this->opt($options);

        try {
            return $this->doQuery($qrystr); // ... and execute
        } catch (\Exception $e) {
            print_d($e->getMessage());
            return null;
        }
    }
384743
public function getColumns($table): ?array
	{
		return $this->driverQuery($this->getSql()->columnList($this->prefixTable($table)), FALSE);
	}
621495
public function backup($table, $start)
    {
        $db = self::connect();
        // 备份表结构
        if (0 == $start) {
            $result = $db->query("SHOW CREATE TABLE `{$table}`");
            $sql = "\n";
            $sql .= "-- -----------------------------\n";
            $sql .= "-- Table structure for `{$table}`\n";
            $sql .= "-- -----------------------------\n";
            $sql .= "DROP TABLE IF EXISTS `{$table}`;\n";
            $sql .= trim($result[0]['Create Table']) . ";\n\n";
            if (false === $this->write($sql)) {
                return false;
            }
        }
        //数据总数
        $result = $db->query("SELECT COUNT(*) AS count FROM `{$table}`");
        $count = $result['0']['count'];
        //备份表数据
        if ($count) {
            //写入数据注释
            if (0 == $start) {
                $sql = "-- -----------------------------\n";
                $sql .= "-- Records of `{$table}`\n";
                $sql .= "-- -----------------------------\n";
                $this->write($sql);
            }
            //备份数据记录
            $result = $db->query("SELECT * FROM `{$table}` LIMIT {$start}, 1000");
            foreach ($result as $row) {
                $row = array_map('addslashes', $row);
                $sql = "INSERT INTO `{$table}` VALUES ('" . str_replace(array("\r", "\n"), array('\\r', '\\n'), implode("', '", $row)) . "');\n";
                if (false === $this->write($sql)) {
                    return false;
                }
            }
            //还有更多数据
            if ($count > $start + 1000) {
                //return array($start + 1000, $count);
                return $this->backup($table, $start + 1000);
            }
        }
        //备份下一表
        return 0;
    }
1367788
public function create($columns, $options='charset=utf8 engine=innodb')
    {
        $columnSql = array();
        $platform = $this->_connection->platform();

        foreach($columns as $name=>$type)
            $columnSql []= $type->columnSql($name, $platform);

        $sql = sprintf('CREATE TABLE %s (%s) %s',
            $this->_name->quoted(),
            implode(', ', $columnSql),
            $options
        );

        $this->_connection->execute($sql);
    }
463205
public static function orderColumns($table, $columns)
    {
        // If no columns given, return table as-is
        if (!$columns) {
            return $table;
        }

        // Order
        $result = [];
        foreach ($columns as $column) {
            if (array_key_exists($column, $table)) {
                $result[$column] = $table[$column];
            }
        }

        return $result;
    }
981967
public function delete($table, $options = array())
    {
        $query_string = 'DELETE FROM `' . $this->pref . $table . '`' . $this->opt($options);

        try {
            $stmt = $this->doQuery($query_string);
            return $stmt->rowCount();
        } catch (\Exception $e) {
            print_r($e->getMessage());
            return false;
        }
    }
730606
private function get_columns( $table ) {
		global $wpdb;

		$table_sql    = $this->esc_sql_ident( $table );
		$primary_keys = $text_columns = $all_columns = array();

		foreach ( $wpdb->get_results( "DESCRIBE $table_sql" ) as $col ) {
			if ( 'PRI' === $col->Key ) {
				$primary_keys[] = $col->Field;
			}

			if ( $this->is_text_col( $col->Type ) ) {
				$text_columns[] = $col->Field;
			}

			$all_columns[] = $col->Field;
		}

		return array( $primary_keys, $text_columns, $all_columns );
	}
44681
public function getAlterTableInfo($table, $options)
    {
        $table = $this->buildRealTableName($table);
        return $this->getSchema()->getAlterTableInfo($table, $options);
    }
586071
public function getAlterTableSql($table, array $options)
    {
        $table = $this->buildRealTableName($table);
        return $this->getSchema()->getAlterTableSql($table, $options);
    }
794740
public function update($table, $data, $options = array())
    {
        // empty data
        if (empty($data))
            Throw new \ErrorException("SQL Error: Can't update empty data.");

        // prepare data
        $list = array();
        foreach ($data as $column => $value) {
            $list[] = '`' . $column . "` = '" . $this->escape($value) . "'";
        }

        // build query string...
        $query_string = 'UPDATE `' . $this->pref . $table . '` SET ' . implode(',', $list) . $this->opt($options);

        try {
            return $this->doQuery($query_string); // ... and execute
        } catch (\Exception $e) {
            print_r($e->getMessage());
            return null;
        }
    }
934220
protected function findColumns($table)
	{
		$columnsTable="INFORMATION_SCHEMA.COLUMNS";
		$where=array();
		$where[]="t1.TABLE_NAME='".$table->name."'";
		if (isset($table->catalogName))
		{
			$where[]="t1.TABLE_CATALOG='".$table->catalogName."'";
			$columnsTable = $table->catalogName.'.'.$columnsTable;
		}
		if (isset($table->schemaName))
			$where[]="t1.TABLE_SCHEMA='".$table->schemaName."'";

		$sql="SELECT t1.*, columnproperty(object_id(t1.table_schema+'.'+t1.table_name), t1.column_name, 'IsIdentity') AS IsIdentity, ".
			 "CONVERT(VARCHAR, t2.value) AS Comment FROM ".$this->quoteTableName($columnsTable)." AS t1 ".
			 "LEFT OUTER JOIN sys.extended_properties AS t2 ON t1.ORDINAL_POSITION = t2.minor_id AND ".
			 "object_name(t2.major_id) = t1.TABLE_NAME AND t2.class=1 AND t2.class_desc='OBJECT_OR_COLUMN' AND t2.name='MS_Description' ".
			 "WHERE ".join(' AND ',$where);
		try
		{
			$columns=$this->getDbConnection()->createCommand($sql)->queryAll();
			if(empty($columns))
				return false;
		}
		catch(Exception $e)
		{
			return false;
		}

		foreach($columns as $column)
		{
			$c=$this->createColumn($column);
			if (is_array($table->primaryKey))
				$c->isPrimaryKey=in_array($c->name, $table->primaryKey);
			else
				$c->isPrimaryKey=strcasecmp($c->name,$table->primaryKey)===0;

			$c->isForeignKey=isset($table->foreignKeys[$c->name]);
			$table->columns[$c->name]=$c;
			if ($c->autoIncrement && $table->sequenceName===null)
				$table->sequenceName=$table->name;
		}
		return true;
	}
469963
public function get($table = '', $start = 0, $limit = 0, array $order = array(), array $where = array())
    {
        $parameters = array(
            'start' => $start,
            'limit' => $limit,
            'order' => $order,
            'where' => $where,
        );

        $parameters = array_filter($parameters);

        return $this->makeRequest($this->endpoint.'/'.$table, $parameters);
    }
21636
public static function build(Table $table, $columnName, $type = null, $options = [])
    {
        $column = new Column();
        $column->setName($columnName);
        $column->setType($type);
        $column->setOptions($options); // map options to column methods

        return new static($table, $column);
    }
923344
public function hasColumns($table, array $columns)
    {
        $tableColumns = array_map('strtolower', array_keys($this->getColumnListing($table)));

        foreach ($columns as $column) {
            if (!in_array(strtolower($column), $tableColumns)) {
                return false;
            }
        }

        return true;
    }