-
Notifications
You must be signed in to change notification settings - Fork 5
/
Grammar.php
70 lines (57 loc) · 2 KB
/
Grammar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Laracache\Cache\Query\Grammars;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Grammars\SqlServerGrammar;
class Grammar extends SqlServerGrammar
{
protected function wrapValue($value)
{
return $value;
}
protected function compileAnsiOffset(Builder $query, $components)
{
if (!$query->limit) {
$query->limit = 'all';
}
if (empty($components['orders'])) {
$components['orders'] = 'order by 1';
}
$components['columns'] = $this->compileOver($this->columnize($query->columns));
$sql = $this->concatenate($components);
return $this->compileTableExpression($sql, $query);
}
protected function compileOver($orderings)
{
return "select top all {$orderings}";
}
protected function compileTableExpression($sql, $query)
{
$constraint = $this->compileRowConstraint($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)
);
}
}