-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSqlParser.php
64 lines (52 loc) · 1.73 KB
/
SqlParser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Yiisoft\Db\Oracle;
use Yiisoft\Db\Syntax\AbstractSqlParser;
final class SqlParser extends AbstractSqlParser
{
public function getNextPlaceholder(int|null &$position = null): string|null
{
$result = null;
$length = $this->length - 1;
while ($this->position < $length) {
$pos = $this->position++;
match ($this->sql[$pos]) {
':' => ($word = $this->parseWord()) === ''
? $this->skipChars(':')
: $result = ':' . $word,
'"' => $this->skipToAfterChar('"'),
"'" => $this->skipQuotedWithoutEscape($this->sql[$pos]),
'q', 'Q' => $this->sql[$this->position] === "'"
? $this->skipQuotedWithQ()
: null,
'-' => $this->sql[$this->position] === '-'
? ++$this->position && $this->skipToAfterChar("\n")
: null,
'/' => $this->sql[$this->position] === '*'
? ++$this->position && $this->skipToAfterString('*/')
: null,
default => null,
};
if ($result !== null) {
$position = $pos;
return $result;
}
}
return null;
}
/**
* Skips quoted string with Q-operator.
*/
private function skipQuotedWithQ(): void
{
$endChar = match ($this->sql[++$this->position]) {
'[' => ']',
'<' => '>',
'{' => '}',
'(' => ')',
default => $this->sql[$this->position],
};
++$this->position;
$this->skipToAfterString("$endChar'");
}
}