@param string $dql
@param array  $parameters

@throws \LogicException

@return AttributeQueryBuilderInterface
773569
public function rawDQL($dql, array $parameters = [])
    {
        if (null !== $this->dql) {
            throw new \LogicException("Condition as already been applied {$this->dql}");
        }

        $this->dql = $dql;
        $this->parameters = $parameters;

        return $this;
    }
670654
public function sendQueryWithParameters($query, array $parameters = [])
    {
        $res = pg_send_query_params(
            $this->getHandler(),
            $query,
            $parameters
        );

        try {
            return $this
                ->testQuery($res, $query)
                ->getQueryResult($query)
                ;
        } catch (SqlException $e) {
            throw $e->setQueryParameters($parameters);
        }
    }
1122602
public function query(string $sql, array $bindings = []): IQueryBuilderHandler
    {
        $queryObject = new QueryObject($sql, $bindings, $this->getConnection());
        $this->connection->setLastQuery($queryObject);

        $this->fireEvents(EventHandler::EVENT_BEFORE_QUERY, $queryObject);

        [$response, $executionTime] = $this->statement($queryObject->getSql(), $queryObject->getBindings());

        $this->fireEvents(EventHandler::EVENT_AFTER_QUERY, $queryObject, [
            'execution_time' => $executionTime,
        ]);

        $this->pdoStatement = $response;

        return $this;
    }
591997
public function addParameters(Parameter ...$parameters): MutableQuery
    {
        $cloned = clone $this;

        $activeParameters = iterator_to_array($this->parameters);
        $activeParameters = array_merge($activeParameters, $parameters);

        $cloned->parameters = new ParameterCollection(...$activeParameters);

        return $cloned;
    }
805134
public function applyJoin()
    {
        if ($this->skipJoin) {
            return $this;
        }
        $attributeCode = $this->attribute->getCode();
        if ($this->joinApplied) {
            throw new \LogicException("Join for attribute query builder {$attributeCode} already applied");
        }
        $qb = $this->eavQueryBuilder->getQueryBuilder();

        // Join based on attributeCode
        $attributeParameter = $this->generateUniqueId('attribute');
        $qb->setParameter($attributeParameter, $attributeCode);
        $joinDql = "{$this->joinAlias}.attributeCode = :{$attributeParameter}";

        if ($this->enforceFamilyCondition) {
            $family = $this->attribute->getFamily();
            if (!$family) {
                throw new MissingFamilyException("Unable to resolve family for attribute {$attributeCode}");
            }
            $familyParameter = $this->generateUniqueId('family');
            $qb->setParameter($familyParameter, $family->getCode());
            $joinDql .= " AND {$this->joinAlias}.familyCode = :{$familyParameter}";
        }

        if ($this->context) {
            /** @var ContextualValueInterface $valueClass */
            $valueClass = $this->attribute->getFamily()->getValueClass();
            if (!is_a($valueClass, ContextualValueInterface::class, true)) {
                throw new ContextException('Unable to filter by context on a non-contextual value class');
            }
            foreach ($this->context as $axis => $axisValues) {
                if (!\in_array($axis, $valueClass::getContextKeys(), true)) {
                    throw new ContextException("Trying to filter on invalid axis '{$axis}'");
                }
                if (!\in_array($axis, $this->attribute->getContextMask(), true)) {
                    continue;
                }
                $axisValueParameter = $this->generateUniqueId($axis.'Axis');
                $joinDql .= " AND {$this->joinAlias}.{$axis}";
                if (is_array($axisValues)) {
                    $joinDql .= " IN (:{$axisValueParameter})";
                } else {
                    $joinDql .= " = :{$axisValueParameter}";
                }
                $qb->setParameter($axisValueParameter, $axisValues);
            }
        }

        $qb->leftJoin(
            $this->eavQueryBuilder->getAlias().'.values',
            $this->joinAlias,
            Join::WITH,
            $joinDql
        );

        if ($this->joinRelation) {
            $qb->leftJoin(
                $this->joinAlias.'.'.$this->attribute->getType()->getDatabaseType(),
                $this->joinRelation
            );
        }

        $this->joinApplied = true;

        return $this;
    }
986509
public function findOrCreate($criteria, $parameters = null)
    {
        if ($criteria instanceof Bag) {
            $criteria = $criteria->toArray();
        }

        if ($parameters === null) {
            $parameters = $criteria;
        }

        $parameters = $this->castParameters($parameters);
        $entity = $this->getRepository()->findOneBy($criteria);

        if ($entity == null) {
            return $this->create($parameters);
        }

        $result = new Result();
        $result->getResources()->push($entity);

        return $result;
    }
930349
public function executeStatement($statementQuery, array $parameters) {
		$statement = $this->connection->prepare($statementQuery);
		foreach ($parameters as $parameterName => $parameterValue) {
			$statement->bindValue($parameterName, $parameterValue);
		}

		$result = $statement->execute();
		$resultArray = array();
		while ($resultRow = $result->fetchArray(SQLITE3_ASSOC)) {
			$resultArray[] = $resultRow;
		}

		return $resultArray;
	}
605696
public function query($query, $parameters = [])
    {
        try {
            $statement = $this->handle->prepare($query, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
            $statement->execute($parameters);
            return new DatabaseStatement($statement);
        } catch (\PDOException $e) {
            throw new DatabaseException('Error while preparing query « ' . $query . ' » (' .
                $e->getMessage() . ')', $query);
        }
    }
1077467
public function create($queryType, $queryParams = [])
    {
        if (!isset($this->factories[$queryType])) {
            throw new \LogicException("No factory found for query of type {$queryType}");
        }

        return $this->factories[$queryType]->create($queryParams);
    }
752120
private function checkQueryResourceId(array $parameters, string $type): void
    {
        if (!$this->resourceId && $parameters['resource_id']) {
            throw new \InvalidArgumentException(\sprintf(
                'Trying to query with a resource ID, but the repository %s does not provide support for them',
                $this->name
            ));
        }
        if (self::ENDPOINT_SINGLE === $type && !$parameters['resource_id']) {
            throw new \InvalidArgumentException(\sprintf(
                'Trying to query a single element without providing a resource ID for repository %s',
                $this->name
            ));
        }
        if (self::ENPOINT_COLLECTION === $type && $parameters['resource_id']) {
            throw new \InvalidArgumentException(\sprintf(
                'Trying to query a collection element by providing a resource ID for repository %s',
                $this->name
            ));
        }
    }
1075442
public function handleData(QueryHandlerInterface $queryHandler, FilterInterface $filter, $data): void
    {
        if (!$queryHandler instanceof EAVQueryHandlerInterface) {
            throw new BadQueryHandlerException($queryHandler, EAVQueryHandlerInterface::class);
        }
        if (!$queryHandler->isEAVFilter($filter)) {
            $this->fallbackFilterType->handleData($queryHandler, $filter, $data);

            return;
        }
        if ($this->isEmpty($data)) {
            return;
        }

        $eavQb = new EAVQueryBuilder($queryHandler->getQueryBuilder(), $queryHandler->getAlias());
        $eavQb->setContext($queryHandler->getQueryContext());
        $dqlHandlers = [];
        foreach ($filter->getAttributes() as $attributePath) {
            $attributeQb = $queryHandler->getEAVAttributeQueryBuilder($eavQb, $attributePath);
            $dqlHandlers[] = $this->applyAttributeQueryBuilder($attributeQb, $data);
        }

        if (0 < \count($dqlHandlers)) {
            $eavQb->apply($eavQb->getOr($dqlHandlers));
        }
    }
1167672
public function query($pQuery, array $pParams = array())
    {
        $this->_stm = Agl::app()->getDb()->getConnection()->prepare($pQuery);

        if (! $this->_stm->execute($pParams)) {
            $error = $this->_stm->errorInfo();
            throw new Exception("The query failed with message '" . $error[2] . "'");
        }

        if (Agl::app()->isDebugMode()) {
            Agl::app()->getDb()->incrementCounter();
        }

        return $this->_stm->fetchAll(PDO::FETCH_ASSOC);
    }
151613
public function getNamedQuery($queryName)
    {
        if ( ! isset($this->namedQueries[$queryName])) {
            throw MappingException::queryNotFound($this->name, $queryName);
        }
        return $this->namedQueries[$queryName]['dql'];
    }
1131155
private function convertParameters(array $parameters, $type, \DOMElement $parent, $keyAttribute = 'key')
    {
        $withKeys = array_keys($parameters) !== range(0, count($parameters) - 1);
        foreach ($parameters as $key => $value) {
            $element = $this->document->createElement($type);
            if ($withKeys) {
                $element->setAttribute($keyAttribute, $key);
            }

            if ($value instanceof ServiceClosureArgument) {
                $value = $value->getValues()[0];
            }
            if (is_array($value)) {
                $element->setAttribute('type', 'collection');
                $this->convertParameters($value, $type, $element, 'key');
            } elseif ($value instanceof TaggedIteratorArgument) {
                $element->setAttribute('type', 'tagged');
                $element->setAttribute('tag', $value->getTag());
            } elseif ($value instanceof IteratorArgument) {
                $element->setAttribute('type', 'iterator');
                $this->convertParameters($value->getValues(), $type, $element, 'key');
            } elseif ($value instanceof Reference) {
                $element->setAttribute('type', 'service');
                $element->setAttribute('id', (string) $value);
                $behaviour = $value->getInvalidBehavior();
                if (ContainerInterface::NULL_ON_INVALID_REFERENCE == $behaviour) {
                    $element->setAttribute('on-invalid', 'null');
                } elseif (ContainerInterface::IGNORE_ON_INVALID_REFERENCE == $behaviour) {
                    $element->setAttribute('on-invalid', 'ignore');
                } elseif (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE == $behaviour) {
                    $element->setAttribute('on-invalid', 'ignore_uninitialized');
                }
            } elseif ($value instanceof Definition) {
                $element->setAttribute('type', 'service');
                $this->addService($value, null, $element);
            } elseif ($value instanceof Expression) {
                $element->setAttribute('type', 'expression');
                $text = $this->document->createTextNode(self::phpToXml((string) $value));
                $element->appendChild($text);
            } else {
                if (in_array($value, array('null', 'true', 'false'), true)) {
                    $element->setAttribute('type', 'string');
                }
                $text = $this->document->createTextNode(self::phpToXml($value));
                $element->appendChild($text);
            }
            $parent->appendChild($element);
        }
    }
479298
protected function _authenticateQueryDql(\Doctrine\ORM\Query $dqlQuery)
    {
        try {
            $resultIdentities = $dqlQuery->getResult();
        } catch (\Exception $e) {
            throw new \Zend_Auth_Adapter_Exception('The supplied parameters to Extlib\Auth\Adapter\Doctrine2 failed to '
                . 'produce a valid sql statement, please check table and column names '
                . 'for validity.', 0, $e);
        }

        return $resultIdentities;
    }
804699
public function modify(QueryBuilder $queryBuilder, $dqlAlias)
    {
        $paramName = $this->generateParameterName($queryBuilder);
        $queryBuilder->setParameter($paramName, $this->value);

        return (string) new DoctrineComparison(
            $this->createPropertyWithAlias($dqlAlias),
            $this->operator,
            sprintf(':%s', $paramName)
        );
    }
1277103
public function buildQuery(QueryBuilder $qb, array $parameters)
    {
        $emConfig = $this->getEntityManager()->getConfiguration();
        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
        $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
        $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');

        if (isset($parameters['year'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND YEAR(main_item.publishedAt) = :year')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND YEAR(main_item.createdAt) = :year')
                ->orWhere('main_item.status = :article_status_published AND YEAR(main_item.publishedAt) = :year')
                ->setParameter('year', $parameters['year'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }
        if (isset($parameters['month'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND MONTH(main_item.publishedAt) = :month')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND MONTH(main_item.createdAt) = :month')
                ->orWhere('main_item.status = :article_status_published AND MONTH(main_item.publishedAt) = :month')
                ->setParameter('month', $parameters['month'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }
        if (isset($parameters['day'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND DAY(main_item.publishedAt) = :day')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND DAY(main_item.createdAt) = :day')
                ->orWhere('main_item.status = :article_status_published AND DAY(main_item.publishedAt) = :day')
                ->setParameter('day', $parameters['day'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }

        return $qb;
    }