Get the sql without any replacements
@return string
349260
public function getRawQuery()
    {
        $sql = array();

        foreach ($this->getClauses() as $clause) {
            if (!$clause->isEmpty()) {
                $sql[] = $clause;
            }
        }

        return implode(' ', $sql);
    }
1332036
public function getSqlSegment()
    {
        if (!empty($this->sqlSegment)) {
            return $this->sqlSegment;
        }

        if ($this->dbTableName && $this->columnName) {
            return $this->dbTableName . '.' . $this->columnName;
        }
    }
962612
protected function get_instance_sql() {
        global $DB;
        if ($this->_instancessql === null) {
            $instances = $this->get_enrolment_instances();
            $filter = $this->get_enrolment_filter();
            if ($filter && array_key_exists($filter, $instances)) {
                $sql = " = :ifilter";
                $params = array('ifilter'=>$filter);
            } else {
                $filter = 0;
                if ($instances) {
                    list($sql, $params) = $DB->get_in_or_equal(array_keys($this->get_enrolment_instances()), SQL_PARAMS_NAMED);
                } else {
                    // no enabled instances, oops, we should probably say something
                    $sql = "= :never";
                    $params = array('never'=>-1);
                }
            }
            $this->instancefilter = $filter;
            $this->_instancessql = array($sql, $params, $filter);
        }
        return $this->_instancessql;
    }
320580
protected function sql()
    {
        if ( null === $this->sql )
        {
            $this->sql = new Sql(
                $this->getDbAdapter(),
                $this->getTableInSchema( 'settings' )
            );
        }

        return $this->sql;
    }
211098
public function getQuery()
    {
        $joins = empty($this->joins) ? '' : implode(' ', $this->joins);
        $where = empty($this->where) ? '' : 'WHERE '.implode(' AND ', $this->where);
        $sort = empty($this->sortBy) ? '' : 'ORDER BY '.implode(', ', $this->sortBy);
        $limit = is_null($this->page) ? '' : 'LIMIT ' . $this->page .',' .$this->length;
        $group = empty($this->group) ? '' : 'GROUP BY ' . implode(', ', $this->group);
        
        $query = sprintf(
            'SELECT %s FROM %s %s %s %s %s %s;',
            $this->select,
            $this->from,
            $joins,
            $where,
            $group,
            $sort,
            $limit
        );
        
        return str_replace('  ', ' ', $query);
    }
147887
public function getCount()
	{
		$data_source_sql_builder = $this->data_source->getSqlBuilder();

		try {
			$primary = $this->data_source->getPrimary();

		} catch (\LogicException $e) {
			if ($data_source_sql_builder->getGroup() !== '') {
				return $this->data_source->count(
					'DISTINCT ' . Strings::replace($data_source_sql_builder->getGroup(), '~ (DESC|ASC)~')
				);
			}

			return $this->data_source->count('*');
		}

		if ($data_source_sql_builder->getGroup() !== '') {
			return $this->data_source->count(
				'DISTINCT ' . Strings::replace($data_source_sql_builder->getGroup(), '~ (DESC|ASC)~')
			);
		} else {
			return $this->data_source->count(
				$this->data_source->getName() . '.' . (is_array($primary) ? reset($primary) : $primary)
			);
		}
	}
545328
protected function getCurrentSQL() {
        $cloneQuery = clone $this->query;
        $cloneQuery = $this->loadElements($cloneQuery);
        return $cloneQuery->compile();
    }
381728
public function sqlFilters()
    {
        if (!$this->hasFilters()) {
            return '';
        }

        $criteria = $this->createFilter([
            'filters' => $this->filters()
        ]);

        $sql = $criteria->sql();
        if (strlen($sql) > 0) {
            $sql = ' WHERE '.$sql;
        }

        return $sql;
    }
868095
private function buildOriginalQuery()
    {
        return
            'SELECT '.$this->buildSelectedColumns().' FROM '.$this->quoteIdentifier(
                self::cyrus()->getTableName()
            ).' '.$this->getWhere().
            ' '.$this->getGroupBy().' '.$this->buildHavingConditions().' '.$this->getOrderBy().' '.$this->getLimit();
    }
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;
	}
1309646
private function getSQLForInsert()
    {
        return 'INSERT INTO ' . $this->sqlParts['from']['table'] .
        ' (' . implode(', ', array_keys($this->sqlParts['values'])) . ')' .
        ' VALUES(' . implode(', ', $this->sqlParts['values']) . ')';
    }
793436
public function build()
    {
        $sql = [
            $this->select->build(),
            $this->from->build(),
            $this->where->build(),
            $this->groupBy->build(),
            $this->having->build(),
            $this->orderBy->build(),
            $this->limit->build(),
            $this->union->build(),
        ];

        $this->values = array_merge(
            $this->where->getValues(),
            $this->having->getValues(),
            $this->union->getValues());

        $sql = implode(' ', array_filter($sql));

        // when there is no select statement then the query
        // is probably just a where subquery, thus does
        // not need to be prefixed with WHERE
        if ('WHERE ' === substr($sql, 0, 6)) {
            return substr($sql, 6);
        }

        return $sql;
    }
783677
public function sqlOrders()
    {
        if (!$this->hasOrders()) {
            return '';
        }

        $parts = [];
        foreach ($this->orders() as $order) {
            if (!$order instanceof DatabaseOrder) {
                $order = $this->createOrder($order->data());
            }

            $sql = $order->sql();
            if (strlen($sql) > 0) {
                $parts[] = $sql;
            }
        }

        if (empty($parts)) {
            return '';
        }

        return ' ORDER BY '.implode(', ', $parts);
    }
505651
protected function whereSql() {
        $this->params = [];
        $sql = $this->parseWhere($this->wheres, $this->params);
        if ($sql) {
            $sql = " WHERE " . $sql;
        }
        return $sql;
    }
524358
public function getSql()
    {
        $compileFunction = $this->getCompileFunction();
        $grammar = $this->queryBuilder->getGrammar();

        $sql = call_user_func_array([$grammar, $compileFunction], [
            'builder'  => $this->queryBuilder,
            'values'   => $this->values,
            'sequence' => '',
        ]);

        // For some DBMS like SQLite Laravel issues two queries as an array instead of one string
        // This is seriously not ok, but anyway...
        if (is_array($sql)) {
            $sql = implode('; ', array_keys($sql));
        }

        return $sql;
    }
1080503
public function getSelectSql()
    {
        $sql = "SELECT ";

        $sql .= $this->implodeSqlClauses($this->columns, ", ").
            " FROM `".$this->schemaName."` AS `".$this->getAlias()."`";

        foreach($this->joins as $join){
            $joinsSql = $join->getSql($this);
            if (strpos($joinsSql," ") !== false){
                $joinsSql = "(".$joinsSql.")";
            }

            $sql .= " ".$join->joinType." ".$joinsSql." AS `".$join->statement->getAlias()."` ON `".$this->getAlias()."`.`".
                $join->parentColumn."` = `".$join->statement->getAlias()."`.`".$join->childColumn."`";
        }

        if ($this->whereExpression) {
            $havingSql = $this->whereExpression->getWhereSql($this);
            if ($havingSql != "" ){
                $sql .= " WHERE ".$havingSql;
            }
        }
        
        if (count($this->groups)){
            $sql .= " GROUP BY ".$this->implodeSqlClauses($this->groups, ", ");
        }

        if ($this->whereExpression) {
            $havingSql = $this->whereExpression->getHavingSql($this);
            if ($havingSql != "" ){
                $sql .= " HAVING ".$havingSql;
            }
        }

        if (count($this->sorts)){
            $sql .= " ORDER BY ".$this->implodeSqlClauses($this->sorts, ", ");
        }

        if ($this->hasLimit()){
            $sql .= " LIMIT ".$this->limitStart.", ".$this->limitCount;
        }

        return $sql;
    }
107533
public function nextQuery()
    {
        $sql = null;

        while (($line = $this->sqlReader->readLine()) !== null) {
            $delimiter = $this->parent->getDelimiter();
            $project = $this->parent->getOwningTarget()->getProject();
            $line = $project->replaceProperties(trim($line));

            if (($line != $delimiter) && (StringHelper::startsWith("//", $line)
                    || StringHelper::startsWith("--", $line)
                    || StringHelper::startsWith("#", $line))
            ) {
                continue;
            }

            $sql .= " " . $line . "\n";

            /**
             * fix issue with PDO and wrong formated multistatements
             *
             * @issue 1108
             */
            if (StringHelper::endsWith($delimiter, $line)) {
                break;
            }
        }

        return $sql;
    }