Generates the "FROM" clause.

@return string The "FROM" clause.
499762
private function getFromClause()
    {
        $fromClauses = array();

        foreach ($this->parts['from'] as $from) {
            $fromClause = $from['table'];

            if ($from['alias'] !== null) {
                $fromClause .= ' '.$from['alias'];
            }

            if (isset($this->parts['join'][$from['alias']])) {
                foreach ($this->parts['join'][$from['alias']] as $join) {
                    $fromClause .= ' '.strtoupper($join['type']).
                                   ' JOIN '.$join['table'].' '.$join['alias'].
                                   ' ON '.$join['expression'];
                }
            }

            $fromClauses[] = $fromClause;
        }

        return implode(', ', $fromClauses);
    }
407787
protected function buildStatement(): string
    {
        $this->statementBuilder->prepareRawStatement($this->statement, $this->bindings);
        return $this->statementBuilder->getStatement();
    }
1099696
public function getRootEntities()
    {
        $entities = [];

        foreach ($this->dqlParts['from'] as &$fromClause) {
            if (is_string($fromClause)) {
                $spacePos = strrpos($fromClause, ' ');
                $from     = substr($fromClause, 0, $spacePos);
                $alias    = substr($fromClause, $spacePos + 1);

                $fromClause = new Query\Expr\From($from, $alias);
            }

            $entities[] = $fromClause->getFrom();
        }

        return $entities;
    }
41857
public function getFrom()
    {
        if ($this->from) {
            return $this->from;
        }

        if ($this->alphaNumSender && strlen($this->alphaNumSender) > 0) {
            return $this->alphaNumSender;
        }
    }
125295
private function getUpdateQuery()
    {
        if (isset($this->parts['from'][0]['alias'])) {
            $fromClause = $this->parts['from'][0]['alias'].' FROM '.$this->getFromClause();
        } else {
            $fromClause = $this->parts['from'][0]['table'];
        }

        $setClause = array();

        foreach ($this->parts['set'] as $idenfier => $value) {
            $setClause[] = $this->getExpressionBuilder()->equal($idenfier, $value);
        }

        return 'UPDATE '.$fromClause.
               ' SET '.implode(', ', $setClause).
               (($this->parts['where'] !== null) ? ' WHERE '.$this->parts['where'] : null);
    }
1324115
public function getQuery()
    {
        $queryParts = array_map(function ($value) {
            return ($value instanceof Operator) ? $value->expression() : $value;
        }, $this->queryParts);

        return implode('', $queryParts);
    }
823509
public function generateAlias(Clause $clause)
    {
        if ($clause instanceof FieldName)
        {
            $table = $clause->getTable();
            if (empty($table))
            {
                // When no table is defined, it means only one table is being
                // used in the query. Aliases will not be required
                return "";
            }

            $prefix = $table->getPrefix();
            $alias = $prefix . '_' . $clause->getField();
        }
        elseif ($clause instanceof SQLFunction)
        {
            $func = $clause->getFunction();
            $alias = strtolower($func);
        }
        else
            throw new ImplementationException("No alias generation implemented for: " . get_class($clause));

        $cnt = 1;
        $base_alias = $alias;
        while (isset($this->field_aliases[$alias]))
            $alias = $base_alias . (++$cnt);

        $this->field_aliases[$alias] = true;
        return $alias;
    }
1097567
public function getQuery() {
        $query = 'SELECT '.implode(', ', $this->fields)
                .' FROM '.implode(', ', $this->from);
        if (count($this->conditions) > 0) {
            $query = $query.' WHERE '.implode(' AND ', $this->conditions);
        }
        $query = rtrim($query).';';

        return $query;
    }
503637
public function generate()
    {
        $code = array();

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        $propertyCode = $this->getIndentation() . $this->getVisibility() . ' ';
        if ($this->isStatic() === true) {
            $propertyCode .= 'static ';
        }

        $propertyCode .= '$' . $this->name;

        if ($this->defaultValue !== null && $this->defaultValue->getValue() !== null) {
            $propertyCode .= ' = ' . $this->defaultValue . ';';
        } else {
            $propertyCode .= ';';
        }

        $code[] = $propertyCode;

        return implode($this->getLineFeed(), $code);
    }
1210077
public function from()
    {
        $from = '';

        $numargs = func_num_args();

        if ($this->oosql_del_multiFlag) {


            if ($numargs < $this->oosql_del_numargs) {
                $msg = 'Columns and passed data do not match! ' . $this->sql();
                throw new \Exception($msg, 9810, null);
            }


        }

        $from .= ' FROM ';

        $from .= $this->oosql_table;

        if ($numargs > 0) {
            $from .= ', ';

            $arg_list = func_get_args();

            for ($i = 0; $i < $numargs; $i++) {
                if ($i !== 0 && $numargs > $i) {
                    $from .= ', ';
                }

                if ($arg_list[$i] instanceof oosql) {

                    $arg_list[$i]->alias();
                    $fields = $arg_list[$i]->getFields($arg_list[$i]->getTableAlias());

                    $this->sql(',' . implode(', ', $fields));
                    $from .= $arg_list[$i]->getSql() . ' AS ' . $arg_list[$i]->getTableAlias();
                } else {
                    $from .= $arg_list[$i];
                }
            }
        }

        $this->sql($from);

        $this->oosql_fromFlag = false;

        return $this;
    }
1194916
protected function buildStatement(): string
    {
        $this->statementBuilder->addTable($this->table);
        $this->statementBuilder->addCols($this->cols);
        $this->statementBuilder->addWhere($this->where);
        return $this->statementBuilder->getStatement();
    }
949691
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;
        }
569364
public function get_sql() : string {
		if ( empty( $this->columns_to_select ) ) {
			// this should be the default behavior
			$this->columns_to_select = [ '*' ];
		}

		$from = ' FROM ' . implode( ', ', $this->from ) . ' ';

		if ( ! empty( $this->joins ) ) {
			$from .= $this->joins;
		}

		$from  .= 'WHERE ' . $this->where_clause;
		$select = 'SELECT ' . implode( ', ', $this->columns_to_select ) . $from;

		if ( ! empty( $this->group_by ) ) {
			$select .= 'GROUP BY ' . implode( ', ', $this->group_by ) . ' ';
		}

		if ( $this->order_by !== '' ) {
			$select .= 'ORDER BY ' . $this->order_by . ' ';
		}

		$select .= 'LIMIT ' . $this->limit;

		if ( $this->offset !== '' ) {
			$select .= ' OFFSET ' . $this->offset;
		}

		return $select;
	}
830433
public function toString()
    {
        $query = '';

        switch ($this->type) {
            case 'select':
                $query .= (string) $this->select;
                $query .= (string) $this->from;

                if ($this->join) {
                    // Special case for joins
                    foreach ($this->join as $join) {
                        $query .= (string) $join;
                    }
                }

                if ($this->where) {
                    $query .= (string) $this->where;
                }

                if ($this->group) {
                    $query .= (string) $this->group;
                }

                if ($this->having) {
                    $query .= (string) $this->having;
                }

                if ($this->order) {
                    $query .= (string) $this->order;
                }

                if ($this->forUpdate) {
                    $query .= (string) $this->forUpdate;
                } else {
                    if ($this->forShare) {
                        $query .= (string) $this->forShare;
                    }
                }

                if ($this->noWait) {
                    $query .= (string) $this->noWait;
                }

                break;

            case 'update':
                $query .= (string) $this->update;
                $query .= (string) $this->set;

                if ($this->join) {
                    $onWord = ' ON ';

                    // Workaround for special case of JOIN with UPDATE
                    foreach ($this->join as $join) {
                        $joinElem = $join->getElements();

                        $joinArray = explode($onWord, $joinElem[0]);

                        $this->from($joinArray[0]);
                        $this->where($joinArray[1]);
                    }

                    $query .= (string) $this->from;
                }

                if ($this->where) {
                    $query .= (string) $this->where;
                }

                break;

            case 'insert':
                $query .= (string) $this->insert;

                if ($this->values) {
                    if ($this->columns) {
                        $query .= (string) $this->columns;
                    }

                    $elements = $this->values->getElements();

                    if (!($elements[0] instanceof $this)) {
                        $query .= ' VALUES ';
                    }

                    $query .= (string) $this->values;

                    if ($this->returning) {
                        $query .= (string) $this->returning;
                    }
                }

                break;

            default:
                $query = parent::toString();
                break;
        }

        $query = $this->processLimit($query, $this->limit, $this->offset);

        if ($this->suffix) {
            $query .= ' ' . (string) $this->suffix;
        }

        if ($this->type === 'select' && $this->alias !== null) {
            $query = sprintf('(%s) AS %s', $query, $this->alias);
        }

        return $query;
    }
913225
private function createCommandDocument()
    {
        $cmd = ['find' => $this->collectionName, 'filter' => (object) $this->filter];

        $options = $this->createQueryOptions();

        if (empty($options)) {
            return $cmd;
        }

        // maxAwaitTimeMS is a Query level option so should not be considered here
        unset($options['maxAwaitTimeMS']);

        $modifierFallback = [
            ['allowPartialResults', 'partial'],
            ['comment', '$comment'],
            ['hint', '$hint'],
            ['maxScan', '$maxScan'],
            ['max', '$max'],
            ['maxTimeMS', '$maxTimeMS'],
            ['min', '$min'],
            ['returnKey', '$returnKey'],
            ['showRecordId', '$showDiskLoc'],
            ['sort', '$orderby'],
            ['snapshot', '$snapshot'],
        ];

        foreach ($modifierFallback as $modifier) {
            if ( ! isset($options[$modifier[0]]) && isset($options['modifiers'][$modifier[1]])) {
                $options[$modifier[0]] = $options['modifiers'][$modifier[1]];
            }
        }
        unset($options['modifiers']);

        return $cmd + $options;
    }
202007
private function getSelectQuery()
	{
		$result = $this->getSelectClause();

		if ($join = $this->getJoinClause()) {
			$result .= ' ' . $join;
		}

		if ($where = $this->getWhereClause()) {
			$result .= ' ' . $where;
		}

		if ($groupBy = $this->getGroupByClause()) {
			$result .= ' ' . $groupBy;
		}

		if ($orderBy = $this->getOrderByClause()) {
			$result .= ' ' . $orderBy;
		}

		if ($limit = $this->getLimitClause()) {
			$result .= ' ' . $limit;
		}

		if ($offset = $this->getOffsetClause()) {
			$result .= ' ' . $offset;
		}

		return $result;
	}
887270
public function getCreateStatement()
    {
        $sql = [];

        foreach ($this->tables as $table) {
            /** @var Table $table*/
            $createTable = new CreateTable($table->getName());
            $createTable->setAdapter($this->getAdapter());
            $createTable->setColumns($table->getColumns());
            $createTable->setConstraints($table->getConstraints());
            $sql[] = $createTable->getQueryString();
        }
        return implode(';', $sql);
    }