Skip to content

fix: fix support for quoted alias #37

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

Merged
merged 3 commits into from
Feb 4, 2021
Merged

Conversation

Capo93
Copy link
Contributor

@Capo93 Capo93 commented May 6, 2020

Hi,
i found some issue with the support of quoted aliases.

CASE 1: multiple quoted alias

select a as `A A`, aa as `A AA` from b

Test result: OK
Select Item expected:

"selectItems": {
	"type": "SelectExpr",
	"value": [
		{
			"type": "Identifier",
			"value": "a",
			"alias": "`A A`",
			"hasAs": true
		},
		{
			"type": "Identifier",
			"value": "b",
			"alias": "`B B`",
			"hasAs": true
		}
	]
},

Received:

"selectItems": {
	"type": "SelectExpr",
	"value": [
		{
			"type": "Identifier",
			"value": "a",
			"alias": "`A A`, b as `B B`",
			"hasAs": true
		}
	]
},

The RegEx [`].+[`] match from first backquote to last backquote. The behavior should be from one backquote to the next. Same issue for next case.

CASE 2: quoted alias in orderBy

select a as `A A` from z order by `A A` desc
     Error: Parse error on line 1:
...om z order by `A A` desc
-----------------------^
Expecting 'EOF', ';', 'UNION', ')', ',', 'FROM', got 'DESC'

The 'a' alias in this case is: A A` from z order by `A A

--

I replace the ReqEx with this: ([`])(?:(?=(\\?))\2.)*?\1
And add quoted_identifier as Identifier (not as String) in expr.
The result in orderby:

"orderBy": {
	"type": "OroupBy",
	"value": [
		{
			"type": "GroupByOrderByItem",
			"value": {
				"type": "Identifier",
				"value": "`A A`"
			},
			"sortOpt": "DESC"
		}
	],
	"rollUp": null
},

Hope my fix are correct and helpfull!
Thanks a lot for this library:)!

@Capo93
Copy link
Contributor Author

Capo93 commented May 7, 2020

Also add support for double quote alias

        throw error;
        ^

Error: Parse error on line 1:
...ect customerName as "Customer Name" from 
-----------------------^

adding | AS STRING { $$ = {alias: $2, hasAs: true} } in selectExprAliasOpt

@albin3
Copy link
Member

albin3 commented May 8, 2020

hello @Capo93 , thanks for the pr!

I think it's better to merge identifier and quoted_ identifier into one symbol. Can you try this?

@Capo93
Copy link
Contributor Author

Capo93 commented May 12, 2020

I tried and it works. In last commit I merge quoted_identifier in identifier.

@albin3 albin3 added the bug label May 13, 2020
@albin3 albin3 merged commit 7f3b853 into JavaScriptor:master Feb 4, 2021
@albin3
Copy link
Member

albin3 commented Feb 8, 2021

hi @Capo93 , thanks for the pr. it's merged and released at 🎉 v1.4.1 🎉.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants