generate SQL column definition query
@return bool|string
435684
public function getColumnQuery() {
        // prepare column types
        $type_val = $this->getTypeVal();
        // build query
        $query = $this->db->quotekey($this->name).' '.$type_val.' '.
            $this->getNullable();
        // unify default for booleans
        if (preg_match('/bool/i', $type_val) && $this->default!==null)
            $this->default = (int) $this->default;
        // default value
        if ($this->default !== false) {
            $def_cmds = array(
                'sqlite2?|mysql|pgsql' => 'DEFAULT',
                'mssql|sybase|dblib|odbc|sqlsrv' => 'constraint DF_'.$this->table->name.'_'.$this->name.' DEFAULT',
                'ibm' => 'WITH DEFAULT',
            );
            $def_cmd = $this->findQuery($def_cmds).' '.$this->getDefault();
            $query .= ' '.$def_cmd;
        }
        if (!empty($this->after) && $this->table instanceof TableModifier) {
            // `after` feature only works for mysql
            if (preg_match('/mysql/', $this->db->driver())) {
                $after_cmd = 'AFTER '.$this->db->quotekey($this->after);
                $query .= ' '.$after_cmd;
            }
        }
        return $query;
    }
518022
public function &buildColumnList()
    {

        $str = "";
        $ct = 0;

        // Build Select Column List
        foreach ($this->columns as $k => $col) {
            if ($col->in_select) {
                if ($ct > 0) {
                    $str .= ",";
                }

                $str .= " ";

                if ($col->table_name) {
                    $str .= $col->table_name . ".";
                }

                $str .= $col->column_name;

                if (($col->query_name)) {
                    $str .= " " . $col->query_name;
                }

                $ct++;
            }
        }
        //die;
        return $str;
    }
280742
private function buildQuery()
    {
        $this->validateQuery();

        $statement = "";
        if ($this->select !== null) {
            $statement .= sprintf("%s %s ", self::SELECT, $this->select);
        }
        if ($this->from !== null) {
            $statement .= sprintf("%s %s ", self::FROM, $this->from);
        }
        if ($this->where !== null) {
            $statement .= sprintf("%s %s ", self::WHERE, $this->where);
        }
        if ($this->orderBy !== null) {
            $statement .= sprintf("%s %s ", self::ORDER_BY, $this->orderBy);
        }
        if ($this->limit !== null) {
            $statement .= sprintf("%s %s ", self::LIMIT, $this->limit);
        }
        if ($this->offset !== null) {
            $statement .= sprintf("%s %s ", self::OFFSET, $this->offset);
        }

        return trim($statement);
    }
1083833
final public function generateQueryForUPdate () : string
	{
		$generatedArray = [];
		foreach ($this->sanitizedAttributes() as $key => $value):
			$generatedArray[] = "{$key} = '{$value}'";
		endforeach;
		return joinArray($generatedArray, ", ");
	}
1140412
private function generateSQL(&$sql, $from, $joins, $where, $having, $group, $values) {
        $froms = [];
        foreach ($from as $f) {
            $froms [] = $f [0] . ' AS ' . $f [1];
        }
        $sql [] = implode(',', $froms);
        if ($joins) {
            foreach ($joins as $join) {
                $sql [] = $join [2] . ' ' . $join [0] . ' AS ' . $join [3] . ' ON (' . $join [1] . ')';
            }
        }
        if ($where && count($where) > 0) {
            $sql [] = 'WHERE ' . $where->getWhereCondition($this, $values);
        }
        if ($group) {
            $sql [] = 'GROUP BY ' . implode(' , ', $group);
        }
        if ($having) {
            $sql [] = 'HAVING ' . implode(' AND ', $having);
        }
    }
349096
protected function generateSQLColumnFilter($column, $search_value)
    {
        return self::_generateSQLColumnFilter($column, $search_value, $this->pdoLink, isset($this->sRangeSeparator) ? $this->sRangeSeparator : '~');
    }
105506
public function makeQuery()
    {
        $data = $this->q;

        $params = array();
        $query = "SELECT ";

        if (isset($data['from']['columns'])) {
            foreach ($data['from']['columns'] as $key => $value) {
                $query .= "$value, ";
            }

            $query = substr($query, 0, -2);
        } else {
            $query .= "{$data['from']['table']}.* ";
        }

        // Join columns
        if (isset($data['join'])) {
            foreach ($data['join'] as $join) {
                if (isset($join['columns'])) {
                    foreach ($join['columns'] as $col) {
                        $query .= ", {$join['table']}.{$col}";
                    }
                } else {
                    $query .= ", {$join['table']}.*";
                }

            }
        }

        $query .= " FROM {$data['from']['table']}";

        // Join
        if (isset($data['join'])) {
            foreach ($data['join'] as $join) {
                $query .= " JOIN {$join['table']} ON {$join['conditions']}";

            }
        }

        if (isset($data['where'])) {
            $query .= " WHERE (";

            $iWhere = 0;
            foreach ($data['where'] as $key => $value) {
                if (!is_int($key)) {
                    $query .= "$key = :where$iWhere AND ";
                    $params[":where$iWhere"] = $value;
                    $iWhere++;
                } else {
                    $query .= "$value AND";
                }

            }

            $query = substr($query, 0, -4);

            $iWhereO = 0;
            if (isset($data['orwhere'])) {
                foreach ($data['orwhere'] as $key => $value) {
                    if (!is_int($key)) {
                        $query .= " OR $key = :whereO$iWhereO ";
                        $params[":whereO$iWhereO"] = $value;
                        $iWhereO++;
                    } else {
                        $query .= "OR $value ";
                    }
                }
            }
            $query .= ")";
        }

        if (isset($data['group'])) {
            $query .= " GROUP BY :group";
            $params[':group'] = $data['group'];
        }

        $iOrder = 0;
        if (isset($data['order'])) {
            $query .= " ORDER BY ";
            foreach ($data['order'] as $key => $value) {
                $query .= ":order$iOrder $value";
                $params[":order$iOrder"] = $key;
                $iOrder++;
            }
        }

        if (isset($data['limit'])) {
            $query .= " LIMIT :limit";
            $params[":limit"] = $data['limit']['limit'];
            if (isset($data['limit']['offset'])) {
                $query .= ", :offset";
                $params[":offset"] = $data['limit']['offset'];
            }
        }

        return ['query' => $query, 'params' => $params];
    }
1209496
private function createQuery(): string
    {
        // 已经直接传递了SQL,Prepare与SQL相同
        $this->prepare = $this->sql;

        // 查找其中的表名
        $this->tables = $this->db->getNameFromQuery($this->sql);

        return $this->prepare;
    }
999106
private function buildSelectColumns()
    {
        $columns = array();

        foreach ($this->query['select'] as $column => $as) {
            // Normal column select
            if (is_numeric($column)) {
                $columns[] = $this->columnName($as);
            }
            // Alias
            else {
                $columns[] = $this->columnName($column) . " AS `{$as}`";
            }
        }

        // Join columns and return
        return implode(', ', $columns);
    }
1309646
private function getSQLForInsert()
    {
        return 'INSERT INTO ' . $this->sqlParts['from']['table'] .
        ' (' . implode(', ', array_keys($this->sqlParts['values'])) . ')' .
        ' VALUES(' . implode(', ', $this->sqlParts['values']) . ')';
    }
713231
protected function buildColumns() {
		$select = [];
		$params = [];
		if(!$this->columns)
			return ['*', []];
		else {
			foreach($this->columns as $alias=>$column) {
				if($column instanceof static) {
					$sql = $column->buildSQL();
					$params = array_merge($params, $column->getParameters());
					$select[] = '('.$sql.') AS '.$this->identifierQuotes($alias);
				}
				elseif($column instanceof Raw) {
					$sql = $column->getSQL();
					$params = array_merge($params, $column->getParameters());
					$select[] = $sql.' AS '.$this->identifierQuotes($alias);
				}
				elseif((string)$alias !== (string)$column)
					$select[] = $this->identifierQuotes($column).' AS '.$this->identifierQuotes($alias);
				else
					$select[] = $this->identifierQuotes($column);
			}
		}
		return [implode(', ', $select), $params];
	}
305519
public function getSql()
    {
        $where = (count($this->conditions) === 0)
            ? ''
            : 'WHERE ' . implode(' and ', $this->conditions);
        $sql = "SELECT $this->select FROM $this->table $where $this->order $this->limit $this->offset";
        return $sql;
    }
288558
function query($sql)
    {
        $res = false;

        for ($i = 0; $i < 2; $i++)
        {
            $res = mysql_query($sql, $this->conn);
            if ($res === false)
            {
                if (mysql_errno($this->conn) == 2006 or mysql_errno($this->conn) == 2013 or (mysql_errno($this->conn) == 0 and !$this->ping()))
                {
                    $r = $this->checkConnection();
                    if ($r === true)
                    {
                        continue;
                    }
                }
                \Swoole\Error::info(__CLASS__." SQL Error", $this->errorMessage($sql));
                return false;
            }
            break;
        }

        if (!$res)
        {
            Swoole\Error::info(__CLASS__." SQL Error", $this->errorMessage($sql));
            return false;
        }
        if (is_bool($res))
        {
            return $res;
        }
        return new MySQLRecord($res);
    }
98763
public function getQuery()
    {
        $query = $this->database->getSelectQuery()->from($this->table);

        foreach ($this->join as $join) {
            if (!is_array($join[2])) {
                $join[2] = [$join[2]];
            }

            $where = array_shift($join[2]);
            if (!empty($join[2])) {
                foreach ($join[2] as $i => $value) {
                    $join[2][$i] = $this->database->bind($value);
                }

                $where = vsprintf($where, $join[2]);
            }

            $query->join($join[0], $join[1], $where, $join[3]);
        }

        foreach ($this->filter as $i => $filter) {
            //array('post_id=%s AND post_title IN %s', 123, array('asd'));
            $where = array_shift($filter);
            if (!empty($filter)) {
                foreach ($filter as $i => $value) {
                    $filter[$i] = $this->database->bind($value);
                }

                $where = vsprintf($where, $filter);
            }

            $query->where($where);
        }

        return $query;
    }
1122376
public function get_query()
	{
		// Get the columns
		$columns = $this->select(false);

		// Start building the query
		$select = $columns;
		if ($this->use_subquery())
		{
			$select = array();
			foreach ($columns as $c)
			{
				$select[] = $c[0];
			}
		}
		$query = call_fuel_func_array('DB::select', $select);

		// Set the defined connection on the query
		$query->set_connection($this->connection);

		// Set from table
		$query->from(array($this->_table(), $this->alias));

		// Build the query further
		$tmp = $this->build_query($query, $columns);

		return $tmp['query'];
	}
522896
public static function get_title_sql()
    {

        // Get title_format with fallback to default
        $format = static::config()->get('title_format');
        if (!$format) {
            $format = [
                'columns' => ['Surname', 'FirstName'],
                'sep' => ' ',
            ];
        }

        $columnsWithTablename = array();
        foreach ($format['columns'] as $column) {
            $columnsWithTablename[] = static::getSchema()->sqlColumnForField(__CLASS__, $column);
        }

        $sepSQL = Convert::raw2sql($format['sep'], true);
        $op = DB::get_conn()->concatOperator();
        return "(" . join(" $op $sepSQL $op ", $columnsWithTablename) . ")";
    }
371898
protected function generateSchemaAsSql()
    {
        $prefix = ezcDbSchema::$options->tableNamePrefix;
        foreach ( $this->schema as $tableName => $tableDefinition )
        {
            $this->generateDropTableSql( $prefix . $tableName );
            $this->generateCreateTableSql( $prefix . $tableName, $tableDefinition );
        }
    }