-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle arbitrary whitespaces when parsing SQL in order to apply LIMIT
for MS SQL Server
#2372
Conversation
@@ -115,12 +115,16 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) | |||
|
|||
// Queries using OFFSET... FETCH MUST have an ORDER BY clause | |||
// Find the position of the last instance of ORDER BY and ensure it is not within a parenthetical statement | |||
$orderByPos = strripos($query, " ORDER BY "); | |||
|
|||
if (preg_match_all('/\s+ORDER\s+BY\s+/i', $query, $matches, PREG_OFFSET_CAPTURE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why PREG_OFFSET_CAPTURE
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the line below. The $orderByPos
is obtained from the captured offset.
@morozov Does the test suite pass? Logic change looks fine to me but 😩 @ SQL Server... |
@zeroedin-bill I only ran the new test locally, while at the moment I submitted this PR, the whole build on Travis was far from stable. |
@morozov thanks! |
Decided to target this PR for |
… for MS SQL Server
2ca3884
to
81dd0b7
Compare
Rebased and resolved merge conflicts with #2428. |
This goes in! Thanks @morozov! |
LIMIT
for MS SQL Server
Given that the DBAL and QueryBuilder allow using plain SQL queries or their chunks, the DBAL should properly parse queries containing line breaks or other arbitrary formatting. Currently
SQLServerPlatform::doModifyLimitQuery()
(andSQLServer2012Platform::doModifyLimitQuery()
which is not released yet) produce invalid SQL in case if the original query contains line breaks or other whitespaces.