Prepare string to apply it inside SQL query

@return string
492109
protected function prepareOrderBy(): string
    {
        if (empty($this->orderBy)) {
            return '';
        }
        $orders = [];
        foreach ($this->orderBy as $column => $order) {
            $orders[] = $column . ' ' . $order;
        }
        return ' ORDER BY ' . implode(', ', $orders);
    }
1298334
public function toQueryString()
    {
        $queryString = '';
        $inString = false;
        $parameterIndex = 0;
        $length = strlen($this->statement);

        for ($i=0; $i < $length; $i++) {
            $char = $this->statement{$i};
            if ($char === '\'') {
                if ($inString && $this->statement{max(0, $i-1)} === '\\') {
                    $inString = true;
                } else {
                    $inString = !$inString;
                }
                $queryString .= $char;
            } elseif ($char === '?' && !$inString) {
                $parameterIndex ++;
                $queryString .= $this->parametersMap[$parameterIndex];
            } else {
                $queryString .= $char;
            }
        }

        return $queryString;
    }
715641
public function prepare(string $sql = null)
    {
        $this->sqlQuery = $this->getConnection()->prepare($this->getSql($sql));

        return $this;
    }
159471
public function toSql(): string
    {
        $sql = $this->queryRelate->getQuery()->toSql();

        $this->resetQueryRelate();

        return $sql;
    }
349260
public function getRawQuery()
    {
        $sql = array();

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

        return implode(' ', $sql);
    }
249268
public function prepare($query = null)
    {
        $of         = is_null($query) ? $this->getQuery() : $query;
        $datatables = $this->datatables->of($of, get_class($this));
        $path       = str_replace(url('/'), '', url()->current());
        Event::fire("datatables.value.{$path}", [$datatables]);
        Event::fire(new Value($path, $datatables));

        return $datatables;
    }
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;
    }
1366580
public function prepare($sql)
    {
        $connection = ConnectionManager::getConnection();
        $statement = $connection->prepare($sql);
        $statement->setFetchMode(\PDO::FETCH_NUM);
        return $statement;
    }
948690
public function compose(SQL $SQL){

		$tokens = [];
		$query_string = '';

		foreach($this->_values as $name => $value){

			// Throws an exception on invalid name/value

			$this->_checkParameter($name, $value);

			assert('is_array($this->_parameters[$name])');

			$prepared_value = $this->_prepareValue($value, $SQL,
				$this->_parameters[$name]['identifier']);
			$tokens[$this->_parameters[$name]['uid']] = $prepared_value;
		}

		foreach($this->_query as $query_part){

			list($token, $value) = explode(' ', $query_part, 2);

			switch($token){

				case 'P':

					if(isset($tokens[$value])){

						$query_string .= $tokens[$value];
					}

					break;

				case 'T':

					$query_string .= $value;

					break;

				default: ExceptionHandler::notice("Invalid token $token");
			}
		}

		return $query_string;
	}
656064
protected function prepare()
    {
        $this
            ->getSession()
            ->getConnection()
            ->sendPrepareQuery(
                $this->getClientIdentifier(),
                $this->orderParameters($this->sql)
            );
        $this->is_prepared = true;

        return $this;
    }
993521
final public function prepare()
    {

        $DB = $this->DBO;
        $QUERY = $this->compile();

        //echo $QUERY;
        //Compile the query;
        $STATEMENT = $DB->prepare($QUERY);

        //Return the Result Object;
        return $STATEMENT;
    }
1182066
public function toString()
    {
        if (!$this->_parts['into']) {
            throw new SqlException("Invalid `INSERT` statement, missing `INTO` clause.");
        }

        $fields = count($this->_parts['values']) ? array_keys($this->_parts['values'][0]) : [];

        return 'INSERT' .
            $this->_buildFlags($this->_parts['flags']) .
            $this->_buildClause('INTO', $this->dialect()->name($this->_parts['into'], true)) .
            $this->_buildChunk('(' . $this->dialect()->names($fields, true) . ')', false) .
            $this->_buildValues() .
            $this->_buildClause('RETURNING', $this->dialect()->names($this->_parts['returning'], false, ''));
    }
492040
public function prepare() {
        $sql = $this->getSql();
        $params = array_merge($this->whereParams(), $this->having_params);
        return [$sql, $params];
    }
795627
private function _prepareExpression()
	{
		$this->expression = ($this->tableName && $this->alias) ?
			$this->tableName . '.' . $this->columnName . ' AS ' . $this->alias : (($this->tableName && !$this->alias) ?
				$this->tableName . '.' . $this->columnName : ((!$this->tableName && $this->alias) ?
					$this->columnName . ' AS ' . $this->alias : $this->columnName));
	}
764472
protected function prepareExpressionPlaceholders($sql)
    {
        if (!count($this->expressions)) {
            return $sql;
        }
        $sql = str_replace(array_keys($this->expressions), array_values($this->expressions), $sql);

        return $sql;
    }
653348
protected function prepare_sql_items() {
        global $DB;
        if (!preg_match('/\\%ITEMFILTER\\%/', $this->sql)) {
            return;
        }
        $this->init_items_access();
        $unaccessibleitems = array_filter($this->accessibleitems, function($item) {
            return !$item;
        });
        $idx = 0;
        while (preg_match('/^([^\\0]*?)\\%ITEMFILTER\\%([^\\0]*)$/', $this->sql, $matches)) {
            list($sql, $params) = $DB->get_in_or_equal(array_keys($unaccessibleitems),
                    SQL_PARAMS_NAMED, 'ia_'.($idx++).'_', false, 0);
            $this->sql = $matches[1].' '.$sql.' '.$matches[2];
            $this->params += $params;
        }
    }
1104051
public function getQuery(): string
    {
        $sql = $this->getSql();

        $sql = str_replace(['%', '?'], ['%%', '"%s"'], $sql);

        // replace mask by data
        return vsprintf($sql, $this->getParams());
    }