★ wanayoo — archive 1999 https://github.com/JavaScriptor/js-sql-parser/pull/37Nouvelle recherche | Portail wanayoo
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

fix: fix support for quoted alias #37

Open
wants to merge 3 commits into
base: master
from
Open

Conversation

@Capo93
Copy link

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
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.