|
1 |
| -<?php namespace Uepg\LaravelSybase\Database\Query; |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Uepg\LaravelSybase\Database\Query; |
2 | 4 |
|
3 | 5 | use Illuminate\Database\Query\Builder;
|
4 | 6 | use Illuminate\Database\Query\Grammars\Grammar;
|
5 | 7 |
|
6 | 8 | class SybaseGrammar extends Grammar {
|
| 9 | + /** |
| 10 | + * All of the available clause operators. |
| 11 | + * |
| 12 | + * @var array |
| 13 | + */ |
| 14 | + protected $operators = [ |
| 15 | + '=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=', |
| 16 | + 'like', 'not like', 'between', 'ilike', |
| 17 | + '&', '&=', '|', '|=', '^', '^=', |
| 18 | + ]; |
| 19 | + |
| 20 | + protected $builder; |
| 21 | + |
| 22 | + public function getBuilder(){ |
| 23 | + return $this->builder; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Compile a select query into SQL. |
| 28 | + * |
| 29 | + * @param \Illuminate\Database\Query\Builder |
| 30 | + * @return string |
| 31 | + */ |
| 32 | + public function compileSelect(Builder $query) |
| 33 | + { |
| 34 | + $this->builder = $query; |
| 35 | + $components = $this->compileComponents($query); |
| 36 | + |
| 37 | + return $this->concatenate($components); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Compile the "select *" portion of the query. |
| 42 | + * |
| 43 | + * @param \Illuminate\Database\Query\Builder $query |
| 44 | + * @param array $columns |
| 45 | + * @return string |
| 46 | + */ |
| 47 | + protected function compileColumns(Builder $query, $columns) |
| 48 | + { |
| 49 | + if (!is_null($query->aggregate)) { |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + $select = $query->distinct ? 'select distinct ' : 'select '; |
| 54 | + |
| 55 | + // If there is a limit on the query, but not an offset, we will add the |
| 56 | + // top clause to the query, which serves as a "limit" type clause |
| 57 | + // within the SQL Server system similar to the limit keywords available |
| 58 | + // in MySQL. |
| 59 | + if ($query->limit > 0 && $query->offset <= 0) { |
| 60 | + $select .= 'top ' . $query->limit . ' '; |
| 61 | + } |
| 62 | + |
| 63 | + return $select . $this->columnize($columns); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Compile the "from" portion of the query. |
| 68 | + * |
| 69 | + * @param \Illuminate\Database\Query\Builder $query |
| 70 | + * @param string $table |
| 71 | + * @return string |
| 72 | + */ |
| 73 | + protected function compileFrom(Builder $query, $table) |
| 74 | + { |
| 75 | + $from = parent::compileFrom($query, $table); |
| 76 | + |
| 77 | + if (is_string($query->lock)) { |
| 78 | + return $from . ' ' . $query->lock; |
| 79 | + } |
| 80 | + |
| 81 | + if (!is_null($query->lock)) { |
| 82 | + return $from . ' with(rowlock,' . |
| 83 | + ($query->lock ? 'updlock,' : '') . 'holdlock)'; |
| 84 | + } |
7 | 85 |
|
8 |
| - /** |
9 |
| - * All of the available clause operators. |
10 |
| - * |
11 |
| - * @var array |
12 |
| - */ |
13 |
| - protected $operators = array( |
14 |
| - '=', '<', '>', '<=', '>=', '!<', '!>', '<>', '!=', |
15 |
| - 'like', 'not like', 'between', 'ilike', |
16 |
| - '&', '&=', '|', '|=', '^', '^=', |
17 |
| - ); |
18 |
| - |
19 |
| - protected $Builder; |
20 |
| - public function getBuilder(){ |
21 |
| - return $this->Builder; |
| 86 | + return $from; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Compile the "limit" portions of the query. |
| 91 | + * |
| 92 | + * @param \Illuminate\Database\Query\Builder $query |
| 93 | + * @param int $limit |
| 94 | + * @return string |
| 95 | + */ |
| 96 | + protected function compileLimit(Builder $query, $limit) |
| 97 | + { |
| 98 | + return ''; |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Compile the "offset" portions of the query. |
| 103 | + * |
| 104 | + * @param \Illuminate\Database\Query\Builder $query |
| 105 | + * @param int $offset |
| 106 | + * @return string |
| 107 | + */ |
| 108 | + protected function compileOffset(Builder $query, $offset) |
| 109 | + { |
| 110 | + return ''; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Compile a truncate table statement into SQL. |
| 115 | + * |
| 116 | + * @param \Illuminate\Database\Query\Builder $query |
| 117 | + * @return array |
| 118 | + */ |
| 119 | + public function compileTruncate(Builder $query) |
| 120 | + { |
| 121 | + return [ |
| 122 | + 'truncate table ' . $this->wrapTable($query->from) => array() |
| 123 | + ]; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Get the format for database stored dates. |
| 128 | + * |
| 129 | + * @return string |
| 130 | + */ |
| 131 | + public function getDateFormat() |
| 132 | + { |
| 133 | + return 'Y-m-d H:i:s.000'; |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Wrap a single string in keyword identifiers. |
| 138 | + * |
| 139 | + * @param string $value |
| 140 | + * @return string |
| 141 | + */ |
| 142 | + protected function wrapValue($value) |
| 143 | + { |
| 144 | + if ($value === '*') { |
| 145 | + return $value; |
22 | 146 | }
|
23 |
| - |
24 |
| - |
25 |
| - /** |
26 |
| - * Compile a select query into SQL. |
27 |
| - * |
28 |
| - * @param \Illuminate\Database\Query\Builder |
29 |
| - * @return string |
30 |
| - */ |
31 |
| - |
32 |
| - public function compileSelect(Builder $query) |
33 |
| - { |
34 |
| - $this->Builder = $query; |
35 |
| - $components = $this->compileComponents($query); |
36 |
| - |
37 |
| - return $this->concatenate($components); |
38 |
| - } |
39 |
| - /** |
40 |
| - * Compile the "select *" portion of the query. |
41 |
| - * |
42 |
| - * @param \Illuminate\Database\Query\Builder $query |
43 |
| - * @param array $columns |
44 |
| - * @return string |
45 |
| - */ |
46 |
| - protected function compileColumns(Builder $query, $columns) |
47 |
| - { |
48 |
| - if ( ! is_null($query->aggregate)) return; |
49 |
| - |
50 |
| - $select = $query->distinct ? 'select distinct ' : 'select '; |
51 |
| - |
52 |
| - // If there is a limit on the query, but not an offset, we will add the top |
53 |
| - // clause to the query, which serves as a "limit" type clause within the |
54 |
| - // SQL Server system similar to the limit keywords available in MySQL. |
55 |
| - if ($query->limit > 0 && $query->offset <= 0) |
56 |
| - { |
57 |
| - $select .= 'top '.$query->limit.' '; |
58 |
| - } |
59 |
| - |
60 |
| - return $select.$this->columnize($columns); |
61 |
| - } |
62 |
| - |
63 |
| - /** |
64 |
| - * Compile the "from" portion of the query. |
65 |
| - * |
66 |
| - * @param \Illuminate\Database\Query\Builder $query |
67 |
| - * @param string $table |
68 |
| - * @return string |
69 |
| - */ |
70 |
| - protected function compileFrom(Builder $query, $table) |
71 |
| - { |
72 |
| - $from = parent::compileFrom($query, $table); |
73 |
| - |
74 |
| - if (is_string($query->lock)) return $from.' '.$query->lock; |
75 |
| - |
76 |
| - if ( ! is_null($query->lock)) |
77 |
| - { |
78 |
| - return $from.' with(rowlock,'.($query->lock ? 'updlock,' : '').'holdlock)'; |
79 |
| - } |
80 |
| - |
81 |
| - return $from; |
82 |
| - } |
83 |
| - |
84 |
| - /** |
85 |
| - * Compile the "limit" portions of the query. |
86 |
| - * |
87 |
| - * @param \Illuminate\Database\Query\Builder $query |
88 |
| - * @param int $limit |
89 |
| - * @return string |
90 |
| - */ |
91 |
| - protected function compileLimit(Builder $query, $limit) |
92 |
| - { |
93 |
| - return ''; |
94 |
| - } |
95 |
| - |
96 |
| - /** |
97 |
| - * Compile the "offset" portions of the query. |
98 |
| - * |
99 |
| - * @param \Illuminate\Database\Query\Builder $query |
100 |
| - * @param int $offset |
101 |
| - * @return string |
102 |
| - */ |
103 |
| - protected function compileOffset(Builder $query, $offset) |
104 |
| - { |
105 |
| - return ''; |
106 |
| - } |
107 |
| - |
108 |
| - /** |
109 |
| - * Compile a truncate table statement into SQL. |
110 |
| - * |
111 |
| - * @param \Illuminate\Database\Query\Builder $query |
112 |
| - * @return array |
113 |
| - */ |
114 |
| - public function compileTruncate(Builder $query) |
115 |
| - { |
116 |
| - return array('truncate table '.$this->wrapTable($query->from) => array()); |
117 |
| - } |
118 |
| - |
119 |
| - /** |
120 |
| - * Get the format for database stored dates. |
121 |
| - * |
122 |
| - * @return string |
123 |
| - */ |
124 |
| - public function getDateFormat() |
125 |
| - { |
126 |
| - return 'Y-m-d H:i:s.000'; |
127 |
| - } |
128 |
| - |
129 |
| - /** |
130 |
| - * Wrap a single string in keyword identifiers. |
131 |
| - * |
132 |
| - * @param string $value |
133 |
| - * @return string |
134 |
| - */ |
135 |
| - protected function wrapValue($value) |
136 |
| - { |
137 |
| - if ($value === '*') return $value; |
138 |
| - |
139 |
| - return '['.str_replace(']', ']]', $value).']'; |
140 |
| - } |
141 | 147 |
|
| 148 | + return '[' . str_replace(']', ']]', $value) . ']'; |
| 149 | + } |
142 | 150 | }
|
0 commit comments