Skip to content

Commit 56d39cf

Browse files
committed
Special-cased =? operator to be excluded from parameter parser.
Restored capturing groups in parameter parser regex.
1 parent 25ca9ee commit 56d39cf

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Internal/functions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
|
1212
# Unnamed parameters.
1313
(
14-
\$(?:\d+)
14+
\$(\d+)
1515
|
1616
# Match all question marks except those surrounded by "operator"-class characters on either side.
17-
(?<!(?<operators>[-+\\*/<>=~!@#%^&|`?]))
17+
(?<!(?<operators>[-+\\*/<>~!@#%^&|`?]))
1818
\?
19-
(?!\g<operators>)
19+
(?!\g<operators>|=)
2020
)
2121
|
2222
# Named parameters.
23-
(?<!:):(?:[a-zA-Z_][a-zA-Z0-9_]*)
23+
(?<!:):([a-zA-Z_][a-zA-Z0-9_]*)
2424
]msxS
2525
REGEX;
2626

@@ -37,7 +37,7 @@ function parseNamedParams(string $sql, ?array &$names): string
3737
static $index = 0, $unnamed = 0, $numbered = 1;
3838

3939
if (isset($matches[4])) {
40-
$names[$index] = $matches[4];
40+
$names[$index] = $matches[5];
4141
} elseif ($matches[2] === '?') {
4242
$names[$index] = $unnamed++;
4343
} else {

test/InternalFunctionsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public function provideUnnamedParams(): iterable
2525
'Bare' => ['SELECT ?', 'SELECT $1'],
2626
'Parenthesized' => ['SELECT (?)', 'SELECT ($1)'],
2727
'Row constructor' => ['SELECT (?, ?)', 'SELECT ($1, $2)'],
28+
// Special-case exclude the =? operator to permit the following usage.
29+
'=? operator' => ['UPDATE foo SET bar=?', 'UPDATE foo SET bar=$1']
2830
];
2931
}
3032

0 commit comments

Comments
 (0)