1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Staudenmeir\LaravelAdjacencyList\Query\Grammars; |
4
|
|
|
|
5
|
|
|
use HarryGulliford\Firebird\Query\Grammars\FirebirdGrammar as Base; |
6
|
|
|
use Illuminate\Database\Query\Builder; |
7
|
|
|
|
8
|
|
|
class FirebirdGrammar extends Base implements ExpressionGrammar |
9
|
|
|
{ |
10
|
|
|
use OrdersByPath; |
11
|
|
|
|
12
|
|
|
public function compileInitialPath($column, $alias) |
13
|
|
|
{ |
14
|
|
|
return 'cast(' . $this->wrap($column) . ' as varchar(8191)) as ' . $this->wrap($alias); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function compileRecursivePath($column, $alias, bool $reverse = false) |
18
|
|
|
{ |
19
|
|
|
$wrappedColumn = $this->wrap($column); |
20
|
|
|
$wrappedAlias = $this->wrap($alias); |
21
|
|
|
$placeholder = 'cast(? as varchar(8191))'; |
22
|
|
|
|
23
|
|
|
return $reverse ? "($wrappedColumn || $placeholder || $wrappedAlias)" : "($wrappedAlias || $placeholder || $wrappedColumn)"; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getRecursivePathBindings($separator) |
27
|
|
|
{ |
28
|
|
|
return [$separator]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function selectPathList(Builder $query, $expression, $column, $pathSeparator, $listSeparator) |
32
|
|
|
{ |
33
|
|
|
return $query->selectRaw( |
34
|
|
|
'list(' . $this->wrap($column) . ", '$listSeparator')" |
35
|
|
|
)->from($expression); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function compilePivotColumnNullValue(string $type, int $precision, int $scale): string |
39
|
|
|
{ |
40
|
|
|
return 'null'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function compileCycleDetection(string $localKey, string $path): string |
44
|
|
|
{ |
45
|
|
|
$localKey = $this->wrap($localKey); |
46
|
|
|
$path = $this->wrap($path); |
47
|
|
|
|
48
|
|
|
return "position($localKey || ?, $path) > 0 or position(? || $localKey || ?, $path) > 0"; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getCycleDetectionBindings(string $pathSeparator): array |
52
|
|
|
{ |
53
|
|
|
return [$pathSeparator, $pathSeparator, $pathSeparator]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function compileCycleDetectionInitialSelect(string $column): string |
57
|
|
|
{ |
58
|
|
|
return 'false as ' . $this->wrap($column); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function compileCycleDetectionRecursiveSelect(string $sql, string $column): string |
62
|
|
|
{ |
63
|
|
|
return $sql; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function compileCycleDetectionStopConstraint(string $column): string |
67
|
|
|
{ |
68
|
|
|
return 'not ' . $this->wrap($column); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function supportsUnionInRecursiveExpression(): bool |
72
|
|
|
{ |
73
|
|
|
return false; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|