Skip to content

Commit 0515846

Browse files
committed
Merge #442 - Fix #372 - re-implement CALL statements parsing
Pull-request: #442 Fixes: #372 Signed-off-by: William Desportes <[email protected]>
2 parents b0fe7a6 + 41ad592 commit 0515846

5 files changed

Lines changed: 15 additions & 33 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@ parameters:
170170
count: 1
171171
path: src/Components/ExpressionArray.php
172172

173-
-
174-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\:\\:\\$name \\(string\\|null\\) does not accept mixed\\.$#"
175-
count: 1
176-
path: src/Components/FunctionCall.php
177-
178173
-
179174
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\FunctionCall\\:\\:\\$parameters \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\.$#"
180175
count: 1
@@ -560,11 +555,6 @@ parameters:
560555
count: 1
561556
path: src/Parser.php
562557

563-
-
564-
message: "#^Cannot access property \\$type on PhpMyAdmin\\\\SqlParser\\\\Token\\|null\\.$#"
565-
count: 1
566-
path: src/Statement.php
567-
568558
-
569559
message: "#^Offset 'class' does not exist on array\\{class\\?\\: string, field\\?\\: non\\-empty\\-string, options\\?\\: array\\<string, string\\>\\}\\.$#"
570560
count: 1

psalm-baseline.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@
203203
</RedundantCondition>
204204
</file>
205205
<file src="src/Components/FunctionCall.php">
206-
<MixedAssignment occurrences="1">
207-
<code>$ret-&gt;name</code>
208-
</MixedAssignment>
206+
<MixedOperand occurrences="1">
207+
<code>$token-&gt;value</code>
208+
</MixedOperand>
209209
<MoreSpecificImplementedParamType occurrences="1">
210210
<code>$component</code>
211211
</MoreSpecificImplementedParamType>
@@ -879,9 +879,6 @@
879879
<MixedOperand occurrences="1">
880880
<code>$class::build($this-&gt;$field)</code>
881881
</MixedOperand>
882-
<PossiblyNullPropertyFetch occurrences="1">
883-
<code>$list-&gt;offsetGet($list-&gt;idx)-&gt;type</code>
884-
</PossiblyNullPropertyFetch>
885882
<PossiblyUndefinedArrayOffset occurrences="4">
886883
<code>Parser::$KEYWORD_PARSERS[$name]['class']</code>
887884
<code>Parser::$KEYWORD_PARSERS[$name]['field']</code>

src/Components/FunctionCall.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
7878

7979
// End of statement.
8080
if ($token->type === Token::TYPE_DELIMITER) {
81+
--$list->idx; // Let last token to previous one to avoid "This type of clause was previously parsed."
8182
break;
8283
}
8384

@@ -87,13 +88,15 @@ public static function parse(Parser $parser, TokensList $list, array $options =
8788
}
8889

8990
if ($state === 0) {
90-
$ret->name = $token->value;
91-
$state = 1;
92-
} elseif ($state === 1) {
93-
if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) {
94-
$ret->parameters = ArrayObj::parse($parser, $list);
91+
if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') {
92+
--$list->idx; // ArrayObj needs to start with `(`
93+
$state = 1;
94+
continue;// do not add this token to the name
9595
}
9696

97+
$ret->name .= $token->value;
98+
} elseif ($state === 1) {
99+
$ret->parameters = ArrayObj::parse($parser, $list);
97100
break;
98101
}
99102
}

src/Statement.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace PhpMyAdmin\SqlParser;
66

7-
use PhpMyAdmin\SqlParser\Components\FunctionCall;
87
use PhpMyAdmin\SqlParser\Components\OptionsArray;
98
use Stringable;
109

@@ -415,13 +414,6 @@ public function parse(Parser $parser, TokensList $list)
415414
}
416415

417416
$this->after($parser, $list, $token);
418-
419-
// #223 Here may make a patch, if last is delimiter, back one
420-
if ($class !== FunctionCall::class || $list->offsetGet($list->idx)->type !== Token::TYPE_DELIMITER) {
421-
continue;
422-
}
423-
424-
--$list->idx;
425417
}
426418

427419
// This may be corrected by the parser.

tests/Builder/CallStatementTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testBuilderShort(): void
3131

3232
public function testBuilderWithDbName(): void
3333
{
34-
$query = 'CALL foo()';
34+
$query = 'CALL mydb.foo()';
3535

3636
$parser = new Parser($query);
3737
$stmt = $parser->statements[0];
@@ -41,7 +41,7 @@ public function testBuilderWithDbName(): void
4141

4242
public function testBuilderWithDbNameShort(): void
4343
{
44-
$query = 'CALL foo';
44+
$query = 'CALL mydb.foo';
4545

4646
$parser = new Parser($query);
4747
$stmt = $parser->statements[0];
@@ -51,12 +51,12 @@ public function testBuilderWithDbNameShort(): void
5151

5252
public function testBuilderWithDbNameAndParams(): void
5353
{
54-
$query = 'CALL foo(@bar, @baz);';
54+
$query = 'CALL mydb.foo(@bar, @baz);';
5555

5656
$parser = new Parser($query);
5757
$stmt = $parser->statements[0];
5858

59-
$this->assertEquals('CALL foo(@bar,@baz)', $stmt->build());
59+
$this->assertEquals('CALL mydb.foo(@bar,@baz)', $stmt->build());
6060
}
6161

6262
public function testBuilderMultiCallsShort(): void

0 commit comments

Comments
 (0)