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
|`%multiOr`| OR condition with multiple conditions in pairs |
47
-
|`%values`, `%values[]`| expands array for INSERT clause, multi insert |
48
-
|`%set`| expands array for SET clause |
49
-
|`%table`, `%table[]`| escapes string as table name, may contain a database or schema name separated by a dot; surrounding parentheses are not added to `%table[]` modifier; `%table` supports also processing a `Nextras\Dbal\Platforms\Data\Fqn` instance. |
50
-
|`%column`, `%column[]`| escapes string as column name, may contain a database name, schema name or asterisk (`*`) separated by a dot; surrounding parentheses are not added to `%column[]` modifier; |
51
-
|`%ex`| expands array as processor arguments |
52
-
|`%raw`| inserts string argument as is |
53
-
|`%%`| escapes to single `%` (useful in `date_format()`, etc.) |
54
-
|`[[`, `]]`| escapes to single `[` or `]` (useful when working with array, etc.) |
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.)
|`%multiOr`| OR condition with multiple conditions in pairs |
47
+
|`%values`, `%values[]`| expands array for INSERT clause, multi insert |
48
+
|`%set`| expands array for SET clause |
49
+
|`%table`, `%table[]`| escapes string as table name, may contain a database or schema name separated by a dot; surrounding parentheses are not added to `%table[]` modifier; `%table` supports formatting a `Nextras\Dbal\Platforms\Data\Fqn` instance.|
50
+
|`%column`, `%column[]`| escapes string as column name, may contain a database name, schema name or asterisk (`*`) separated by a dot; surrounding parentheses are not added to `%column[]` modifier; `%table` supports formatting a `Nextras\Dbal\Platforms\Data\Fqn` instance.|
51
+
|`%ex`| expands array as processor arguments |
52
+
|`%raw`| inserts string argument as is |
53
+
|`%%`| escapes to single `%` (useful in `date_format()`, etc.) |
54
+
|`[[`, `]]`| escapes to single `[` or `]` (useful when working with array, etc.) |
55
+
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