From 8d76130f6b3138ec94604605b9557ce9cb5ae04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robson=20Ten=C3=B3rio?= Date: Wed, 2 Feb 2022 15:30:27 -0300 Subject: [PATCH] Backport `compileSelect` This is a compatible method that usually worked with old version of SqlServerGramar. This PR introduced a braking change, once Laravel now supports only SQLServer 2017+ https://github.com/laravel/framework/pull/39863 (see changed files). Just copied over old method, before PR merged. --- src/Cache/Query/Grammars/Grammar.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Cache/Query/Grammars/Grammar.php b/src/Cache/Query/Grammars/Grammar.php index bf269d3..f1e300b 100644 --- a/src/Cache/Query/Grammars/Grammar.php +++ b/src/Cache/Query/Grammars/Grammar.php @@ -39,4 +39,32 @@ protected function compileTableExpression($sql, $query) return "select *, %vid from ({$sql}) where %vid {$constraint}"; } + + + /** + * This is a compatible method that usually worked with old version of SqlServerGramar. + * + * This PR introduced a braking change, once Laravel now supports only SQLServer 2017+ + * https://github.com/laravel/framework/pull/39863 (see changed files) + * + * Just copied over old method, before Laravel PR got merged. + * + */ + public function compileSelect(Builder $query) + { + if (! $query->offset) { + return parent::compileSelect($query); + } + + // If an offset is present on the query, we will need to wrap the query in + // a big "ANSI" offset syntax block. This is very nasty compared to the + // other database systems but is necessary for implementing features. + if (is_null($query->columns)) { + $query->columns = ['*']; + } + + return $this->compileAnsiOffset( + $query, $this->compileComponents($query) + ); + } }