Attempts to compile the current query, including all Patterns and Filters
Excludes Transformations

@return string
545328
protected function getCurrentSQL() {
        $cloneQuery = clone $this->query;
        $cloneQuery = $this->loadElements($cloneQuery);
        return $cloneQuery->compile();
    }
243655
protected function compileExpression()
    {
        $parts = [$this->getMode()];

        foreach ($this->targetSize as $value) {

            if (is_numeric($value)) {
                $parts[] = (string) $value;
            }
        }

        foreach ($this->arguments as $i => $arg) {

            if (is_numeric($arg) || ($i === 1 and $this->isColor($arg))) {
                $parts[] = trim((string) $arg);
            }
        }

        $source = $this->source;
        $params = implode('/', $parts);
        $filter = $this->compileFilterExpression();

        return compact('source', 'params', 'filter');
    }
645476
public function buildQuery()
    {
        $model = $this->model;
        $query = $model::query();

        // perform joins
        if (is_array($this->join)) {
            foreach ($this->join as $condition) {
                list($joinModel, $column, $foreignKey) = $condition;
                $query->join($joinModel, $column, $foreignKey);
            }
        }

        // sanitze and set the filter
        $filter = $this->parseFilterInput($this->filter);
        $query->where($filter);

        // performs a search using LIKE queries
        // WARNING use sparingly, these queries are expensive
        if (!empty($this->search) && is_string($this->search) && property_exists($model, 'searchableProperties')) {
            $w = [];
            $search = addslashes($this->search);
            foreach ($model::$searchableProperties as $name) {
                $w[] = "`$name` LIKE '%$search%'";
            }

            if (count($w) > 0) {
                $query->where('('.implode(' OR ', $w).')');
            }
        }

        // eager loading
        foreach ($this->expand as $k) {
            $property = $model::getProperty($k);
            if ($property && isset($property['relation'])) {
                if (isset($property['id_property'])) {
                    $query->with($property['id_property']);
                } else {
                    $query->with($k);
                }
            }
        }

        if (isset($this->sort)) {
            $query->sort($this->sort);
        }

        // calculate limit and offset
        $start = ($this->page - 1) * $this->perPage;
        $query->start($start)->limit($this->perPage);

        return $query;
    }
357169
public function GetQueryRestrictionForActiveFilter()
    {
        $sQuery = $this->GetFromInternalCache('sQueryRestrictionForActiveFilter');
        if (is_null($sQuery)) {
            $aValues = $this->aActiveFilterData;
            if (!is_array($aValues)) {
                if (empty($aValues)) {
                    $aValues = array();
                } else {
                    $aValues = array($aValues);
                }
            }
            if (count($aValues) > 0) {
                $aValues = TTools::MysqlRealEscapeArray($aValues);
                //          $oVariantType = $this->GetVariantType();

                $sItemListQuery = "SELECT DISTINCT `shop_article`.`variant_parent_id`
                      FROM `shop_variant_type_value`
                INNER JOIN `shop_article_shop_variant_type_value_mlt` ON `shop_variant_type_value`.`id` = `shop_article_shop_variant_type_value_mlt`.`target_id`
                INNER JOIN `shop_article` ON `shop_article_shop_variant_type_value_mlt`.`source_id` = `shop_article`.`id`
                INNER JOIN `shop_article` AS PARENTARTICLE ON `shop_article`.`variant_parent_id` = PARENTARTICLE.`id`
                INNER JOIN `shop_variant_type` ON `shop_variant_type_value`.`shop_variant_type_id` = `shop_variant_type`.`id`
                     WHERE (`shop_variant_type_value`.`name` IN ('".implode("','", $aValues)."') OR `shop_variant_type_value`.`name_grouped` IN ('".implode("','", $aValues)."'))
                       AND `shop_variant_type`.`identifier` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->sVariantTypeIdentifier)."'
                       AND PARENTARTICLE.`active` = '1'
                   ";
                $sActiveRestrictions = TdbShopArticleList::GetActiveArticleQueryRestriction(false);
                if (!empty($sActiveRestrictions)) {
                    $sItemListQuery .= ' AND ('.$sActiveRestrictions.')';
                }
                $tRes = MySqlLegacySupport::getInstance()->query($sItemListQuery);
                //echo $sItemListQuery;echo "\n\n";
                $aIdList = array();
                while ($aItemRow = MySqlLegacySupport::getInstance()->fetch_assoc($tRes)) {
                    $aIdList[] = MySqlLegacySupport::getInstance()->real_escape_string($aItemRow['variant_parent_id']);
                }

                if (count($aIdList) > 0) {
                    $sQuery = "`shop_article`.`id` IN ('".implode("','", $aIdList)."')";
                }
            }

            $this->SetInternalCache('sQueryRestrictionForActiveFilter', $sQuery);
        }

        return $sQuery;
    }
1324115
public function getQuery()
    {
        $queryParts = array_map(function ($value) {
            return ($value instanceof Operator) ? $value->expression() : $value;
        }, $this->queryParts);

        return implode('', $queryParts);
    }
98763
public function getQuery()
    {
        $query = $this->database->getSelectQuery()->from($this->table);

        foreach ($this->join as $join) {
            if (!is_array($join[2])) {
                $join[2] = [$join[2]];
            }

            $where = array_shift($join[2]);
            if (!empty($join[2])) {
                foreach ($join[2] as $i => $value) {
                    $join[2][$i] = $this->database->bind($value);
                }

                $where = vsprintf($where, $join[2]);
            }

            $query->join($join[0], $join[1], $where, $join[3]);
        }

        foreach ($this->filter as $i => $filter) {
            //array('post_id=%s AND post_title IN %s', 123, array('asd'));
            $where = array_shift($filter);
            if (!empty($filter)) {
                foreach ($filter as $i => $value) {
                    $filter[$i] = $this->database->bind($value);
                }

                $where = vsprintf($where, $filter);
            }

            $query->where($where);
        }

        return $query;
    }
841779
public function getQueryParts()
    {
        // extract the part before {
        $partBeforeBrace = substr($this->query, 0, strpos($this->query, '{'));

        $this->queryParts = [
            'filter_pattern' => $this->extractFilterPattern($this->queryParts['where']),
            'graphs' => $this->extractGraphs($this->getQuery()),
            'named_graphs' => $this->extractNamedGraphs($this->getQuery()),
            'namespaces' => $this->extractNamespacesFromQuery($this->queryParts['where']),
            'prefixes' => $this->extractPrefixesFromQuery($this->getQuery()),
            'result_variables' => $this->extractVariablesFromQuery($partBeforeBrace),
            'sub_type' => $this->determineSubType($this->getQuery()),
            'triple_pattern' => $this->extractTriplePattern($this->queryParts['where']),
            'variables' => $this->extractVariablesFromQuery($this->getQuery()),
        ];

        $this->unsetEmptyValues($this->queryParts);

        return $this->queryParts;
    }
1298682
private function compile()
    {
        $commands = array_keys($this->commands);
        $values = $this->getArrayValues(array_values($this->commands));

        $origSource = $this->source;

        $vs = '%s';
        $bin = $this->converter;
        $type = preg_replace('#^image/#', null, $this->getInfo('type'));

        $this->tmpFile = $this->getTempFile();

        if ($this->isMultipartImage()) {

            $this->intermediate = $this->getTempFile($type);
            $this->source = $this->intermediate;

        }

        array_unshift($values, sprintf('%s:%s', $type, escapeshellarg($this->source)));

        array_unshift($values, $bin);

        array_unshift($commands, $vs);
        array_unshift($commands, $vs);

        if ($this->isMultipartImage()) {

            array_unshift(
                $values,
                sprintf(
                    '%s %s:%s -coalesce %s %s',
                    $this->converter,
                    $type,
                    $origSource,
                    $this->intermediate,
                    PHP_EOL
                )
            );
            array_unshift($commands, $vs);
        }

        array_push($values, sprintf('%s:%s', $this->getOutputType(), $this->tmpFile));
        array_push($commands, $vs);

        $cmd = implode(' ', $commands);

        $this->source = $origSource;

        return vsprintf($cmd, $values);
    }
151383
public function GetQueryRestrictionForActiveFilter()
    {
        $sQuery = $this->GetFromInternalCache('sQueryRestrictionForActiveFilter');
        if (is_null($sQuery)) {
            $aValues = $this->aActiveFilterData;
            if (count($aValues) > 0) {
                $sItemListQuery = $this->GetSQLQueryForQueryRestrictionForActiveFilter();
                $aIdList = array();
                if (!empty($sItemListQuery)) {
                    $tRes = MySqlLegacySupport::getInstance()->query($sItemListQuery);
                    $aIdList = array();
                    while ($aItemRow = MySqlLegacySupport::getInstance()->fetch_assoc($tRes)) {
                        $aIdList[] = MySqlLegacySupport::getInstance()->real_escape_string($aItemRow['source_id']);
                    }
                }

                if (count($aIdList) > 0) {
                    $sQuery = "`shop_article`.`id` IN ('".implode("','", $aIdList)."')";
                }
            }
            $this->SetInternalCache('sQueryRestrictionForActiveFilter', $sQuery);
        }

        return $sQuery;
    }
61223
public function compile()
	{
		//reset arrays
		$this->params     = [];
		$this->paramNames = [];
		$this->conditions = [];

		$this->compiled = true;

		$uri = $this->normalizeUri($this->getUri());

		// match patterns like /{param?:regex}
		// tested in https://regex101.com/r/gP6yH7
		$regex = preg_replace_callback(
			'#(?:(\\/)?\\{(\\w+)(\\?)?(?::((?:\\\\\\{|\\\\\\}|[^{}]|\\{\\d(?:\\,(?:\\d)?)?\\})+))?\\})#',
			[$this, 'createRegex'],
			$uri
		);

		$regex .= "/?";

		$regex = '#^' . $regex . '$#';

		if ($this->caseSensitive === false)
		{
			$regex .= 'i';
		}

		$this->pattern = $regex;

		return $this;
	}
930131
public function compile()
    {
        preg_match_all('#{(.*?)}#i', $this->format, $out);

        $compiled = $this->format;

        foreach ($out[0] as $i => $var) {
            $format = '(?P<%s>%s)%s';
            $name   = str_replace('?', '', $out[1][$i]);
            $regex  = $this->getWhere($name) ?: '.*';
            $opt    = '';

            if (substr($var, -2, 1) == '?') {
                $opt = '?';
                $compiled = str_replace('/'.$var, '/?'.$var, $compiled);
            }

            $compiled = str_replace($var, sprintf($format, $name, $regex, $opt), $compiled);
        }

        return $compiled;
    }
355116
public final function compile()
	{
		try {
			$q = $this->compileQuery();
			if ($this->log_query) {
				error_log(sprintf("SQL Query (compile):\n%s", $this->query_sql));
			}
			return $q;
		}
		catch (\Exception $ex) {
			// Make sure unfinished query will not make it to the output.
			ob_end_clean();
			throw $ex;
		}
	}
980295
public function compile()
    {
        $templateFilePrefix = $this->hasLocalizedVersion() ?
            $this->generateLocalizedViewPath() :
            $this->generateDefaultViewPath();

        $content = self::parseFile(
            $templateFilePrefix . $this->getConfig('file_extention'),
            $this->contextualVariables,
            (bool)$this->getConfig('allow_debug')
        );

        if (is_null($this->getConfig("layout"))) {
            return $content;
        }

        $layout = self::parseFile(
            $this->generateDefaultLayoutPath() . $this->getConfig('file_extention'),
            $this->contextualVariables,
            (bool)$this->getConfig('allow_debug')
        );

        return str_replace(self::TPL_YIELD, $content, $layout);
    }
906163
public function query()
	{
		if ($this->query_sql === null) {
			$this->compile();
		}

		if (empty($this->query_params)) {
			$t = microtime(true);
			try {
				$result = $this->pdo->query($this->query_sql);
				if ($this->log_query) {
					error_log(sprintf("SQL Query time: %F ms (query), %d rows.", (microtime(true) - $t) * 1000, $result->rowCount()));
				}
			}
			catch (\PDOException $ex) {
				throw new FlupdoException($ex->getMessage(), $ex->getCode(), $ex, $this->query_sql, $this->query_params);
			}
			if (!$result) {
				throw new FlupdoException(vsprintf("SQLSTATE[%s]: Error %s: %s", $this->pdo->errorInfo()),
					$this->pdo->errorCode(), null, $this->query_sql, $this->query_params);
			}
			return $result;
		} else {
			$t = microtime(true);
			try {
				$stmt = $this->prepare();
			}
			catch (\PDOException $ex) {
				throw new FlupdoException($ex->getMessage(), $ex->getCode(), $ex, $this->query_sql, $this->query_params);
			}
			if ($stmt === FALSE) {
				throw new FlupdoException(vsprintf("SQLSTATE[%s]: Error %s: %s", $this->pdo->errorInfo()),
					$this->pdo->errorCode(), null, $this->query_sql, $this->query_params);
			}

			$i = 1;
			foreach ($this->query_params as $param) {
				if (is_bool($param)) {
					$stmt->bindValue($i, $param, \PDO::PARAM_BOOL);
				} else if (is_null($param)) {
					$stmt->bindValue($i, $param, \PDO::PARAM_NULL);
				} else if (is_int($param)) {
					$stmt->bindValue($i, $param, \PDO::PARAM_INT);
				} else {
					// ignore locales when converting to string
					$stmt->bindValue($i, strval($param), \PDO::PARAM_STR);
				}
				$i++;
			}

			try {
				$success = $stmt->execute();
			}
			catch (\PDOException $ex) {
				throw new FlupdoException($ex->getMessage(), $ex->getCode(), $ex, $this->query_sql, $this->query_params);
			}
			if ($success === FALSE) {
				throw new FlupdoException(vsprintf("SQLSTATE[%s]: Error %s: %s", $stmt->errorInfo()),
					$stmt->errorCode(), null, $this->query_sql, $this->query_params);
			}
			if ($this->log_query) {
				error_log(sprintf("SQL Query time: %F ms (prepare + execute), %d rows.", (microtime(true) - $t) * 1000, $stmt->rowCount()));
			}
			if ($this->can_explain && $this->log_explain) {
				$this->explain();
			}
			return $stmt;
		}
	}
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);
    }
970268
protected function compile()
	{
		if ($this->compiled !== false)
		{
			return $this->compiled;
		}

		if ($this->isStatic())
		{
			$this->compiled = '~^'.$this->pattern.'$~';
			return $this->compiled;
		}

		$compiled = $this->pattern;
		foreach ($this->getSegments($compiled) as $segment)
		{
			$compiled = \str_replace($segment['token'], $segment['regex'], $compiled);
		}

		$this->compiled = "~^{$compiled}$~";
		return $this->compiled;
	}
67699
public function findOne()
    {
        $this->compile();
        $queryArr   = $this->queryArr;
        $queryArr['limit'] = 'LIMIT 1';
        $arguments  = $this->arguments;
        return $this->connection->fetchAssoc(implode(" ", $this->queryArr), $this->arguments);
    }