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
+21-21Lines changed: 21 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -70,28 +70,28 @@ test('Processes array conditions after WHERE clause', function () use ($preproce
70
70
71
71
test('Handles IN operator with array values', function () use ($preprocessor) {
72
72
[$sql, $params] = $preprocessor->process(['SELECT id FROM author WHERE id IN (?)', [10, 11]]);
73
-
Assert::same('SELECT id FROM author WHERE id IN (?, ?)', $sql);
74
-
Assert::same([10, 11], $params);
73
+
Assert::same('SELECT id FROM author WHERE id IN (10, 11)', $sql);
74
+
Assert::same([], $params);
75
75
76
76
[$sql, $params] = $preprocessor->process(['SELECT id FROM author WHERE (id, name) IN (?)', [[10, 'a'], [11, 'b']]]);
77
-
Assert::same('SELECT id FROM author WHERE (id, name) IN ((?, ?), (?, ?))', $sql);
78
-
Assert::same([10, 'a', 11, 'b'], $params);
77
+
Assert::same('SELECT id FROM author WHERE (id, name) IN ((10, ?), (11, ?))', $sql);
78
+
Assert::same(['a', 'b'], $params);
79
79
80
80
[$sql, $params] = $preprocessor->process(['SELECT * FROM table WHERE ? AND id IN (?) AND ?', ['a' => 111], [3, 4], ['b' => 222]]);
81
-
Assert::same(reformat('SELECT * FROM table WHERE ([a] = ?) AND id IN (?, ?) AND ([b] = ?)'), $sql);
82
-
Assert::same([111, 3, 4, 222], $params);
81
+
Assert::same(reformat('SELECT * FROM table WHERE ([a] = ?) AND id IN (3, 4) AND ([b] = ?)'), $sql);
82
+
Assert::same([111, 222], $params);
83
83
84
84
[$sql, $params] = $preprocessor->process(['SELECT id FROM author WHERE id IN ?', [10, 11]]); // without ()
85
-
Assert::same('SELECT id FROM author WHERE id IN (?, ?)', $sql);
86
-
Assert::same([10, 11], $params);
85
+
Assert::same('SELECT id FROM author WHERE id IN (10, 11)', $sql);
86
+
Assert::same([], $params);
87
87
88
88
[$sql, $params] = $preprocessor->process(['SELECT id FROM author WHERE id IN (?)', 10]); // single item in ()
89
89
Assert::same('SELECT id FROM author WHERE id IN (?)', $sql);
90
90
Assert::same([10], $params);
91
91
92
92
[$sql, $params] = $preprocessor->process(['SELECT id FROM author WHERE id IN (?)', [10, 11]]); // array in ()
93
-
Assert::same('SELECT id FROM author WHERE id IN (?, ?)', $sql);
94
-
Assert::same([10, 11], $params);
93
+
Assert::same('SELECT id FROM author WHERE id IN (10, 11)', $sql);
94
+
Assert::same([], $params);
95
95
});
96
96
97
97
@@ -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 (1, 2)))'), $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 (1, 2)))'), $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] = (1, 2)))'), $sql);
157
157
});
158
158
159
159
@@ -256,8 +256,8 @@ test('multi-value IN conditions (tuples)', function () use ($preprocessor) {
256
256
[5, 6],
257
257
]]);
258
258
259
-
Assert::same(reformat('SELECT * FROM book_tag WHERE (book_id, tag_id) IN ((?, ?), (?, ?), (?, ?))'), $sql);
260
-
Assert::same([1, 2, 3, 4, 5, 6], $params);
259
+
Assert::same(reformat('SELECT * FROM book_tag WHERE (book_id, tag_id) IN ((1, 2), (3, 4), (5, 6))'), $sql);
260
+
Assert::same([], $params);
261
261
});
262
262
263
263
@@ -368,8 +368,8 @@ test('WHERE conditions with SQL literals', function () use ($preprocessor) {
368
368
'web' => newSqlLiteral('NOW()'),
369
369
]]);
370
370
371
-
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) AND ([born] IN (?, ?, 3+1)) AND ([web] = NOW()))'), $sql);
372
-
Assert::same([1, 2], $params);
371
+
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) AND ([born] IN (1, 2, 3+1)) AND ([web] = NOW()))'), $sql);
372
+
Assert::same([], $params);
373
373
});
374
374
375
375
@@ -387,8 +387,8 @@ test('AND operator in WHERE conditions', function () use ($preprocessor) {
387
387
'born' => [1, 2],
388
388
]]);
389
389
390
-
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) AND ([born] IN (?, ?)))'), $sql);
391
-
Assert::same([1, 2], $params);
390
+
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) AND ([born] IN (1, 2)))'), $sql);
391
+
Assert::same([], $params);
392
392
});
393
393
394
394
@@ -398,8 +398,8 @@ test('OR operator in WHERE conditions', function () use ($preprocessor) {
398
398
'born' => [1, 2],
399
399
]]);
400
400
401
-
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) OR ([born] IN (?, ?)))'), $sql);
402
-
Assert::same([1, 2], $params);
401
+
Assert::same(reformat('SELECT id FROM author WHERE (([id] IS NULL) OR ([born] IN (1, 2)))'), $sql);
0 commit comments