Generates the Select clause from this ResultSetMappingBuilder.

Works only for all the entity results. The select parts for scalar
expressions have to be written manually.

@param string[] $tableAliases

@return string
422793
public function generateSelectClause($tableAliases = [])
    {
        $sql = '';

        foreach ($this->columnOwnerMap as $columnName => $dqlAlias) {
            $tableAlias = $tableAliases[$dqlAlias] ?? $dqlAlias;

            if ($sql) {
                $sql .= ', ';
            }

            $sql .= $tableAlias . '.';

            if (isset($this->fieldMappings[$columnName])) {
                $class = $this->em->getClassMetadata($this->declaringClasses[$columnName]);
                $field = $this->fieldMappings[$columnName];
                $sql  .= $class->getProperty($field)->getColumnName();
            } elseif (isset($this->metaMappings[$columnName])) {
                $sql .= $this->metaMappings[$columnName];
            } elseif (isset($this->discriminatorColumns[$dqlAlias])) {
                $sql .= $this->discriminatorColumns[$dqlAlias];
            }

            $sql .= ' AS ' . $columnName;
        }

        return $sql;
    }
788459
public function join($table, $constraint, $tableAlias = null)
    {
        return $this->addJoinSource('', $table, $constraint, $tableAlias);
    }
757957
protected function addLoadClausesToSelect(Select $select, string $tableAlias): string
    {
        $table = $select->getTableFromAlias($tableAlias);

        foreach ($this->getAllColumnsToLoad() as $column) {
            $select->addColumn($column, Expr::column($tableAlias, $table->getColumn($column)));
        }

        return $tableAlias;
    }
918254
public function createResultSetMappingBuilder($alias)
    {
        $rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT);
        $rsm->addRootEntityFromClassMetadata($this->_entityName, $alias);

        return $rsm;
    }
451810
public function sqlSelect()
    {
        $properties = $this->properties();
        if (empty($properties)) {
            return self::DEFAULT_TABLE_ALIAS.'.*';
        }

        $parts = [];
        foreach ($properties as $key) {
            $parts[] = Expression::quoteIdentifier($key, self::DEFAULT_TABLE_ALIAS);
        }

        if (empty($parts)) {
            throw new UnexpectedValueException(
                'Can not get SQL SELECT clause. No valid properties.'
            );
        }

        $clause = implode(', ', $parts);

        return $clause;
    }
1364743
public function translate($alias, array $params = [])
    {
        $result = '';
        $query  = $this->getQueryBuilder()
            ->select([$this->getResultFieldName()])
            ->where([
                $this->getLanguageFieldName() => $this->getLanguage(),
                $this->getAliasFieldName() => $alias
            ])
            ->table($this->getTableName())
            ->generate();
        $res    = $this->getConnection()->query($query,
            $this->getQueryBuilder()->getParams());

        if ($res !== false) {
            $result = $res->fetchColumn($this->getResultFieldName());
        }
        return $result;
    }
956110
public function formatFieldsWithFieldAlias($table_alias = null)
    {
        $fields = $this->getFieldsWithTableAlias($table_alias);

        return join(
            ', ',
            array_map(
                function ($field_alias, $field_definition) {
                    return sprintf(
                        '%s as "%s"',
                        $field_definition,
                        addcslashes($field_alias, '"\\')
                    );
                },
                array_keys($fields),
                $fields
            )
        );
    }
1110006
private function getSelectQuery($table, $fields, $fieldName, $keys)
    {
        /** @var Select $query */
        $query = $this->applyFilters(
            $this->queryBuilder
                ->select($fields)
                ->from($table, $this->alias)
        );

        $query->where(
            $this->equalsExpression($fieldName, $keys)
        );

        return $query;
    }
627906
public function select(array $statements): array
    {
        $hasDistincts = false;

        if (isset($statements['distincts']) === true && \count($statements['distincts']) > 0) {
            $hasDistincts = true;

            if (isset($statements['selects']) === true && \count($statements['selects']) > 0) {
                $statements['selects'] = array_merge($statements['distincts'], $statements['selects']);
            } else {
                $statements['selects'] = $statements['distincts'];
            }

        } else if (isset($statements['selects']) === false) {
            $statements['selects'] = ['*'];
        }

        // From
        $fromEnabled = false;
        $tables = '';

        if (isset($statements['tables']) === true) {
            $tablesFound = [];

            foreach ((array)$statements['tables'] as $table) {
                if ($table instanceof Raw) {
                    $t = $table;
                } else {
                    $prefix = $statements['aliases'][$table] ?? null;

                    if ($prefix !== null) {
                        $t = sprintf('`%s` AS `%s`', $table, strtolower($prefix));
                    } else {
                        $t = sprintf('`%s`', $table);
                    }
                }

                $tablesFound[] = $t;
            }

            $tables = implode(',', $tablesFound);
            $fromEnabled = true;
        }

        // WHERE
        [$whereCriteria, $whereBindings] = $this->buildCriteriaWithType($statements, 'wheres', 'WHERE');

        // HAVING
        [$havingCriteria, $havingBindings] = $this->buildCriteriaWithType($statements, 'havings', 'HAVING');

        $sql = $this->concatenateQuery([
            'SELECT' . ($hasDistincts === true ? ' DISTINCT' : ''),
            $this->arrayStr($statements['selects'], ', '),
            $fromEnabled ? 'FROM' : '',
            $tables,
            $this->buildQueryPart(static::QUERY_PART_JOIN, $statements),
            $whereCriteria,
            $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements),
            $havingCriteria,
            $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements),
            $this->buildQueryPart(static::QUERY_PART_LIMIT, $statements),
            $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements),
        ]);

        $sql = $this->buildUnion($statements, $sql);

        $bindings = array_merge(
            $whereBindings,
            $havingBindings
        );

        return compact('sql', 'bindings');
    }
456368
public function select(SQLStatement $select): string
    {
        $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
        $sql .= $this->handleColumns($select->getColumns());
        $sql .= $this->handleInto($select->getIntoTable(), $select->getIntoDatabase());
        $sql .= ' FROM ';
        $sql .= $this->handleTables($select->getTables());
        $sql .= $this->handleJoins($select->getJoins());
        $sql .= $this->handleWheres($select->getWheres());
        $sql .= $this->handleGroupings($select->getGroupBy());
        $sql .= $this->handleOrderings($select->getOrder());
        $sql .= $this->handleHavings($select->getHaving());
        $sql .= $this->handleOffset($select->getOffset(), $select->getLimit());
        $sql .= $this->handleLimit($select->getLimit(), $select->getOffset());

        return $sql;
    }
1063409
public final function select(...$fileds) {
        if (empty($fileds) || !isset($fileds[0])) {
            if (isset($this->fields) && $this->fields) {
                $fileds = $this->defaultQueryFields;
            } else {
                $fileds = '*';
            }
        }
        $sql      = new Query($fileds);
        $sql->orm = new Orm($this, $this->primaryKeys[0]);
        $sql->setDialect($this->dialect)->from($this->qualifiedName);

        return $sql;
    }
578626
public static function generateQueryString(array $parts)
    {
        $return = "";

        foreach ($parts as $part) {
            if ($part instanceof Table) {
                $return .= "`{$part->getTableName()}`";
                if ($part->getTableAs() !== null) {
                    $return .= " " . $part->getTableAs();
                }

                $return .= ",";
            }
        }

        return ($return !== "" ? substr($return, 0, -1) : "*");
    }
268143
public function setSQLTableAlias($tableName, $alias, $dqlAlias = '')
    {
        $tableName .= $dqlAlias ? '@[' . $dqlAlias . ']' : '';

        $this->tableAliasMap[$tableName] = $alias;

        return $alias;
    }
972573
public function getFieldsWithTableAlias($table_alias = null)
    {
        $vals = [];
        $replace = $table_alias === null ? '' : sprintf("%s.", $table_alias);

        foreach ($this->fields as $name => $definition) {
            $vals[$name] = $this->replaceToken($this->fields[$name], $replace);
        }

        return $vals;
    }
504848
public function select($fields = '*')
    {
        if (is_string($fields) && strpos($fields, '(') !== false) {
            $this->query['select'] = $fields;
        } else {
            if (!is_array($fields)) {
                $fields = $this->splitParts($fields);
            }
            foreach ($fields as $k => $field) {
                if (false === strpos($field, '(')) {
                    if ($alias = $this->matchAlias($field)) {
                        $fields[$k] = $this->db->quoteColumn($alias[0]) . ' AS ' . $this->db->quoteColumn($alias[1]);
                    } else {
                        $fields[$k] = $this->db->quoteColumn($field);
                    }
                }
            }
            $this->query['select'] = implode(', ', $fields);
        }

        return $this;
    }
1247887
public function toString($schemas = [], $aliases = [])
    {
        $fields = $this->dialect()->names($this->_parts['fields']);
        $sql = 'SELECT' .
            $this->_buildFlags($this->_parts['flags']) .
            $this->_buildChunk($fields ?: '*') .
            $this->_buildClause('FROM', $this->dialect()->names($this->_parts['from'])) .
            $this->_buildJoins($schemas, $aliases) .
            $this->_buildClause('WHERE', $this->dialect()->conditions($this->_parts['where'], compact('schemas', 'aliases'))) .
            $this->_buildClause('GROUP BY', $this->_group()) .
            $this->_buildClause('HAVING', $this->dialect()->conditions($this->_parts['having'], compact('schemas', 'aliases'))) .
            $this->_buildOrder($aliases) .
            $this->_buildClause('LIMIT', $this->_parts['limit']);

        if ($this->_parts['lock']) {
            $sql .= $this->_buildFlag($this->_parts['lock'], $this->_parts['lock']) .
                    $this->_buildFlag('NOWAIT', $this->_parts['noWait']);
        }

        return $this->_alias ? "({$sql}) AS " . $this->dialect()->name($this->_alias) : $sql;
    }
759389
protected function getExpressionByJoiningRelations(
        Select $select,
        string $tableAlias,
        array $separateTableRelations,
        callable $expressionLoader
    ) : Expr
    {
        /** @var Select $subSelect */
        list($subSelect, $joinedTableAlias) = $this->getJoinedSubSelectAndTableAlias($select, $tableAlias, $separateTableRelations);

        $subSelect->setColumns(['__single_val' => $expressionLoader($subSelect, $joinedTableAlias)]);

        return Expr::subSelect($subSelect);
    }