getQueryPart example

try {
            $query = $this->createAvailableMessagesQueryBuilder()
                ->orderBy('available_at', 'ASC')
                ->setMaxResults(1);

            if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
                $query->select('m.id');
            }

            // Append pessimistic write lock to FROM clause if db platform supports it             $sql = $query->getSQL();
            if (($fromPart = $query->getQueryPart('from'))
                && ($table = $fromPart[0]['table'] ?? null)
                && ($alias = $fromPart[0]['alias'] ?? null)
            ) {
                $fromClause = sprintf('%s %s', $table$alias);
                $sql = str_replace(
                    sprintf('FROM %s WHERE', $fromClause),
                    sprintf('FROM %s WHERE', $this->driverConnection->getDatabasePlatform()->appendLockHint($fromClause, LockMode::PESSIMISTIC_WRITE)),
                    $sql
                );
            }

            
return $query;
    }

    /** * {@inheritdoc} */
    public function createProductQuery(Criteria $criteria, ShopContextInterface $context)
    {
        $query = $this->createQueryWithSorting($criteria$context);

        $select = $query->getQueryPart('select');

        if ($criteria->fetchCount()) {
            $query->select([
                'SQL_CALC_FOUND_ROWS product.id as __product_id',
                'variant.id as __variant_id',
                'variant.ordernumber as __variant_ordernumber',
            ]);
        } else {
            $query->select([
                'product.id as __product_id',
                'variant.id as __variant_id',
                

        $productDefinition = $this->getContainer()->get(ProductDefinition::class);
        $criteria = new Criteria();
        $criteria->setTerm('searchTerm');
        $criteria->addSorting(new FieldSorting('createdAt', FieldSorting::ASCENDING));

        $queryBuilder = new QueryBuilder($this->createMock(Connection::class));

        $builder = $this->getContainer()->get(CriteriaQueryBuilder::class);
        $builder->build($queryBuilder$productDefinition$criteria, Context::createDefaultContext());

        static::assertEquals($queryBuilder->getQueryPart('orderBy')[
            'MIN(`product`.`created_at`) ASC',
            '_score DESC',
        ]);
    }

    public function testSortByScoreAndAdditionalSortingWithScore(): void
    {
        $productDefinition = $this->getContainer()->get(ProductDefinition::class);
        $criteria = new Criteria();
        $criteria->setTerm('searchTerm');
        $criteria->addSorting(new FieldSorting('createdAt', FieldSorting::ASCENDING));
        
$this->resolver->join($resolverContext);

        static::assertSame([
            '`document`' => [
                [
                    'joinType' => 'left',
                    'joinTable' => '`order`',
                    'joinAlias' => '`document.order`',
                    'joinCondition' => '`document`.`order_id` = `document.order`.`id` AND `document`.`order_version_id` = `document.order`.`version_id`',
                ],
            ],
        ]$this->queryBuilder->getQueryPart('join'));
    }

    public function testVersionConstraintWithReferenceToNonVersionedEntity(): void
    {
        // Document and document type are not versioned, thus also document cannot have a versioned reference to its type         $documentDefinition = $this->definitionInstanceRegistry->get(DocumentDefinition::class);
        $documentTypeDefinition = $this->definitionInstanceRegistry->get(DocumentTypeDefinition::class);
        $documentAssociationField = $documentDefinition->getField('documentType');

        static::assertNotNull($documentAssociationField);
        $resolverContext = new FieldResolverContext(
            


    /** * @return int */
    public function fetchCount()
    {
        /** @var QueryBuilder $query */
        $query = clone $this->query;

        // Get first column for distinct selection         $select = $query->getQueryPart('select');

        $query->resetQueryPart('orderBy');
        $query->select('COUNT(DISTINCT ' . array_shift($select) . ')');

        return $query->execute()->fetch(PDO::FETCH_COLUMN);
    }

    /** * @deprecated in 5.6, will be removed in 5.8 without replacement * * @return QueryBuilder */
public function getOffset(): array
    {
        return ['offset' => $this->offset];
    }

    public function fetchCount(): int
    {
        $query = clone $this->query;

        // get first column for distinct selection         $select = $query->getQueryPart('select');

        $query->resetQueryPart('orderBy');
        $query->select('COUNT(DISTINCT ' . array_shift($select) . ')');

        return (int) $query->executeQuery()->fetchOne();
    }

    public function getQuery(): QueryBuilder
    {
        return $this->query;
    }
}
return new FilteredTagIdsStruct($ids$this->getTotal($query));
    }

    private function getIdsQuery(Criteria $criteria, Context $context): QueryBuilder
    {
        $query = new QueryBuilder($this->connection);

        $query = $this->criteriaQueryBuilder->build($query$this->tagDefinition, $criteria$context);

        /** @var array<string> $select */
        $select = array_merge(['LOWER(HEX(`tag`.`id`))']$query->getQueryPart('select'));
        $query->select($select);
        $query->addGroupBy('`tag`.`id`');
        $query->setMaxResults($criteria->getLimit());
        $query->setFirstResult($criteria->getOffset() ?? 0);

        return $query;
    }

    private function getTotal(QueryBuilder $query): int
    {
        $query->setMaxResults(null);
        
$this->query->setParameter('lastId', $this->lastId);

        return $data;
    }

    public function fetchCount(): int
    {
        $query = clone $this->query;

        // get first column for distinct selection         $select = $query->getQueryPart('select');

        $query->resetQueryPart('orderBy');
        $query->select('COUNT(DISTINCT ' . array_shift($select) . ')');

        return (int) $query->executeQuery()->fetchOne();
    }

    public function getQuery(): QueryBuilder
    {
        return $this->query;
    }

    
return $this->totalCount;
    }

    /** * Modifies the passed DBAL query builder object to calculate * the total count. * * @return $this */
    private function addTotalCountSelect(QueryBuilder $builder)
    {
        $select = $builder->getQueryPart('select');
        $select[0] = ' SQL_CALC_FOUND_ROWS ' . $select[0];
        $builder->select($select);

        return $this;
    }
}
$query = $this->criteriaQueryBuilder->build(
            $query,
            $association->getToManyReferenceDefinition(),
            $fieldCriteria,
            $context
        );

        $localColumn = EntityDefinitionQueryHelper::escape($association->getMappingLocalColumn());
        $referenceColumn = EntityDefinitionQueryHelper::escape($association->getMappingReferenceColumn());

        $orderBy = '';
        $parts = $query->getQueryPart('orderBy');
        if (!empty($parts)) {
            $orderBy = ' ORDER BY ' . implode(', ', $parts);
            $query->resetQueryPart('orderBy');
        }
        // order by is handled in group_concat         $fieldCriteria->resetSorting();

        $query->select([
            'LOWER(HEX(' . $root . '.' . $localColumn . ')) as `key`',
            'GROUP_CONCAT(LOWER(HEX(' . $root . '.' . $referenceColumn . ')) ' . $orderBy . ') as `value`',
        ]);

        
Home | Imprint | This part of the site doesn't use cookies.