Returns a comma-separated list of compiled columns.

@param  array  $columns    Array of columns
@param  bool   $allowAlias Allow aliases?
@return string
500996
public function columns(array $columns, bool $allowAlias = false): string
	{
		$pieces = [];

		foreach($columns as $column)
		{
			$pieces[] = $this->column($column, $allowAlias);
		}

		return implode(', ', $pieces);
	}
1346448
public function select($columns = '*'): SelectQuery
    {
        return $this->database->select(func_num_args() ? func_get_args() : '*')->from($this->name);
    }
1126451
protected function getColumnHeaders($columns)
    {
        $headers = [];

        foreach ($columns as $column => $label) {
            $headers[] = Lang::get($label);
        }

        return $headers;
    }
232668
protected function _normalizeTableColumns($columns)
    {
        $_defaults = [
            'get' => false,
            'before' => '',
            'after' => '',
        ];
        $result = [];

        foreach ($columns as $name => $options) {
            if (is_array($options)) {
                $_defaults['get'] = $name;
                $result[$name] = array_merge($_defaults, $options);
            } else {
                $_defaults['get'] = $options;
                $result[$options] = $_defaults;
            }
        }
        return $result;
    }
174110
public function formatTableIndex($index, array $columns) {
        return sprintf($this->getClause(self::INDEX), $this->quote($index), $this->quoteList($columns));
    }
1334878
public function toQuery( Query $query, array $columns = [], $alias = '' ) {

		foreach( $this->criteria as $column => $criteria ) {

			if( !$column = $this->getColumnName($columns, $column, $alias) )
				continue;

			foreach( $criteria as $operator => $value ) {
				$query->where($column, $operator, $value);
			}

		}

		foreach( $this->getOrder() as $column => $ascending ) {
			$column = $this->getColumnName($columns, $column, $alias);
			if( !$column )
				continue;
			$query->orderBy($column, $ascending);
		}

		if( $this->offset )
			$query->offset($this->offset);

		if( $this->limit )
			$query->limit($this->limit);

		return $query;

	}
205246
protected function getSelectColumns( $columns = null )
    {
        if ( null === $columns )
        {
            $proxyData = true;
        }
        elseif ( ( $index = array_search( 'proxyData', $columns ) ) )
        {
            $proxyData = true;
            unset( $columns[$index] );
        }
        else
        {
            $proxyData = false;
        }

        if ( null === $columns )
        {
            $tags = true;
        }
        elseif ( ( $index = array_search( 'tags', $columns ) ) )
        {
            $tags = true;
            unset( $columns[$index] );
        }
        else
        {
            $tags = false;
        }

        if ( null === $columns )
        {
            $tagIds = true;
        }
        elseif ( ( $index = array_search( 'tagIds', $columns ) ) )
        {
            $tagIds = true;
            unset( $columns[$index] );
        }
        else
        {
            $tagIds = false;
        }

        if ( null === $columns )
        {
            $localeTags = true;
        }
        elseif ( ( $index = array_search( 'localeTags', $columns ) ) )
        {
            $localeTags = true;
            unset( $columns[$index] );
        }
        else
        {
            $localeTags = false;
        }

        $columns  = parent::getSelectColumns( $columns );
        $platform = $this->getDbAdapter()
                         ->getPlatform();

        if ( $proxyData )
        {
            $columns['proxyData'] = new Sql\Expression( '(' .
                $this->sql( $this->getTableInSchema(
                        static::$propertyTableName
                     ) )
                     ->select()
                     ->columns( array(
                         new Sql\Expression( 'TEXT( ARRAY_TO_JSON(
                             ARRAY_AGG(
                                 ?
                                 ORDER BY CASE ?
                                    WHEN ? THEN 1
                                    WHEN ? THEN 2
                                    WHEN ? THEN 3
                                    WHEN ? THEN 4
                                    ELSE 5
                                 END DESC
                             )
                         ) )', array(
                             static::$propertyTableName,
                             'locale',
                             $this->getLocale(),
                             $this->getPrimaryLanguage(),
                             $this->getDefaultLocale(),
                             'en',
                         ), array(
                             Sql\Expression::TYPE_IDENTIFIER,
                             Sql\Expression::TYPE_IDENTIFIER,
                             Sql\Expression::TYPE_VALUE,
                             Sql\Expression::TYPE_VALUE,
                             Sql\Expression::TYPE_VALUE,
                             Sql\Expression::TYPE_VALUE,
                         ) ),
                     ) )
                     ->where( array(
                         new Sql\Predicate\Operator(
                             static::$propertyTableName . '.paragraphId',
                             Sql\Predicate\Operator::OPERATOR_EQUAL_TO,
                             static::$tableName . '.id',
                             Sql\Predicate\Operator::TYPE_IDENTIFIER,
                             Sql\Predicate\Operator::TYPE_IDENTIFIER
                         ),
                     ) )
                     ->getSqlString( $platform ) .
            ')' );
        }
        else
        {
            $original = array_keys( static::getColumns() ) + array(
                'tags', 'tagIds', 'localeTags',
            );

            foreach ( $columns as $key => $column )
            {
                if ( is_numeric( $key ) && ! in_array( $column, $original ) )
                {
                    unset( $columns[$key] );

                    if ( ! isset( $columns[$column] ) )
                    {
                        $columns[$column] = new Sql\Expression( '(' .
                            $this->sql( $this->getTableInSchema(
                                     static::$propertyTableName
                                 ) )
                                 ->select()
                                 ->columns( array( 'value' ) )
                                 ->where( array(
                                     new Sql\Predicate\Operator(
                                         static::$propertyTableName . '.paragraphId',
                                         Sql\Predicate\Operator::OPERATOR_EQUAL_TO,
                                         static::$tableName . '.id',
                                         Sql\Predicate\Operator::TYPE_IDENTIFIER,
                                         Sql\Predicate\Operator::TYPE_IDENTIFIER
                                     ),
                                     'name' => $column,
                                 ) )
                                 ->order( array(
                                     new Sql\Expression(
                                         'CASE ? ' .
                                             'WHEN ? THEN 1 ' .
                                             'WHEN ? THEN 2 ' .
                                             'WHEN ? THEN 3 ' .
                                             'ELSE 4 ' .
                                         'END ASC',
                                         array(
                                             'locale',
                                             $this->getLocale(),
                                             $this->getPrimaryLanguage(),
                                             '*',
                                         ),
                                         array(
                                             Sql\Expression::TYPE_IDENTIFIER,
                                             Sql\Expression::TYPE_VALUE,
                                             Sql\Expression::TYPE_VALUE,
                                             Sql\Expression::TYPE_VALUE,
                                         )
                                     ),
                                 ) )
                                 ->limit( 1 )
                                 ->getSqlString( $platform ) .
                        ')' );
                    }
                }
            }
        }

        if ( $tags )
        {
            $columns['tags'] = new Sql\Expression( '(' .
                $this->sql( $this->getTableInSchema(
                        static::$tagTableName
                     ) )
                     ->select()
                     ->columns( array(
                         new Sql\Expression(
                             'STRING_AGG( ?, ? ORDER BY ? ASC )',
                             array(
                                 'name',
                                 static::TAG_SEPARATOR,
                                 'name',
                             ),
                             array(
                                 Sql\Expression::TYPE_IDENTIFIER,
                                 Sql\Expression::TYPE_VALUE,
                                 Sql\Expression::TYPE_IDENTIFIER,
                             )
                         ),
                     ) )
                     ->join(
                         $this->getTableInSchema( static::$tagJoinTableName ),
                         static::$tagTableName . '.id = ' .
                         static::$tagJoinTableName . '.tagId',
                         array()
                     )
                     ->where( array(
                         new Sql\Predicate\Operator(
                             static::$tagJoinTableName . '.paragraphId',
                             Sql\Predicate\Operator::OPERATOR_EQUAL_TO,
                             static::$tableName . '.id',
                             Sql\Predicate\Operator::TYPE_IDENTIFIER,
                             Sql\Predicate\Operator::TYPE_IDENTIFIER
                         ),
                     ) )
                     ->getSqlString( $platform ) .
            ')' );
        }

        if ( $tagIds )
        {
            $columns['tagIds'] = new Sql\Expression( '(' .
                $this->sql( $this->getTableInSchema(
                        static::$tagJoinTableName
                     ) )
                     ->select()
                     ->columns( array(
                         new Sql\Expression(
                             'STRING_AGG( TEXT( ? ), ? ORDER BY ? ASC )',
                             array(
                                 'tagId',
                                 static::TAG_SEPARATOR,
                                 'tagId',
                             ),
                             array(
                                 Sql\Expression::TYPE_IDENTIFIER,
                                 Sql\Expression::TYPE_VALUE,
                                 Sql\Expression::TYPE_IDENTIFIER,
                             )
                         ),
                     ) )
                     ->where( array(
                         new Sql\Predicate\Operator(
                             static::$tagJoinTableName . '.paragraphId',
                             Sql\Predicate\Operator::OPERATOR_EQUAL_TO,
                             static::$tableName . '.id',
                             Sql\Predicate\Operator::TYPE_IDENTIFIER,
                             Sql\Predicate\Operator::TYPE_IDENTIFIER
                         ),
                     ) )
                     ->getSqlString( $platform ) .
            ')' );
        }

        if ( $localeTags )
        {
            $columns['localeTags'] = new Sql\Expression( '(' .
                $this->sql( $this->getTableInSchema(
                        static::$tagTableName
                     ) )
                     ->select()
                     ->columns( array(
                         new Sql\Expression(
                             'STRING_AGG( ?, ? ORDER BY ? ASC )',
                             array(
                                 'name',
                                 static::TAG_SEPARATOR,
                                 'name',
                             ),
                             array(
                                 Sql\Expression::TYPE_IDENTIFIER,
                                 Sql\Expression::TYPE_VALUE,
                                 Sql\Expression::TYPE_IDENTIFIER,
                             )
                         ),
                     ) )
                     ->join(
                         $this->getTableInSchema( static::$tagJoinTableName ),
                         static::$tagTableName . '.id = ' .
                         static::$tagJoinTableName . '.tagId',
                         array()
                     )
                     ->where( array(
                         new Sql\Predicate\Operator(
                             static::$tagJoinTableName . '.paragraphId',
                             Sql\Predicate\Operator::OPERATOR_EQUAL_TO,
                             static::$tableName . '.id',
                             Sql\Predicate\Operator::TYPE_IDENTIFIER,
                             Sql\Predicate\Operator::TYPE_IDENTIFIER
                         ),
                         new Sql\Predicate\PredicateSet(
                             array(
                                 new Sql\Predicate\IsNull(
                                     static::$tagTableName . '.locale'
                                 ),
                                 new Sql\Predicate\In(
                                     static::$tagTableName . '.locale',
                                     array(
                                         $this->getLocale(),
                                         $this->getPrimaryLanguage(),
                                         '',
                                     )
                                 ),
                             ),
                             Sql\Predicate\PredicateSet::COMBINED_BY_OR
                         ),
                     ) )
                     ->getSqlString( $platform ) .
            ')' );
        }

        return $columns;
    }
489023
public function selectConcat(array $columns, string $delimiter = '', ?string $alias = null)
    {
        $instance = $this->selectQueryInstance();

        $instance->selectQuery()->columnConcat($columns, $delimiter, $alias);

        return $instance;
    }
344878
public function getAddColumnsDDL($columns)
    {
        $ret = '';
        foreach ($columns as $column) {
            $ret .= $this->getAddColumnDDL($column);
        }

        return $ret;
    }
740564
public function addSelect($columns) {
		if(is_array($columns))
			return $this->_addSelect($columns);

		$columns = explode(',', $columns);
		foreach($columns as $columnstr) {
			$columnstr = trim($columnstr);

			preg_match('/(.*?)\s+as\s+([a-z_][a-zA-Z0-9_]*)?$/i', $columnstr, $matches);
			if(isset($matches[2])) {
				$alias = $matches[2];
				$column = $matches[1];
			}
			else
				$alias = $column = $columnstr;

			if(isset($this->columns[$alias]))
				throw new \Exception('Column alias '.$alias.' is already used.');
			$this->columns[$alias] = $column;
		}

		return $this;
	}
974789
public function select($columns= '*') {
        if (!is_array($columns)) {
            $columns= trim($columns);
            if ($columns == '*' || $columns === $this->_alias . '.*' || $columns === $this->xpdo->escape($this->_alias) . '.*') {
                $columns= $this->xpdo->getSelectColumns($this->_class, $this->_alias, $this->_alias . '_');
            }
            $columns= explode(',', $columns);
            foreach ($columns as $colKey => $column) $columns[$colKey] = trim($column);
        }
        if (is_array ($columns)) {
            if (!is_array($this->query['columns'])) {
                $this->query['columns']= $columns;
            } else {
                $this->query['columns']= array_merge($this->query['columns'], $columns);
            }
        }
        return $this;
    }
152492
protected function withoutSelectAliases(array $columns)
    {
        return array_map(function ($column) {
            return is_string($column) && ($aliasPosition = stripos($column, ' as ')) !== false
                    ? substr($column, 0, $aliasPosition) : $column;
        }, $columns);
    }
573295
protected function sortedQueryPrefix(array $aliases) {

        $sortFields = [];

        $result = $this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
                $this->getDriverEscaper()->reserved('subject') . ' ' .
                $this->getDriverEscaper()->dbCommand('FROM') .
                $this->operationSeparator . '(' .
                $this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
                $this->getDriverEscaper()->reserved('mainq') . '.' .
                $this->getDriverEscaper()->reserved('subject') .
                $this->getDriverEscaper()->getFieldsSeparator();

        foreach ($aliases as $alias) {
            $sortFields[] = $this->getDriverEscaper()->reserved($alias['name']) . '.' .
                    $this->getDriverEscaper()->reserved('object') . ' ' .
                    $this->getDriverEscaper()->dbCommand('AS') . ' ' . $alias['name'];
        }

        $result .= implode($this->getDriverEscaper()->getFieldsSeparator(), $sortFields)
                . ' ' .
                $this->getDriverEscaper()->dbCommand('FROM') . ' ' .
                ' ( ' . $this->query . ' ) AS mainq ' .
                $this->operationSeparator;

        return $result;
    }
1089764
protected function getSelectColumns(array $columns = array('*'))
	{
		if ($columns == array('*'))
		{
			$columns = array($this->related->getTable().'.*');
		}

		return array_merge($columns, array($this->parent->getTable().'.'.$this->firstKey));
	}
250198
public function getColumnList($columns, $delim = ',')
    {
        $list = array();
        foreach ($columns as $col) {
            if ($col instanceof Column) {
                $col = $col->getName();
            }
            $list[] = $col;
        }

        return implode($delim, $list);
    }
196385
protected function getSelectedColumns(array $fields, $fieldSourceAlias)
    {
        $columns = [];

        foreach ($fields as $fieldName => $field) {
            if ($field instanceof ILocalizableField && $field->getIsLocalized()) {
                $currentLocaleId = $this->getCurrentLocale();
                $defaultLocaleId = $this->getDefaultLocale();

                if ($this->withLocalization) {
                    foreach ($field->getLocalizations() as $localeId => $localeInfo) {
                        $columnName = $fieldSourceAlias . self::FIELD_SEPARATOR . $localeInfo['columnName'];
                        $alias = $fieldSourceAlias . self::ALIAS_SEPARATOR . $fieldName
                            . ILocalizedProperty::LOCALE_SEPARATOR . $localeId;
                        $columns[] = [$columnName, $alias];
                    }
                } else {
                    $columnName = $fieldSourceAlias . self::FIELD_SEPARATOR
                        . $field->getLocaleColumnName($currentLocaleId);
                    $alias = $fieldSourceAlias . self::ALIAS_SEPARATOR . $fieldName
                        . ILocalizedProperty::LOCALE_SEPARATOR . $currentLocaleId;
                    $columns[] = [$columnName, $alias];

                    if ($currentLocaleId !== $defaultLocaleId) {
                        $columnName = $fieldSourceAlias . self::FIELD_SEPARATOR
                            . $field->getLocaleColumnName($defaultLocaleId);
                        $alias = $fieldSourceAlias . self::ALIAS_SEPARATOR . $fieldName
                            . ILocalizedProperty::LOCALE_SEPARATOR . $defaultLocaleId;
                        $columns[] = [$columnName, $alias];
                    }
                }

            } else {
                $columnName = $fieldSourceAlias . self::FIELD_SEPARATOR . $field->getColumnName();
                $alias = $fieldSourceAlias . self::ALIAS_SEPARATOR . $fieldName;
                $columns[] = [$columnName, $alias];
            }
        }

        return $columns;
    }
916456
private function getJoinSql($baseTableAlias)
    {
        $joinSql           = '';
        $identifierColumns = $this->class->getIdentifierColumns($this->em);

        // INNER JOIN parent tables
        $parentClass = $this->class;

        while (($parentClass = $parentClass->getParent()) !== null) {
            $conditions = [];
            $tableName  = $parentClass->table->getQuotedQualifiedName($this->platform);
            $tableAlias = $this->getSQLTableAlias($parentClass->getTableName());
            $joinSql   .= ' INNER JOIN ' . $tableName . ' ' . $tableAlias . ' ON ';

            foreach ($identifierColumns as $idColumn) {
                $quotedColumnName = $this->platform->quoteIdentifier($idColumn->getColumnName());

                $conditions[] = $baseTableAlias . '.' . $quotedColumnName . ' = ' . $tableAlias . '.' . $quotedColumnName;
            }

            $joinSql .= implode(' AND ', $conditions);
        }

        // OUTER JOIN sub tables
        foreach ($this->class->getSubClasses() as $subClassName) {
            $conditions = [];
            $subClass   = $this->em->getClassMetadata($subClassName);
            $tableName  = $subClass->table->getQuotedQualifiedName($this->platform);
            $tableAlias = $this->getSQLTableAlias($subClass->getTableName());
            $joinSql   .= ' LEFT JOIN ' . $tableName . ' ' . $tableAlias . ' ON ';

            foreach ($identifierColumns as $idColumn) {
                $quotedColumnName = $this->platform->quoteIdentifier($idColumn->getColumnName());

                $conditions[] = $baseTableAlias . '.' . $quotedColumnName . ' = ' . $tableAlias . '.' . $quotedColumnName;
            }

            $joinSql .= implode(' AND ', $conditions);
        }

        return $joinSql;
    }