Get a SELECT Query

@param  Node\SelectStatement $select
@return string
18317
protected function visitSirelNodeSelectStatement(Node\SelectStatement $select)
    {
        return join(" ", array_filter(array(
            "SELECT",

            ($select->distinct ? "DISTINCT" : null),

            ($select->projections
                ? join(", ", $this->visitEach($select->projections))
                : '*'),

            // FROM
            $this->visit($select->source),

            // WHERE
            ($select->restrictions 
                ? "WHERE " . join(" AND ", $this->visitEach($select->restrictions))
                : null
            ),

            // ORDER BY
            ($select->orders
                ? "ORDER BY " . join(", ", $this->visitEach($select->orders))
                : null),

            // GROUP BY
            ($select->groups
                ? "GROUP BY " . join(', ', $this->visitEach($select->groups))
                : null),

            // LIMIT
            ($select->limit ? $this->visit($select->limit) : null),

            // OFFSET 
            ($select->offset ? $this->visit($select->offset) : null)
        ))) . ';';
    }
1311199
public function subselect($parentQuery, $select = '*')
    {
        //Argument 2 must be a string
        Argument::i()->test(2, 'string');
        
        return Subselect::i($parentQuery, $select);
    }
707709
public function selectBridge(Select $select)
    {
        // prepare and execute
        $statement = $this->sql->prepareStatementForSqlObject($select);
        $result = $statement->execute();

        // build result set
        $resultSet = clone $this->resultSetPrototype;
        $resultSet->initialize($result);

        return $resultSet;
    }
934988
protected function getCountQuery(): Select
    {
        if ($this->countQuery instanceof Select) {
            return $this->countQuery;
        }

        if ($this->searchTerm !== null && $this->searchFields === null) {
            $fields = $this->getFields();
            $searchFields = [];
            foreach ($fields as $field) {
                $searchFields[] = $field['name'];
            }
        } else {
            $searchFields = null;
        }

        $query = clone $this;
        $query->resetFields();
        $query->resetLimit();
        $query->resetOrderBy();
        $query->field('COUNT(*)', 'total');

        if ($this->resetGroupBy) {
            $query->resetGroupBy();
        }

        if ($searchFields !== null) {
            $query->setSearchFields($searchFields);
        }

        return $query;
    }
1132457
public function addSelect($select)
    {
        if (null === $select) {
            return $this;
        }
        if (is_array($select)) {
            $t = [];
            foreach ($select as $field => $alias) {
                if (is_int($field)) {
                    $alias = $this->quoteColumnName($alias);
                    array_push($t, "{$alias}");
                } else {
                    $field = $this->quoteColumnName($field);
                    $alias = $this->quoteColumnName($alias);
                    array_push($t, "{$field} AS {$alias}");
                }
            }
            $select = implode(',', $t);
        }
        if (isset($this->query['select']) && !empty($this->query['select'])) {
            $select = "{$this->query['select']},{$select}";
        }
        $this->query['select'] = $select;
        return $this;
    }
1013167
private function getSelectOptions($options, $selected)
    {
        $select = '';

        foreach ($options as $key => $value) {
            $isSelected = ($selected == $key) ? 'selected="selected"' : '';
            $select .= "<option $isSelected value='".$key."'>".$value.'</option>'.PHP_EOL;
        }

        return $select;
    }
338856
protected function _where(Kwf_Db_Table_Select $select, $where)
    {
        $where = (array) $where;

        foreach ($where as $key => $val) {
            // is $key an int?
            if (is_int($key)) {
                // $val is the full condition
                $select->where($val);
            } else {
                // $key is the condition with placeholder,
                // and $val is quoted into the condition
                $select->where($key, $val);
            }
        }

        return $select;
    }
985904
public function select($select=null)
    {
        $select = LambdaUtils::toSelectCallable($select);

        $result = array();
        foreach($this as $key => $record)
        {
            $result[] = call_user_func($select, $record, $key);
        }
        return new ArrayList($result);
    }
99207
public static function getSqlAccessSite($select)
    {
        $access    = Common::prefixTable('access');
        $siteTable = Common::prefixTable('site');

        return "SELECT " . $select . " FROM " . $access . " as t1
				JOIN " . $siteTable . " as t2 USING (idsite) WHERE login = ?";
    }
1219488
private function prepareSelect(array $select)
    {
        if ($select['sql'] instanceof SelectQuery) {
            $columnsCount = count($this->columns);

            $selectColumnsCount = count($select['sql']->getColumns());

            if ($selectColumnsCount and $selectColumnsCount !== $columnsCount) {
                throw new SqlException('INSERT select columns count does not match.'
                                        . ' Expected ' . $columnsCount . ', got ' . $selectColumnsCount);
            }
            [$sql, $params] = $select['sql']->toSql();

            $select['sql'] = $sql;

            $select['params'] = $params;
        }

        return $select;
    }
982260
public function getCustom($id, array $select = array())
    {
        $supported = $this->isSupported('get');

        return (true === $supported) ? $this->makeRequest("{$this->endpoint}/$id", array('select' => $select)) : $supported;
    }
616108
public function selectOption($select, $option)
    {
        $select = $this->fixStepArgument($select);
        $option = $this->fixStepArgument($option);
        $this->getSession()->getPage()->selectFieldOption($select, $option);
    }
667280
public function getSelectQuery()
    {
        $sql = 'SELECT ' . $this->getSelect();
        $sql .= "\nFROM " . $this->getFrom();
        if ($this->where) {
            $sql .= "\nWHERE " . $this->getWhere();
        }
        if ($this->groupBy) {
            $sql .= "\nGROUP BY " . $this->getGroupBy();
        }
        if ($this->having) {
            $sql .= "\nHAVING " . $this->getHaving();
        }
        if ($this->orderBy) {
            $sql .= "\nORDER BY " . $this->getOrderBy();
        }
        if ($this->limit) {
            $sql .= "\nLIMIT " . $this->getLimit();
        }

        return $sql;
    }
16530
protected function loadCount(Select $select) : int
    {
        $limit  = $select->getLimit();
        $offset = $select->getOffset();

        $select->offset(0)->limit(null);

        $rows = $this->connection->load(
            $select->setColumns(['count' => Expr::count()])
        )->asArray();

        if (empty($rows)) {
            return 0;
        }

        $count = (int)$rows[0]['count'] - $offset;

        return $limit !== null ? min($limit, $count) : $count;
    }
418702
public function select($table = '', $option = array())
    {

        $sql = 'SELECT * FROM '.$table.' WHERE ';
        foreach ($option as $k => $v) {
            $sql .= $k.'=:'.$k .' AND ';
        }
        $sql = rtrim($sql, ' AND ');

        foreach ($option as $k => $v) {
            $this->bindParam($k, $v);
        }

        return $this->query($sql);
    }
919901
protected function _where(Zend_Db_Table_Select $select, $where)
    {
        $where = (array) $where;

        foreach ($where as $key => $val) {
            // is $key an int?
            if (is_int($key)) {
                // $val is the full condition
                $select->where($val);
            } else {
                // $key is the condition with placeholder,
                // and $val is quoted into the condition
                $select->where($key, $val);
            }
        }

        return $select;
    }
1150340
public function getSelect($clear = false, $cols = '*')
	{
		if( !$this->_select )
		{
			$this->_select = new Lib_Db_Mongo_Select();
		}
		return $this->_select;
	}