CONCAT with COUNT, SUM, - doctrine-orm

In a complex query, I have a subquery to count/summarize children:
->addSelect('(SELECT CONCAT(COUNT(c.id), \'|\', SUM(c.field1), \'|\', SUM(c.field2), \'|\', SUM(c.field3)) FROM App\Entity\Child c WHERE c.parent = p.id GROUP BY c.parent)')
This query worked perfectly until I upgraded to the new version of Symfony (4.2) and doctrine orm 2.6.1. I got the following error:
[Syntax Error] line 0, col 25: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got 'COUNT'
I tried to use CAST ... AS CHAR(25) but it doesn't work (got the same error).
Anyone can help me please?
Best regards,
Jonathan

Looks Like it is regression in doctrine StringPrimary parser function.
After looking at code I have made comment with my observation in issue related to this problem (while not entierly describing it).
Essentially new function missing this part, and defaulting to error when encountering any aggregate functions:
default:
if ($this->isAggregateFunction($lookaheadType)) {
return $this->AggregateExpression();
}
PS. link to the related issue:
https://github.com/doctrine/doctrine2/issues/7205

I found a workaround: I install doctrine extensions and I replace CONCAT by CONCAT_WS (DoctrineExtensions\Query\Mysql\ConcatWs).
Best regards

Related

PowerBI expression error using List.Genrate

I've been following some tutorial to handle pagination when calling an API limited to 100 records per request.
I'm using the latest version of PowerBI Desktop.
I have created a blank query and opened the Advanced Editor
let
allDeployments = List.Generate(
() => [result=GetDeployments(0), continuation=0],
each [continuation] <> null,
each [result=GetDeployments(GetNextContinuationToken(continuation)), continuation=GetNextContinuationToken(continuation)],
each [result])
in
allDeployments
and I get this error :
Expression.Error: The name 'continuation' wasn't recognized. Make sure it's spelled correctly.
I can't figure out what is the problem.
Do you have an idea ?
After a good night of sleep, I finally found the issue in my syntax.
I forgot some square brackets around "continuation" variable.
Here is the correct code:
let
allDeployments = List.Generate(
() => [result=GetDeployments(0), continuation=0],
each [continuation] <> null,
each [result=GetDeployments(GetNextContinuationToken([continuation])), continuation=GetNextContinuationToken([continuation])],
each [result])
in
allDeployments

How to check ramsey/uuid requirements with a regex?

I'm working on a symfony 5 project.
I use ramsey/uuid.
My doctrine.yaml
dbal:
types:
uuid: Ramsey\Uuid\Doctrine\UuidType
My route in my controller
/**
* #Route(
* "/job/{id}",
* name="job_show",
* methods={"GET"}
* )
*/
I would like to add the requirements to verify if the "id" parameter is a uuid.
I tried with several regex but none work :
Regex tried :
requirements={"id"="/^[a-f0-9]{8}\-[a-f0-9]{4}\-4[a-f0-9]{3}\-[a-f0-9]{4​}\-[a-f0-9]{12}$/"}
requirements={"id"="/^[a-f0-9\-]{36}$/"}
Every time I get this error:
No route found for "GET /job/dc5a945c-25a1-4760-bd69-970d94560cce"
I have watch severals similar questions like Searching for UUIDs in text with regex but none helped me.
Does anyone know where my error may come from or how to do it differently ?
You can use:
requirements={"id"="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"})

Doctrine2 loading DoctrineExtensions

I want to use the DAY() and YEAR() functions in my Doctrine2 query builder. But somehow I keep on getting errors:
Fatal error: Uncaught Doctrine\ORM\Query\QueryException: SELECT DAY(h.date) AS day FROM Entities\Hit h GROUP BY day in
PHP Code:
$totalHits = $this->registry->entityManager->getRepository('Entities\Hit')
->createQueryBuilder('h')
->select('DAY(h.date) AS day')
->groupBy('day')
->getQuery()->getResult();`
Loading the doctrineExtensions through composer or through the autoloader wouldn't fix it:
$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', __DIR__.'/../vendor/beberlei/DoctrineExtensions');
$classLoader->register();
Am I loading the DoctrineExtensions just wrongly or is there something else?
Fixed. Adding:
$entityManagerConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Sqlite\Year');
$entityManagerConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Sqlite\Month');
$entityManagerConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Sqlite\Day');
solved the problem

What is wrong with doctrine2 query builder - expected literal

I am using Doctrine 2 within ZF2 code and I am trying to write update query.
Code is like this:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->update('Application\Entity\Groups', 'group')
->set('group.state', '?1')
->set('group.modified', '?2')
->where($qb->expr()->eq('group.id', '?3'))
->setParameter(1, \Application\Entity\Groups::STATE_DELETED)
->setParameter(2, $modified)
->setParameter(3, $group_id);
Doctrine2 complains about query. Exact error message is:
(string) [Syntax Error] line 0, col 87: Error: Expected Literal, got 'group'
It seems that keyword group created problems. When I used gr alias instead of group it worked fine.
So, DQL bellow worked:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->update('Application\Entity\Groups', 'gr')
->set('gr.state', ':state')
->set('gr.modified', ':modified')
->where($qb->expr()->eq('gr.id', ':group_id'))
->setParameter('group_id', $group_id)
->setParameter('state', \Application\Entity\Groups::STATE_DELETED)
->setParameter('modified', $modified);

LLVM how to set Attributes::NoUnwind to Function?

I think this is very simple question, but I can't resolve it. Very sad.
So. When I do
llc.exe -march=cpp test.bc
I get interesting test.cpp with this piece of code:
AttrListPtr func__Z2f1i_PAL;
{
SmallVector<AttributeWithIndex, 4> Attrs;
AttributeWithIndex PAWI;
PAWI.Index = 4294967295U; PAWI.Attrs = Attribute::None | Attribute::NoUnwind;
Attrs.push_back(PAWI);
func__Z2f1i_PAL = AttrListPtr::get(Attrs.begin(), Attrs.end());
}
But when I want to write string like PAWI.Attrs = Attribute::None | Attribute::NoUnwind;
in my project, I got error IntelliSense: no operator "=" matches these operands operand types are: llvm::Attributes = int What I need to do?
All necessary headers included. [OS - Windows 7 x64, LLVM - 3.2]
I don't know why the cpp backend generates this code. In any case attribute handing was changed in 3.2 (and will change again in 3.3). The proper way to get an attribute in 3.2 should be:
Attributes::get(Context, Attributes::NoUnwind)
(you can always pass any ArrayRef here as the second argument, to initialize the attribute set with multiple values).
The simplest way to add an attribute to a function would be:
Function->addFnAttr(Attributes::NoUnwind)
And if you want an AttributeWithIndex:
AttributeWithIndex::get(Context, ID, Attributes::NoUnwind)
// OR:
AttributeWithIndex::get(ID, Attributes::get(Context, Attributes::NoUnwind))