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 array $tableAliases

@return string
6724
public function generateSelectClause($tableAliases = array())
    {
        $sql = "";

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

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

            $sql .= $tableAlias . ".";

            if (isset($this->fieldMappings[$columnName])) {
                $class = $this->em->getClassMetadata($this->declaringClasses[$columnName]);
                $sql  .= $class->fieldMappings[$this->fieldMappings[$columnName]]['columnName'];
            } else if (isset($this->metaMappings[$columnName])) {
                $sql .= $this->metaMappings[$columnName];
            } else if (isset($this->discriminatorColumn[$columnName])) {
                $sql .= $this->discriminatorColumn[$columnName];
            }

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

        return $sql;
    }
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;
    }
1156438
public function fields(array $fields, string $alias = null): Select
    {
        $alias = ($alias === null) ? '' : "{$alias}.";

        foreach ($fields as $field => $as) {
            if (is_numeric($field)) {
                $this->field($alias . $as);
            } else {
                $this->field($alias . $field, $as);
            }
        }

        return $this;
    }
267975
public function getAlias(): ?string
    {
        return isset($this->statements['aliases']) === true ? array_values($this->statements['aliases'])[0] : null;
    }
1068768
private function _generateDiscriminatorColumnConditionSQL(array $dqlAliases)
    {
        $sqlParts = array();

        foreach ($dqlAliases as $dqlAlias) {
            $class = $this->queryComponents[$dqlAlias]['metadata'];

            if ( ! $class->isInheritanceTypeSingleTable()) continue;

            $conn   = $this->em->getConnection();
            $values = array();

            if ($class->discriminatorValue !== null) { // discriminators can be 0
                $values[] = $conn->quote($class->discriminatorValue);
            }

            foreach ($class->subClasses as $subclassName) {
                $values[] = $conn->quote($this->em->getClassMetadata($subclassName)->discriminatorValue);
            }

            $sqlParts[] = (($this->useSqlTableAliases) ? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.' : '')
                . $class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')';
        }

        $sql = implode(' AND ', $sqlParts);

        return (count($sqlParts) > 1) ? '(' . $sql . ')' : $sql;
    }
861734
public function select($tableName, $fields = ['*'])
    {
        $sql = new Select($tableName, $fields);
        $sql->setAdapter($this->_adapter);
        return $sql;
    }
661549
public static function resultSet(string $tableAlias = null): ResultSet
    {
        $rs = new ResultSet(static::getTableName(), $tableAlias);
        $rs->setModelClass(get_called_class())->setAdapter(static::getAdapterConnection());
        return $rs;
    }
674145
public function formatter(ResultSetInterface $resultSet, array $fields, RepositoryInterface $table, array $user) : array
    {
        $result = [];

        if ($resultSet->isEmpty()) {
            return $result;
        }

        $cakeView = new View();
        $registryAlias = $table->getRegistryAlias();
        $alias = $table->getAlias();

        foreach ($resultSet as $key => $entity) {
            foreach ($fields as $field) {
                list($tableName, $fieldName) = explode('.', $field);
                // current table field
                if ($alias === $tableName) {
                    $result[$key][$field] = $entity->get($fieldName);
                    continue;
                }

                if (!$entity->get('_matchingData')) {
                    continue;
                }

                if (!isset($entity->_matchingData[$tableName])) {
                    continue;
                }
                // associated table field
                $result[$key][$field] = $entity->_matchingData[$tableName]->get($fieldName);
            }

            $result[$key][static::MENU_PROPERTY_NAME] = $cakeView->element('Search.Menu/search-view-actions', [
                'entity' => $entity,
                'model' => $registryAlias,
                'user' => $user
            ]);
        }

        return $result;
    }
416592
public static function select(string $table = null, string $tableAlias = null): Query\Select
    {
        return static::getAdapter()->select($table, $tableAlias);
    }
1334029
public function selectFieldsSingletoneField($field, $tableAlias)
    {
        //
        if (preg_match('/^[a-z_][a-z0-9_]*$/i', $field)) {
            return $tableAlias ? $tableAlias.'.'.$field : $field;
        } else {
            return $field;
        }
    }
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);
    }
539756
public function getWhereConditionExpr(Select $select, string $tableAlias, string $operator, $value) : Expr
    {
        $operand = $this->getExpressionInSelect($select, $tableAlias);

        if ($value === null) {
            if ($operator === ConditionOperator::EQUALS) {
                return Expr::isNull($operand);
            } elseif ($operator === ConditionOperator::NOT_EQUALS) {
                return Expr::isNotNull($operand);
            } else {
                throw InvalidArgumentException::format(
                    'Cannot use operator \'%s\' with NULL value, only (%s) are supported',
                    $operator, Debug::formatValues([ConditionOperator::EQUALS, ConditionOperator::NOT_EQUALS])
                );
            }
        } elseif ($operator === ConditionOperator::IN || $operator == ConditionOperator::NOT_IN) {
            return new BinOp(
                $operand,
                $this->mapConditionOperator($operator),
                Expr::tupleParams(null, $value)
            );
        } else {
            return new BinOp(
                $operand,
                $this->mapConditionOperator($operator),
                Expr::param(null, $value)
            );
        }
    }
262668
protected function getSelectedForAllAliases(array $aliases)
    {
        if (empty($aliases)) {
            $selected = $this->mergeOrderByAttributes($this->getSelectedQueryAttributes($this->operation->getAttributes()));
        } else {
            // If there are aliases, then we need to loop through each one to determine was was actually selected for each.
            $selected = [];
            foreach ($aliases as $alias => $schema) {
                $selected = array_replace(
                    $selected,
                    $this->mergeOrderByAttributes($this->getSelectedQueryAttributes($this->operation->getAttributes(), $schema), $alias)
                );
            }
        }

        return $selected;
    }
1193696
public static function table(string $tableName, string $alias = null): QueryBuilder
    {
        $query = new QueryBuilder();
        $query = $query->table($tableName, $alias);

        return $query;
    }
691873
public function getColumns($tableName)
    {
        if (!isset($this->cache[$tableName])) {
            $columns = $this->entityManager->getConnection()->getSchemaManager()->listTableColumns($tableName);
            if ('leads' === $tableName) {
                if (!$this->extendedFieldAliases) {
                    // Hacked this query into here to avoid a recursive dependency in 2.15.0
                    $fq = $this->entityManager->getConnection()->createQueryBuilder();
                    $fq->select('f.alias')
                        ->from(MAUTIC_TABLE_PREFIX.'lead_fields', 'f')
                        ->where(
                            $fq->expr()->orX(
                                $fq->expr()->eq('f.object', $fq->expr()->literal('extendedField')),
                                $fq->expr()->eq('f.object', $fq->expr()->literal('extendedFieldSecure'))
                            )
                        );
                    foreach ($fq->execute()->fetchAll() as $result) {
                        $this->extendedFieldAliases[$result['alias']] = 'extendedField - This is never used as an actual column object';
                    }
                }
                if ($this->extendedFieldAliases) {
                    $columns = array_merge($columns, $this->extendedFieldAliases);
                }
            }
            $this->cache[$tableName] = $columns ?: [];
        }

        return $this->cache[$tableName];
    }
1138300
protected function getJoinedSubSelectAndTableAlias(Select $select, string $tableAlias, array $separateTableRelations) : array
    {
        InvalidArgumentException::verifyAllInstanceOf(
            __METHOD__, 'separateTableRelations', $separateTableRelations, ISeparateTableRelation::class
        );

        /** @var ISeparateTableRelation $firstRelation */
        $firstRelation = array_shift($separateTableRelations);
        $subSelect     = $firstRelation->getRelationSubSelect($select, $tableAlias);

        $tableAlias = $subSelect->getTableAlias();

        foreach ($separateTableRelations as $relation) {
            if ($relation instanceof IToOneRelation) {
                $joinType = Join::LEFT;
            } else {
                $joinType = Join::INNER;
            }

            $tableAlias = $relation->joinSelectToRelatedTable(
                $tableAlias,
                $joinType,
                $subSelect
            );
        }

        return [$subSelect, $tableAlias];
    }
572406
public function table($table, ...$tables)
    {
        array_unshift($tables, $table);

        foreach ($tables as $table) {
            list($tableAlias, $tableName) = $this->dialect()->parseTable($table);

            if (!is_scalar($tableName)) {
                throw new SqlException('Derived tables are not supported in UPDATE statement.');
            }

            $tableKey = $tableAlias ?: $tableName;

            $tableName = $this->dialect()->quoteTable($tableName);

            if ($tableAlias) {
                $tableAlias = $this->dialect()->quoteName($tableAlias);
            }

            $this->tables[$tableKey] = [
                'tableKey' => $tableKey,
                'table'    => $tableName,
                'alias'    => $tableAlias,
            ];
        }

        return $this;
    }