Skip to content


Subversion checkout URL

You can clone with
Download ZIP


[DBAL-497] Fixed SQL Server platform replacing 'FROM' in column names during limit #306

merged 1 commit into from

4 participants


The regex used to replace the FROM clause was in a "starts with" form, which also matched column names that start with the word "FROM". This resulted in column names being replaced with the logic used for limiting, breaking the query once pagination is used. I added a whitespace requirement after "FROM' in the regex as well as a trailing whitespace in the replacement.



thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

We use Jira to track the state of pull requests and the versions they got
included in.

@guilhermeblanco guilhermeblanco merged commit 10be52a into doctrine:master

1 check failed

Details default The Travis build failed

Added a test for this, but couldn't merge it into 2.3 because the code changed so much in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
2  lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
@@ -845,7 +845,7 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
//Replace only first occurrence of FROM with $over to prevent changing FROM also in subqueries.
- $query = preg_replace('/\sFROM/i', ", ROW_NUMBER() OVER ($over) AS doctrine_rownum FROM", $query, 1);
+ $query = preg_replace('/\sFROM\s/i', ", ROW_NUMBER() OVER ($over) AS doctrine_rownum FROM ", $query, 1);
$start = $offset + 1;
$end = $offset + $limit;
Something went wrong with that request. Please try again.