src/SqlGenerator.php
protected function generateSelectSQL()
        {
            $sql = ($this->query->isDistinct()) ? 'SELECT DISTINCT ' : 'SELECT ';

            if ($this->query->isCustomSelection()) {
                if ($this->query->isDistinct() && Core::getDriver() == Core::DRIVER_POSTGRES) {
                    foreach ($this->query->getSortOrders() as $sort_order) {
                        $this->query->addSelectionColumn($sort_order->getColumn());
                    }
                }

                $sql_parts = [];
                foreach ($this->query->getSelectionColumns() as $column => $selection) {
                    $alias = ($selection->getAlias()) ?? $this->query->getSelectionAlias($column);
                    $sub_sql = $selection->getVariableString();
                    if ($selection->isSpecial()) {
                        $sub_sql .= mb_strtoupper($selection->getSpecial()) . '(' . Query::quoteIdentifier($selection->getColumn()) . ')';
                        if ($selection->hasAdditional())
                            $sub_sql .= ' ' . $selection->getAdditional() . ' ';
                        if (mb_strpos($selection->getSpecial(), '(') !== false)
                            $sub_sql .= ')';
                    } else {
                        $sub_sql .= Query::quoteIdentifier($selection->getColumn());
                    }
                    $sub_sql .= ' AS ' . Query::quoteIdentifier($alias);
                    $sql_parts[] = $sub_sql;
                }
                $sql .= implode(', ', $sql_parts);
            } else {
                $this->addAllSelectColumns();
                $sql .= $this->generateSelectAllSQL();
            }

            return $sql;
        }
protected function generateSelectSQL()
        {
            $sql = ($this->query->isDistinct()) ? 'SELECT DISTINCT ' : 'SELECT ';

            if ($this->query->isCustomSelection()) {
                if ($this->query->isDistinct() && Core::getDriver() == Core::DRIVER_POSTGRES) {
                    foreach ($this->query->getSortOrders() as $sort_order) {
                        $this->query->addSelectionColumn($sort_order->getColumn());
                    }
                }

                $sql_parts = [];
                foreach ($this->query->getSelectionColumns() as $column => $selection) {
                    $alias = ($selection->getAlias()) ?? $this->query->getSelectionAlias($column);
                    $sub_sql = $selection->getVariableString();
                    if ($selection->isSpecial()) {
                        $sub_sql .= mb_strtoupper($selection->getSpecial()) . '(' . Query::quoteIdentifier($selection->getColumn()) . ')';
                        if ($selection->hasAdditional())
                            $sub_sql .= ' ' . $selection->getAdditional() . ' ';
                        if (mb_strpos($selection->getSpecial(), '(') !== false)
                            $sub_sql .= ')';
                    } else {
                        $sub_sql .= Query::quoteIdentifier($selection->getColumn());
                    }
                    $sub_sql .= ' AS ' . Query::quoteIdentifier($alias);
                    $sql_parts[] = $sub_sql;
                }
                $sql .= implode(', ', $sql_parts);
            } else {
                $this->addAllSelectColumns();
                $sql .= $this->generateSelectAllSQL();
            }

            return $sql;
        }
protected function generateSelectSQL ( ) { $ sql = ( $ this -> query -> isDistinct ( ) ) ? 'SELECT DISTINCT ' : 'SELECT ' ; if ( $ this -> query -> isCustomSelection ( ) ) { if ( $ this -> query -> isDistinct ( ) && Core :: getDriver ( ) == Core :: DRIVER_POSTGRES ) { foreach ( $ this -> query -> getSortOrders ( ) as $ sort_order ) { $ this -> query -> addSelectionColumn ( $ sort_order -> getColumn ( ) ) ; } } $ sql_parts = [ ] ; foreach ( $ this -> query -> getSelectionColumns ( ) as $ column => $ selection ) { $ alias = ( $ selection -> getAlias ( ) ) ?? $ this -> query -> getSelectionAlias ( $ column ) ; $ sub_sql = $ selection -> getVariableString ( ) ; if ( $ selection -> isSpecial ( ) ) { $ sub_sql .= mb_strtoupper ( $ selection -> getSpecial ( ) ) . '(' . Query :: quoteIdentifier ( $ selection -> getColumn ( ) ) . ')' ; if ( $ selection -> hasAdditional ( ) ) $ sub_sql .= ' ' . $ selection -> getAdditional ( ) . ' ' ; if ( mb_strpos ( $ selection -> getSpecial ( ) , '(' ) !== false ) $ sub_sql .= ')' ; } else { $ sub_sql .= Query :: quoteIdentifier ( $ selection -> getColumn ( ) ) ; } $ sub_sql .= ' AS ' . Query :: quoteIdentifier ( $ alias ) ; $ sql_parts [ ] = $ sub_sql ; } $ sql .= implode ( ', ' , $ sql_parts ) ; } else { $ this -> addAllSelectColumns ( ) ; $ sql .= $ this -> generateSelectAllSQL ( ) ; } return $ sql ; }
Generate the "select" part of the query

@return string
Generate the select part of the query