Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the additional body tokens issue when create view statements #371

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Statements/CreateStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ public function parse(Parser $parser, TokensList $list)
if ($list->tokens[$nextidx]->value === 'SELECT') {
$list->idx = $nextidx;
$this->select = new SelectStatement($parser, $list);
++$list->idx; // Skipping last token from the select.
} elseif ($list->tokens[$nextidx]->value === 'WITH') {
++$list->idx;
$this->with = new WithStatement($parser, $list);
Expand Down
27 changes: 27 additions & 0 deletions tests/Builder/CreateStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,33 @@ public function testBuilderView(): void
'SELECT id, first_name, FROMzz employee WHERE id = 2 ',
$stmt->build()
);

$parser = new Parser('CREATE VIEW `view_programlevelpartner` AS SELECT `p`.`country_id`'
. 'AS `country_id` FROM `program_level_partner` `p` ORDER BY `p`.`id` asc');
$stmt = $parser->statements[0];
$this->assertEquals(
'CREATE VIEW `view_programlevelpartner` AS SELECT `p`.`country_id`'
. ' AS `country_id` FROM `program_level_partner` AS `p` ORDER BY `p`.`id` ASC ',
$stmt->build()
);

$parser = new Parser('CREATE VIEW `view_zg_bycountry` AS '
. 'SELECT `d`.`zg_id` FROM `view_zg_value` AS `d` GROUP BY `d`.`ind_id`;');
$stmt = $parser->statements[0];
$this->assertEquals(
'CREATE VIEW `view_zg_bycountry` AS '
. 'SELECT `d`.`zg_id` FROM `view_zg_value` AS `d` GROUP BY `d`.`ind_id` ',
$stmt->build()
);

$parser = new Parser('CREATE view view_name AS WITH aa(col1)'
. ' AS ( SELECT 1 UNION ALL SELECT 2 ) SELECT col1 FROM cte AS `d` ');
$stmt = $parser->statements[0];
$this->assertEquals(
'CREATE view view_name AS WITH aa(col1)'
. ' AS (SELECT 1 UNION ALL SELECT 2) SELECT col1 FROM cte AS `d` ',
$stmt->build()
);
}

public function testBuilderViewComplex(): void
Expand Down
6 changes: 1 addition & 5 deletions tests/data/parser/parseCreateView.out
Original file line number Diff line number Diff line change
Expand Up @@ -3534,11 +3534,7 @@
"table": null,
"return": null,
"parameters": null,
"body": [
{
"@type": "@286"
}
],
"body": [],
"CLAUSES": [],
"END_OPTIONS": [],
"options": {
Expand Down
3 changes: 0 additions & 3 deletions tests/data/parser/parseCreateView3.out
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,6 @@
"return": null,
"parameters": null,
"body": [
{
"@type": "@28"
},
{
"@type": "@29"
},
Expand Down
6 changes: 1 addition & 5 deletions tests/data/parser/parseCreateViewWithQuotes.out
Original file line number Diff line number Diff line change
Expand Up @@ -1223,11 +1223,7 @@
"table": null,
"return": null,
"parameters": null,
"body": [
{
"@type": "@43"
}
],
"body": [],
"CLAUSES": [],
"END_OPTIONS": [],
"options": {
Expand Down
3 changes: 0 additions & 3 deletions tests/data/parser/parseCreateViewWithUnion.out
Original file line number Diff line number Diff line change
Expand Up @@ -1266,9 +1266,6 @@
"return": null,
"parameters": null,
"body": [
{
"@type": "@27"
},
{
"@type": "@28"
},
Expand Down
6 changes: 1 addition & 5 deletions tests/data/parser/parseCreateViewWithWrongSyntax.out
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,7 @@
"table": null,
"return": null,
"parameters": null,
"body": [
{
"@type": "@20"
}
],
"body": [],
"CLAUSES": [],
"END_OPTIONS": [],
"options": {
Expand Down
6 changes: 1 addition & 5 deletions tests/data/parser/parseCreateViewWithoutQuotes.out
Original file line number Diff line number Diff line change
Expand Up @@ -1232,11 +1232,7 @@
"table": null,
"return": null,
"parameters": null,
"body": [
{
"@type": "@44"
}
],
"body": [],
"CLAUSES": [],
"END_OPTIONS": [],
"options": {
Expand Down