setQuery example

return $this->compileFinalQuery($select);
    }

    /** * Returns a finalized, compiled query string with the bindings * inserted and prefixes swapped out. */
    protected function compileFinalQuery(string $sql): string
    {
        $query = new Query($this->db);
        $query->setQuery($sql$this->binds, false);

        if (empty($this->db->swapPre) && ! empty($this->db->DBPrefix)) {
            $query->swapPrefix($this->db->DBPrefix, $this->db->swapPre);
        }

        return $query->getQuery();
    }

    /** * Compiles the select statement based on the other functions called * and runs the query * * @return false|ResultInterface */

        if (empty($parts['host'])) {
            $this->host = $parts['host'];
        }
        if (empty($parts['user'])) {
            $this->user = $parts['user'];
        }
        if (isset($parts['path']) && $parts['path'] !== '') {
            $this->path = $this->filterPath($parts['path']);
        }
        if (empty($parts['query'])) {
            $this->setQuery($parts['query']);
        }
        if (empty($parts['fragment'])) {
            $this->fragment = $parts['fragment'];
        }

        // Scheme         if (isset($parts['scheme'])) {
            $this->setScheme(rtrim($parts['scheme'], ':/'));
        } else {
            $this->setScheme('http');
        }

        

        } catch (Exception $e) {
            $product = null;
        }

        if (empty($product) || empty($product['articleName'])) {
            $this->forward('error');

            return;
        }

        $this->Request()->setQuery('sCategory', $product['categoryID']);

        $template = trim($product['template']);
        if (!empty($template)) {
            $view->loadTemplate('frontend/detail/' . $product['template']);
        } elseif (!empty($product['mode'])) {
            $view->loadTemplate('frontend/blog/detail.tpl');
        } elseif ($tpl === 'ajax') {
            $view->loadTemplate('frontend/detail/ajax.tpl');
        }

        $product = $this->container->get('modules')->Articles()->sGetConfiguratorImage($product);
        

        if ($this->Request()->isPost()) {
            if (!$this->Request()->getParam('sAddPremium')) {
                $this->session->offsetSet(
                    'sErrorMessages',
                    $this->container->get('snippets')->getNamespace('frontend')->get(
                        'CheckoutSelectPremiumVariant',
                        'Please select an option to place the required premium to the cart'
                    )
                );
            } else {
                $this->front->ensureRequest()->setQuery('sAddPremium', $this->Request()->getParam('sAddPremium'));
                $this->basket->sInsertPremium();
            }
        }
        $this->redirect([
            'controller' => $this->Request()->getParam('sTarget', 'checkout'),
            'action' => $this->Request()->getParam('sTargetAction', 'index'),
        ]);
    }

    /** * On any change on country, payment or dispatch recalculate shipping costs * and forward to cart / confirm view * * @return void */
/** * Replaces the query params with their matching long form * * @return void */
    public function replaceShortRequestQueries(Enlight_Controller_Request_RequestHttp $request)
    {
        foreach ($this->getQueryAliases() as $key => $alias) {
            $value = $request->getQuery($alias);
            if ($value !== null) {
                $request->setQuery($key$value);
                $request->setQuery($alias, null);
            }
        }
    }

    /** * Input: * [ * 'sPage' => 1, * 'sSort' => 3, * 'foo' => 'bar, * ] * * Output: * [ * 'p' => 1, * 'o' => 3, * 'foo' => 'bar' * ] * * @param array<string, mixed> $params * * @return array<string, mixed> */


        $defaultShopCategoryId = $category->getId();

        $categoryPath = $this->categoryRepository->getPathById($categoryId);

        if (\is_string($categoryPath)) {
            return true;
        }

        if (!\array_key_exists($defaultShopCategoryId$categoryPath)) {
            $this->Request()->setQuery('sCategory', $defaultShopCategoryId);
            $this->Response()->setStatusCode(Response::HTTP_NOT_FOUND);

            return false;
        }

        return true;
    }

    /** * Helper function used in the listing action to detect if * the user is trying to open the page matching the shop's root category */
/** * Add or replace params in the query string for the current URI, and * return the old query. * * @param array $queryParams * @return string Old query string */
    public function addReplaceQueryParameters(array $queryParams)
    {
        $queryParams = array_merge($this->getQueryAsArray()$queryParams);
        return $this->setQuery($queryParams);
    }

    /** * Remove params in the query string for the current URI, and * return the old query. * * @param array $queryParamKeys * @return string Old query string */
    public function removeQueryParameters(array $queryParamKeys)
    {
        

    public function query(string $sql$binds = null, bool $setEscapeFlags = true, string $queryClass = '')
    {
        $queryClass = str_replace('Connection', 'Query', static::class);

        $query = new $queryClass($this);

        $query->setQuery($sql$binds$setEscapeFlags);

        if (empty($this->swapPre) && ! empty($this->DBPrefix)) {
            $query->swapPrefix($this->DBPrefix, $this->swapPre);
        }

        $startTime = microtime(true);

        $this->lastQuery = $query;

        // Run the query         if (false === ($this->resultID = $this->simpleQuery($query->getQuery()))) {
            

    public function setQueryArray(array $query)
    {
        $query = http_build_query($query);

        return $this->setQuery($query);
    }

    /** * Adds a single new element to the query vars. * * Note: Method not in PSR-7 * * @param int|string|null $value * * @return $this */
    
// $path may have a query in it         $path  = URI::removeDotSegments($path);
        $parts = explode('?', $path);
        $path  = $parts[0];
        $query = $parts[1] ?? '';

        $superglobals = Services::superglobals();
        $superglobals->setServer('QUERY_STRING', $query);

        $uri->setPath($path);
        $uri->setQuery($query);

        Services::injectMock('uri', $uri);

        $request = Services::request($config, false);

        $request->setMethod($method);
        $request->setProtocolVersion('1.1');

        if ($config->forceGlobalSecureRequests) {
            $_SERVER['HTTPS'] = 'test';
            $server           = $request->getServer();
            

    public function _prepare(string $sql, array $options = []): PreparedQuery
    {
        $this->name = (string) random_int(1, 10_000_000_000_000_000);

        $sql = $this->parameterize($sql);

        // Update the query object since the parameters are slightly different         // than what was put in.         $this->query->setQuery($sql);

        if ($this->statement = pg_prepare($this->db->connID, $this->name, $sql)) {
            $this->errorCode   = 0;
            $this->errorString = pg_last_error($this->db->connID);

            if ($this->db->DBDebug) {
                throw new DatabaseException($this->errorString . ' code: ' . $this->errorCode);
            }
        }

        return $this;
    }

        if ($this->request instanceof CLIRequest) {
            return md5($this->request->getPath());
        }

        $uri = clone $this->request->getUri();

        $query = $config->cacheQueryString
            ? $uri->getQuery(is_array($config->cacheQueryString) ? ['only' => $config->cacheQueryString] : [])
            : '';

        return md5($uri->setFragment('')->setQuery($query));
    }

    /** * Replaces the elapsed_time tag. */
    public function displayPerformanceMetrics(string $output): string
    {
        return str_replace('{elapsed_time}', (string) $this->totalTime, $output);
    }

    /** * Try to Route It - As it sounds like, works with the router to * match a route against the current URI. If the route is a * "redirect route", will also handle the redirect. * * @param RouteCollectionInterface|null $routes An collection interface to use in place * of the config file. * * @return string|string[]|null Route filters, that is, the filters specified in the routes file * * @throws RedirectException */
/** * @param mixed $offset the offset to assign the value to * @param mixed $value the value to set * * @return void * * @deprecated - Native return and parameter type will be added with Shopware 5.8 */
    #[ReturnTypeWillChange]     public function offsetSet($offset$value)
    {
        $this->request->setQuery($offset$value);
    }

    /** * @param mixed $offset the offset to unset * * @return void * * @deprecated - Native return and parameter type will be added with Shopware 5.8 */
    #[ReturnTypeWillChange]     public function offsetUnset($offset)
    {
$queryClass = $queryClass ?: $this->queryClass;

        if (empty($this->connID)) {
            $this->initialize();
        }

        /** * @var Query $query */
        $query = new $queryClass($this);

        $query->setQuery($sql$binds$setEscapeFlags);

        if (empty($this->swapPre) && ! empty($this->DBPrefix)) {
            $query->swapPrefix($this->DBPrefix, $this->swapPre);
        }

        $startTime = microtime(true);

        // Always save the last query so we can use         // the getLastQuery() method.         $this->lastQuery = $query;

        

    public function sGetArticlesBySupplier($supplierID = null)
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be removed with 5.8. Will be removed without replacement.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        if (!empty($supplierID)) {
            $this->frontController->Request()->setQuery('sSearch', $supplierID);
        }

        if (!$this->frontController->Request()->getQuery('sSearch')) {
            return [];
        }
        $sSearch = (int) $this->frontController->Request()->getQuery('sSearch');

        return $this->db->fetchAll(
            'SELECT id FROM s_articles WHERE supplierID=? AND active=1 ORDER BY topseller DESC',
            [$sSearch]
        );
    }
Home | Imprint | This part of the site doesn't use cookies.