-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
SQL Server syntax error after upgrade to Laravel 9 #45295
Comments
Thank you for reporting this issue! As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub. If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team. Thank you! |
According to the following lines, framework/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php Lines 40 to 42 in 9926399
Following changes may resolve this issue: if (! empty($components['orders'])) {
+ $fetchClause = $query->limit ? " fetch next {$query->limit} rows only" : '';
+
+ return parent::compileSelect($query)." offset {$query->offset} rows".$fetchClause;
- return parent::compileSelect($query)." offset {$query->offset} rows fetch next {$query->limit} rows only";
} However, this is already fixed/handled in a better way on Laravel 10 via #44937 |
Looks like this will be done better in Laravel v10. Thanks |
Illuminate\ Database\ QueryException SQL SERVER PHP 8.2.10 |
Description:
Code which worked prior to updrading to Laravel 9 is now producing an error when querying the database.
Steps To Reproduce:
In Laravel 8, this works as expected:
$posts = Post::Approved()->latest()->with('category', 'user')->where('inside_track', 0)->skip(4)->get()->groupBy('category_id')
The same code in Laravel 9 results in the following error:
SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near 'only'. (SQL: select * from [posts] where [approved_at] is not null and [inside_track] = 0 order by [created_at] desc offset 4 rows fetch next rows only)
Removing the
skip(4)
fixes the problem, but I need to skip the records.The text was updated successfully, but these errors were encountered: