Skip to content

fix: fix support for quoted alias - #37

Merged
albin3 merged 3 commits into
JavaScriptor:masterfrom
Capo93:master
Feb 4, 2021
Merged

fix: fix support for quoted alias#37
albin3 merged 3 commits into
JavaScriptor:masterfrom
Capo93:master

Conversation

@Capo93

@Capo93 Capo93 commented May 6, 2020

Copy link
Copy Markdown
Contributor

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

Capo93 commented May 7, 2020

Copy link
Copy Markdown
Contributor Author

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

albin3 commented May 8, 2020

Copy link
Copy Markdown
Member

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

Capo93 commented May 12, 2020

Copy link
Copy Markdown
Contributor Author

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

albin3 commented Feb 8, 2021

Copy link
Copy Markdown
Member

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