4
4
5
5
use Illuminate \Database \Query \Builder ;
6
6
use Illuminate \Database \Query \Grammars \MySqlGrammar ;
7
+ use Illuminate \Support \Facades \Log ;
8
+ use Exception ;
7
9
8
10
class Grammar extends MySqlGrammar
9
11
{
10
12
public function compileOptions (array $ options ): string
11
13
{
12
14
$ optionString = '' ;
13
15
foreach ($ options as $ key => $ value ) {
14
- if (! empty ($ optionString )) {
16
+ if (!empty ($ optionString )) {
15
17
$ optionString .= ', ' ;
16
18
}
17
- $ optionString .= $ key. '= ' . $ value ;
19
+ $ optionString .= $ key . '= ' . $ value ;
18
20
}
19
21
20
22
return "OPTION ( {$ optionString }) " ;
21
23
}
22
24
25
+ public function compileDelete (Builder $ query )
26
+ {
27
+ if (isset ($ query ->orders )) {
28
+ if ($ query ->connection ->getConfig ('ignore_order_by_in_deletes ' )) {
29
+ if (env ('APP_ENV ' ) !== 'production ' ) {
30
+ Log::warning ('SingleStore does not support "order by" in a delete statement. The "order by" clause will be ignored. ' );
31
+ }
32
+ $ query ->orders = [];
33
+ } else {
34
+ throw new Exception ('SingleStore does not support "order by" in a delete statement. Use "ignore_order_by_in_deletes" configuration to ignore orderBy in delete operations. ' );
35
+ }
36
+ }
37
+
38
+ return parent ::compileDelete ($ query );
39
+ }
40
+
23
41
/**
24
42
* Compile a "where fulltext" clause.
25
43
*
@@ -81,7 +99,7 @@ protected function whereNull(Builder $query, $where)
81
99
if ($ this ->isJsonSelector ($ where ['column ' ])) {
82
100
[$ field , $ path ] = $ this ->wrapJsonFieldAndPath ($ where ['column ' ]);
83
101
84
- return '(JSON_EXTRACT_JSON( ' . $ field. $ path. ') IS NULL OR JSON_GET_TYPE(JSON_EXTRACT_JSON( ' . $ field. $ path. ')) = \'NULL \') ' ;
102
+ return '(JSON_EXTRACT_JSON( ' . $ field . $ path . ') IS NULL OR JSON_GET_TYPE(JSON_EXTRACT_JSON( ' . $ field . $ path . ')) = \'NULL \') ' ;
85
103
}
86
104
87
105
return parent ::whereNull ($ query , $ where );
@@ -92,7 +110,7 @@ protected function whereNotNull(Builder $query, $where)
92
110
if ($ this ->isJsonSelector ($ where ['column ' ])) {
93
111
[$ field , $ path ] = $ this ->wrapJsonFieldAndPath ($ where ['column ' ]);
94
112
95
- return '(JSON_EXTRACT_JSON( ' . $ field. $ path. ') IS NOT NULL AND JSON_GET_TYPE(JSON_EXTRACT_JSON( ' . $ field. $ path. ')) != \'NULL \') ' ;
113
+ return '(JSON_EXTRACT_JSON( ' . $ field . $ path . ') IS NOT NULL AND JSON_GET_TYPE(JSON_EXTRACT_JSON( ' . $ field . $ path . ')) != \'NULL \') ' ;
96
114
}
97
115
98
116
return parent ::whereNotNull ($ query , $ where );
@@ -103,7 +121,7 @@ protected function wrapJsonSelector($value)
103
121
// Break apart the column name from the JSON keypath.
104
122
[$ field , $ path ] = $ this ->wrapJsonFieldAndPath ($ value );
105
123
106
- if (! $ path ) {
124
+ if (!$ path ) {
107
125
return $ field ;
108
126
}
109
127
@@ -144,7 +162,7 @@ protected function wrapJsonFieldAndPath($column)
144
162
return "' $ part' " ;
145
163
}, $ parts );
146
164
147
- $ path = count ($ parts ) ? ', ' . implode (', ' , $ parts ) : '' ;
165
+ $ path = count ($ parts ) ? ', ' . implode (', ' , $ parts ) : '' ;
148
166
149
167
return [$ field , $ path ];
150
168
}
@@ -157,7 +175,7 @@ protected function wrapJsonFieldAndPath($column)
157
175
*/
158
176
protected function wrapUnion ($ sql )
159
177
{
160
- return 'SELECT * FROM ( ' . $ sql. ') ' ;
178
+ return 'SELECT * FROM ( ' . $ sql . ') ' ;
161
179
}
162
180
163
181
/**
@@ -185,7 +203,7 @@ protected function compileUnion(array $union)
185
203
{
186
204
$ conjunction = $ union ['all ' ] ? ' union all ' : ' union ' ;
187
205
188
- return $ conjunction. '( ' . $ union ['query ' ]->toSql (). ') ' ;
206
+ return $ conjunction . '( ' . $ union ['query ' ]->toSql () . ') ' ;
189
207
}
190
208
191
209
/**
@@ -203,19 +221,19 @@ public function compileSelect(Builder $query)
203
221
return ltrim ($ sql );
204
222
}
205
223
206
- if (! empty ($ query ->unionOrders ) || isset ($ query ->unionLimit ) || isset ($ query ->unionOffset )) {
207
- $ sql = 'SELECT * FROM ( ' . $ sql. ') ' ;
224
+ if (!empty ($ query ->unionOrders ) || isset ($ query ->unionLimit ) || isset ($ query ->unionOffset )) {
225
+ $ sql = 'SELECT * FROM ( ' . $ sql . ') ' ;
208
226
209
- if (! empty ($ query ->unionOrders )) {
210
- $ sql .= ' ' . $ this ->compileOrders ($ query , $ query ->unionOrders );
227
+ if (!empty ($ query ->unionOrders )) {
228
+ $ sql .= ' ' . $ this ->compileOrders ($ query , $ query ->unionOrders );
211
229
}
212
230
213
231
if (isset ($ query ->unionLimit )) {
214
- $ sql .= ' ' . $ this ->compileLimit ($ query , $ query ->unionLimit );
232
+ $ sql .= ' ' . $ this ->compileLimit ($ query , $ query ->unionLimit );
215
233
}
216
234
217
235
if (isset ($ query ->unionOffset )) {
218
- $ sql .= ' ' . $ this ->compileUnionOffset ($ query , $ query ->unionOffset );
236
+ $ sql .= ' ' . $ this ->compileUnionOffset ($ query , $ query ->unionOffset );
219
237
}
220
238
}
221
239
@@ -247,11 +265,11 @@ private function compileOffsetWithLimit($offset, $limit): string
247
265
{
248
266
// OFFSET is not valid without LIMIT
249
267
// Add a huge LIMIT clause
250
- if (! isset ($ limit )) {
268
+ if (!isset ($ limit )) {
251
269
// 9223372036854775807 - max 64-bit integer
252
- return ' LIMIT 9223372036854775807 OFFSET ' . (int ) $ offset ;
270
+ return ' LIMIT 9223372036854775807 OFFSET ' . (int ) $ offset ;
253
271
}
254
272
255
- return ' OFFSET ' . (int ) $ offset ;
273
+ return ' OFFSET ' . (int ) $ offset ;
256
274
}
257
275
}
0 commit comments