$query->getCompiledSelect()
worked for me.
You can check system\Database\BaseBuilder.php
and see which function returns sql query as string.
Found this in there and it worked for me.
/**
* Get SELECT query string
*
* Compiles a SELECT query string and returns the sql.
*
* @param boolean $reset TRUE: resets QB values; FALSE: leave QB values alone
*
* @return string
*/
public function getCompiledSelect(bool $reset = true): string
{
$select = $this->compileSelect();
if ($reset === true)
{
$this->resetSelect();
}
return $this->compileFinalQuery($select);
}
and in system\Database\Query.php
there is getQuery()
. Either of this might be useful.
/**
* Returns the final, processed query string after binding, etal
* has been performed.
*
* @return string
*/
public function getQuery(): string
{
if (empty($this->finalQueryString))
{
$this->finalQueryString = $this->originalQueryString;
}
$this->compileBinds();
return $this->finalQueryString;
}