Jira issue originally created by user mklocke:
I'm trying to create a DQL query like that:
SELECT Task.id AS id, Task.date AS date, (
FROM Project\Entity\Position p
) AS poscount
FROM Project\Entity\Task Task
WHERE Task.id <> 0 AND Task.status < 3
ORDER BY Task.date DESC
This works flawlessly on MSSQL until i try to apply a LIMIT/OFFSET by using setFirstResult() and setMaxResults().
Applying a Limit results in an invoke of "doModifyLimitQuery()" in "Doctrine\DBAL\Platforms\SQLServerPlatform".
The function implementation clearly states what's wrong:
//Replace only first occurrence of FROM with $over to prevent changing FROM also in subqueries.
$over = 'ORDER BY ' . implode(', ', $overColumns);
$query = preg*replace('/\sFROM\s/i', ", ROW_NUMBER() OVER ($over) AS doctrine*rownum FROM ", $query, 1);
This breaks support with subqueries in SELECT statements.
Comment created by @deeky666:
Yeah this seems to be indeed wrong. This method is going one step forward and one step back with each adjustment :( I don't feel comfortable trying to fix that one as it is really sensitive. But you are welcome to provide a patch for this on github :) (or someone else).
Comment created by tomdrissen:
I ran into this bug today, which is really annoying. Is there any change this will be fixed shortly?
How about checking parenthesises to determine the 'base' FROM/table?
Patch supplied in PR: #512
Comment created by @doctrinebot:
A related Github Pull-Request [GH-512] was closed:
Fixed in commit: c4d4c5f
Issue was closed with resolution "Fixed"
Comment created by mklocke:
The usage of preg_replace() in this bugfix can cause Apache to abort the PHP execution because of a stack overflow.
Apache's default value for "ThreadStackSize" on Windows is 1MB. This is not sufficient if you use preg_replace() on long queries.
I had to increase the size to 8MB.
This should be mentioned somewhere.
Comment created by @ocramius:
[~mklocke] how long is the query with which you are experiencing this? I'd say it's more a PHP bug than problem of the DBAL
That might be an issue of using recursion in the regular expression maybe. I'm not sure if that is known limitation of PHP. But it seems weird to me you have to adjust apache config instead of PHP for this.
My Query is 1275 characters long.
It's not a bug at all, just a misconfiguration in Apache. But it's really hard to debug this problem, because Apache just kills PHP and doesn't say a word about it. So it would be kind to document this somewhere, so that new Doctrine Users can configure their Apache correctly.