You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: tests/Database/SqlPreprocessor.phpt
+11-11
Original file line number
Diff line number
Diff line change
@@ -131,15 +131,15 @@ test('Auto-detects operator in WHERE conditions', function () use ($preprocessor
131
131
'col_arr' => [1, 2],
132
132
]]);
133
133
134
-
Assert::same(reformat('SELECT id FROM tbl WHERE ([col_null] IS NULL) AND ([x].[col_val] = ?) AND ([col_arr] IN (?, ?))'), $sql);
134
+
Assert::same(reformat('SELECT id FROM tbl WHERE (([col_null] IS NULL) AND ([x].[col_val] = ?) AND ([col_arr] IN (?, ?)))'), $sql);
135
135
136
136
[$sql, $params] = $preprocessor->process(['SELECT id FROM tbl WHERE', [
137
137
'col_null NOT' => null,
138
138
'x.col_val NOT' => 'a',
139
139
'col_arr NOT' => [1, 2],
140
140
]]);
141
141
142
-
Assert::same(reformat('SELECT id FROM tbl WHERE ([col_null] IS NOT NULL) AND ([x].[col_val] != ?) AND ([col_arr] NOT IN (?, ?))'), $sql);
142
+
Assert::same(reformat('SELECT id FROM tbl WHERE (([col_null] IS NOT NULL) AND ([x].[col_val] != ?) AND ([col_arr] NOT IN (?, ?)))'), $sql);
143
143
});
144
144
145
145
@@ -153,7 +153,7 @@ test('Supports explicit operators in WHERE conditions', function () use ($prepro
153
153
'col_arr =' => [1, 2],
154
154
]]);
155
155
156
-
Assert::same(reformat('SELECT id FROM tbl WHERE ([col_is] = ?) AND ([col_not] <> ?) AND ([col_like] LIKE ?) AND ([col_like] NOT LIKE ?) AND ([col_null] = NULL) AND ([col_arr] = (?, ?))'), $sql);
156
+
Assert::same(reformat('SELECT id FROM tbl WHERE (([col_is] = ?) AND ([col_not] <> ?) AND ([col_like] LIKE ?) AND ([col_like] NOT LIKE ?) AND ([col_null] = NULL) AND ([col_arr] = (?, ?)))'), $sql);
157
157
});
158
158
159
159
@@ -230,14 +230,14 @@ test('WHERE conditions with indexed items', function () use ($preprocessor) {
230
230
'foo',
231
231
'bar',
232
232
]]);
233
-
Assert::same(reformat('SELECT id FROM tbl WHERE (?) AND (?)'), $sql);
233
+
Assert::same(reformat('SELECT id FROM tbl WHERE ((?) AND (?))'), $sql);
234
234
Assert::same(['foo', 'bar'], $params); // not useful
235
235
});
236
236
237
237
238
238
test('Combines WHERE conditions with array & direct SQL', function () use ($preprocessor) {
239
239
[$sql, $params] = $preprocessor->process(['SELECT id FROM tbl WHERE id=?', 10, 'AND ?and', ['c1' => null, 'c2' => 2], 'AND ?or', ['c3' => null, 'c4' => 4]]);
240
-
Assert::same(reformat('SELECT id FROM tbl WHERE id=? AND ([c1] IS NULL) AND ([c2] = ?) AND ([c3] IS NULL) OR ([c4] = ?)'), $sql);// is not properly clamped
240
+
Assert::same(reformat('SELECT id FROM tbl WHERE id=? AND (([c1] IS NULL) AND ([c2] = ?)) AND (([c3] IS NULL) OR ([c4] = ?))'), $sql);
241
241
Assert::same([10, 2, 4], $params);
242
242
});
243
243
@@ -284,7 +284,7 @@ test('WHERE conditions with ORDER BY', function () use ($preprocessor) {
284
284
'name' => false,
285
285
]]);
286
286
287
-
Assert::same(reformat('SELECT id FROM author WHERE ([id] = ?) AND ([web] = ?) ORDER BY [name] DESC'), $sql);
287
+
Assert::same(reformat('SELECT id FROM author WHERE (([id] = ?) AND ([web] = ?)) ORDER BY [name] DESC'), $sql);
288
288
Assert::same([1, 'web'], $params);
289
289
});
290
290
@@ -361,7 +361,7 @@ test('WHERE conditions with SQL literals', function () use ($preprocessor) {
361
361
'web' => newSqlLiteral('NOW()'),
362
362
]]);
363
363
364
-
Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([born] IN (?, ?, 3+1)) AND ([web] = NOW())'), $sql);
364
+
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) AND ([born] IN (?, ?, 3+1)) AND ([web] = NOW()))'), $sql);
365
365
Assert::same([1, 2], $params);
366
366
});
367
367
@@ -380,7 +380,7 @@ test('AND operator in WHERE conditions', function () use ($preprocessor) {
380
380
'born' => [1, 2],
381
381
]]);
382
382
383
-
Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) AND ([born] IN (?, ?))'), $sql);
383
+
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) AND ([born] IN (?, ?)))'), $sql);
384
384
Assert::same([1, 2], $params);
385
385
});
386
386
@@ -391,7 +391,7 @@ test('OR operator in WHERE conditions', function () use ($preprocessor) {
391
391
'born' => [1, 2],
392
392
]]);
393
393
394
-
Assert::same(reformat('SELECT id FROM author WHERE ([id] IS NULL) OR ([born] IN (?, ?))'), $sql);
394
+
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) OR ([born] IN (?, ?)))'), $sql);
395
395
Assert::same([1, 2], $params);
396
396
});
397
397
@@ -616,7 +616,7 @@ test('nested SQL literals with special placeholders', function () use ($preproce
616
616
newSqlLiteral('max > ?', [10]),
617
617
newSqlLiteral('min < ?', [20]),
618
618
]]);
619
-
Assert::same(reformat('SELECT id FROM author WHERE (max > ?) OR (min < ?)'), $sql);
619
+
Assert::same(reformat('SELECT id FROM author WHERE ((max > ?) OR (min < ?))'), $sql);
620
620
Assert::same([10, 20], $params);
621
621
});
622
622
@@ -626,7 +626,7 @@ test('complex nested conditions with SQL literals', function () use ($preprocess
626
626
newSqlLiteral('?and', [['a' => 1, 'b' => 2]]),
627
627
newSqlLiteral('?and', [['c' => 3, 'd' => 4]]),
628
628
]])]);
629
-
Assert::same(reformat('SELECT id FROM author WHERE (([a] = ?) AND ([b] = ?)) OR (([c] = ?) AND ([d] = ?))'), $sql);
629
+
Assert::same(reformat('SELECT id FROM author WHERE (((([a] = ?) AND ([b] = ?))) OR ((([c] = ?) AND ([d] = ?))))'), $sql);
0 commit comments