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: docs/param-modifiers.md
+26-2Lines changed: 26 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ Other available modifiers:
53
53
|`%%`| escapes to single `%` (useful in `date_format()`, etc.) |
54
54
|`[[`, `]]`| escapes to single `[` or `]` (useful when working with array, etc.) |
55
55
56
-
Let's examine `%and` and `%or` behavior. If array key is numeric and its value is an array, value is expanded with `%ex` modifier. (See below.)
56
+
Let's examine `%and` and `%or` behavior. If an array key is numeric and its value is an array, value is expanded with `%ex` modifier. If the first value it this array is an `Fqn` instance, the resulted SQL is constructed similarly to a key-value array, the modifier is an optional string on the second index. (See below.)
If you want select multiple rows with combined condition for each row, you may use multi-column `IN` expression. However, some databases do not support this feature, therefore Dbal provides universal `%multiOr` modifier that will handle this for you and will use alternative expanded verbose syntax. MultiOr modifier supports optional modifier appended to the column name, set it for all entries. Let's see an example:
86
+
If you want to select multiple rows with combined condition for each row, you may use multi-column `IN` expression. However, some databases do not support this feature, therefore, Dbal provides universal `%multiOr` modifier that will handle this for you and will use alternative expanded verbose syntax. MultiOr modifier supports optional modifier appended to the column name; it has to be set for all entries. Let's see an example:
// (tag_id = 1 AND book_id = 23) OR (tag_id = 4 AND book_id = 12) OR (tag_id = 9 AND book_id = 83)
93
99
```
94
100
101
+
Alternatively, if you need to pass the column name as `Fqn` instance, use a data format where the array consists of list columns, then the list of values and optional list of modifiers.
102
+
103
+
```php
104
+
$aFqn = new Fqn('tbl', 'tag_id');
105
+
$bFqn = new Fqn('tbl', 'book_id');
106
+
$connection->query('%multiOr', [
107
+
[[$aFqn, 1, '%i'], [$bFqn, 23]],
108
+
[[$aFqn, 4, '%i'], [$bFqn, 12]],
109
+
[[$aFqn, 9, '%i'], [$bFqn, 83]],
110
+
]);
111
+
112
+
// MySQL or PostgreSQL
113
+
// (tbl.tag_id, tbl.book_id) IN ((1, 23), (4, 12), (9, 83))
114
+
115
+
// SQL Server
116
+
// (tbl.tag_id = 1 AND tbl.book_id = 23) OR (tbl.tag_id = 4 AND tbl.book_id = 12) OR (tbl.tag_id = 9 AND tbl.book_id = 83)
0 commit comments