Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4200a15

Browse files
Merge branch 'master' into add-place-holder-support
2 parents 6503d59 + 09b15e4 commit 4200a15

File tree

5 files changed

+61
-40
lines changed

5 files changed

+61
-40
lines changed

‎CHANGELOG‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
1.2.1 fix stringify having #29 , pr: #28
99
1.2.2 feat: add support for "`" quoted alias, pr: #33
1010
1.3.0 fix tableFactor alias bug. AST changed in tableFactor. #34
11+
1.4.0 fix bug `using ' & " for column alias?` #40 #44
12+
1.4.1 hogfix "support quoted alias: multiple alias and orderby support"

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sql grammar follows https://dev.mysql.com/doc/refman/5.7/en/select.html
1010

1111
## news
1212

13+
- Fix bug `using ' & " for column alias?` since v1.4.1 [#40](https://github.com/JavaScriptor/js-sql-parser/issues/40), [#44](https://github.com/JavaScriptor/js-sql-parser/issues/44)
1314
- Fix bug tableFactor alias since v1.3.0 [#34](https://github.com/JavaScriptor/js-sql-parser/issues/34)
1415
- Add support for "`" quoted alias since v1.2.2. [#33](https://github.com/JavaScriptor/js-sql-parser/issues/33)
1516
- Fix bug stringify keyword `having` since v1.2.1. [#29](https://github.com/JavaScriptor/js-sql-parser/issues/29)

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-sql-parser",
3-
"version": "1.3.0",
3+
"version": "1.4.1",
44
"description": "",
55
"main": "./dist/parser/sqlParser.js",
66
"scripts": {

‎src/sqlParser.jison‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ UNION return 'UNION'
127127

128128
[a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]* return 'IDENTIFIER'
129129
\. return 'DOT'
130-
['"][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*["'] return 'QUOTED_IDENTIFIER'
131-
[`].+[`] return 'QUOTED_IDENTIFIER'
130+
["][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*["] return 'STRING'
131+
['][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*['] return 'STRING'
132+
([`])(?:(?=(\\?))2円.)*?1円 return 'IDENTIFIER'
132133

133134
<<EOF>> return 'EOF'
134135
. return 'INVALID'
@@ -281,13 +282,11 @@ selectExprAliasOpt
281282
: { $$ = {alias: null, hasAs: null} }
282283
| AS IDENTIFIER { $$ = {alias: 2ドル, hasAs: true} }
283284
| IDENTIFIER { $$ = {alias: 1ドル, hasAs: false} }
284-
| AS QUOTED_IDENTIFIER { $$ = {alias: 2ドル, hasAs: true} }
285-
| QUOTED_IDENTIFIER { $$ = {alias: $1, hasAs: false} }
285+
| AS STRING { $$ = {alias: 2ドル, hasAs: true} }
286+
| STRING { $$ = {alias: $2, hasAs: false} }
286287
;
287-
288288
string
289-
: QUOTED_IDENTIFIER { $$ = { type: 'String', value: 1ドル } }
290-
| STRING { $$ = { type: 'String', value: 1ドル } }
289+
: STRING { $$ = { type: 'String', value: 1ドル } }
291290
;
292291
number
293292
: NUMERIC { $$ = { type: 'Number', value: 1ドル } }

‎test/main.test.js‎

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const debug = require('debug')('js-sql-parser');
44
const parser = require('../');
55

6-
const testParser = function(sql) {
6+
const testParser = function(sql) {
77
let firstAst = parser.parse(sql);
88
debug(JSON.stringify(firstAst, null, 2));
99
let firstSql = parser.stringify(firstAst);
@@ -22,24 +22,24 @@ const testParser = function(sql) {
2222
return secondAst;
2323
};
2424

25-
describe('select grammar support', function() {
26-
it('test0', function() {
25+
describe('select grammar support', function() {
26+
it('test0', function() {
2727
testParser('select a from b where c > 1 group by d order by e desc;');
2828
});
2929

30-
it('test1', function() {
30+
it('test1', function() {
3131
testParser('select distinct max_statement_time = 1.2 a ');
3232
});
3333

34-
it('test2', function() {
34+
it('test2', function() {
3535
testParser('select all 0x1f');
3636
});
3737

38-
it('test3', function() {
38+
it('test3', function() {
3939
testParser('select distinctrow "xx", a in (1,2)');
4040
});
4141

42-
it('test4', function() {
42+
it('test4', function() {
4343
testParser(`
4444
select
4545
tag_basic.gender as gender,
@@ -58,17 +58,17 @@ describe('select grammar support', function() {
5858
`);
5959
});
6060

61-
it('test5', function() {
61+
it('test5', function() {
6262
testParser('select function(), function(1, "sd", 0x1F)');
6363
});
6464

65-
it('test6 unicode', function() {
65+
it('test6 unicode', function() {
6666
testParser(`
6767
select in中文 from tags
6868
`);
6969
});
7070

71-
it('test7', function() {
71+
it('test7', function() {
7272
testParser(`
7373
SELECT
7474
DISTINCT high_priority MAX_STATEMENT_TIME=1 STRAIGHT_JOIN SQL_SMALL_RESULT SQL_BIG_RESULT SQL_BUFFER_RESULT SQL_CACHE SQL_CALC_FOUND_ROWS fm_customer.lname AS name1,
@@ -89,7 +89,7 @@ describe('select grammar support', function() {
8989
`);
9090
});
9191

92-
it('test8', function() {
92+
it('test8', function() {
9393
testParser(`
9494
SELECT P1.PAYMENTNO, P1.AMOUNT,
9595
(P1.AMOUNT * 100) / SUM(P2.AMOUNT)
@@ -99,7 +99,7 @@ describe('select grammar support', function() {
9999
`);
100100
});
101101

102-
it('test9', function() {
102+
it('test9', function() {
103103
testParser(`
104104
SELECT PLAYERS.PLAYERNO, NAME,
105105
(SELECT COUNT(*)
@@ -114,7 +114,7 @@ describe('select grammar support', function() {
114114
`);
115115
});
116116

117-
it('test10', function() {
117+
it('test10', function() {
118118
testParser(`
119119
SELECT rd.*, rd.rd_numberofrooms - (
120120
SELECT SUM(rn.reservation_numberofrooms) AS count_reserve_room
@@ -148,11 +148,11 @@ describe('select grammar support', function() {
148148
`);
149149
});
150150

151-
it('test11 SELECT `LEFT`(a, 3) FROM b support.', function() {
151+
it('test11 SELECT `LEFT`(a, 3) FROM b support.', function() {
152152
testParser('SELECT `LEFT`(a, 3) FROM b');
153153
});
154154

155-
it('test12', function() {
155+
it('test12', function() {
156156
testParser(`
157157
select
158158
a.product_id,
@@ -202,7 +202,7 @@ describe('select grammar support', function() {
202202
`);
203203
});
204204

205-
it('test13', function() {
205+
it('test13', function() {
206206
testParser(`
207207
SELECT
208208
a.*, f.ORG_NAME DEPT_NAME,
@@ -286,7 +286,7 @@ describe('select grammar support', function() {
286286
`);
287287
});
288288

289-
it('test14', function() {
289+
it('test14', function() {
290290
testParser(`
291291
SELECT
292292
k.*,
@@ -345,7 +345,7 @@ describe('select grammar support', function() {
345345
`);
346346
});
347347

348-
it('test15', function() {
348+
it('test15', function() {
349349
testParser(`
350350
SELECT P1.PAYMENTNO, P1.AMOUNT, (P1.AMOUNT * 100) / SUM(P2.AMOUNT)
351351
FROM PENALTIES AS P1, PENALTIES AS P2
@@ -354,41 +354,41 @@ describe('select grammar support', function() {
354354
`);
355355
});
356356

357-
it('limit support.', function() {
357+
it('limit support.', function() {
358358
testParser('select a from b limit 2, 3');
359359
});
360360

361-
it('fix not equal.', function() {
361+
it('fix not equal.', function() {
362362
testParser('select a from b where a <> 1 limit 2, 3');
363363
});
364364

365-
it('restore semicolon.', function() {
365+
it('restore semicolon.', function() {
366366
testParser('select a from b limit 2;');
367367
});
368368

369-
it('recognoce alias for sql-function calls in stringify function.', function() {
369+
it('recognoce alias for sql-function calls in stringify function.', function() {
370370
testParser('SELECT COUNT(*) AS total, a b, b as c, c/2 d, d & e an FROM b');
371371
});
372372

373-
it('union support, https://dev.mysql.com/doc/refman/8.0/en/union.html', function() {
373+
it('union support, https://dev.mysql.com/doc/refman/8.0/en/union.html', function() {
374374
testParser('select a from dual union select a from foo;');
375375
});
376376

377-
it('union Parenthesized support, https://dev.mysql.com/doc/refman/8.0/en/union.html', function() {
377+
it('union Parenthesized support, https://dev.mysql.com/doc/refman/8.0/en/union.html', function() {
378378
testParser('(select a from dual) union (select a from foo) order by a desc limit 100, 100;');
379379
});
380380

381-
it('union all support, https://dev.mysql.com/doc/refman/8.0/en/union.html', function() {
381+
it('union all support, https://dev.mysql.com/doc/refman/8.0/en/union.html', function() {
382382
testParser('(select a from dual) union all (select a from foo) order by a limit 100');
383383
});
384384

385-
it('union distinct support, https://dev.mysql.com/doc/refman/8.0/en/union.html', function() {
385+
it('union distinct support, https://dev.mysql.com/doc/refman/8.0/en/union.html', function() {
386386
testParser(
387387
'select a from dual order by a desc limit 1, 1 union distinct select a from foo order by a limit 1'
388388
);
389389
});
390390

391-
it('support quoted alias', function() {
391+
it('support quoted alias', function() {
392392
testParser('select a as `A-A` from b limit 2;');
393393
testParser('select a as `A#A` from b limit 2;');
394394
testParser('select a as `A?A` from b limit 2;');
@@ -398,7 +398,7 @@ describe('select grammar support', function() {
398398
testParser('select a as `A A` from b limit 2;');
399399
});
400400

401-
it('bugfix table alias', function() {
401+
it('bugfix table alias', function() {
402402
testParser(`
403403
SELECT stime, A.names, B.names FROM (
404404
SELECT stime, names FROM iaas_data.iaas_d3c0d0681cc1900
@@ -408,13 +408,32 @@ describe('select grammar support', function() {
408408
`);
409409
});
410410

411-
it('bugfix table alias2', function() {
411+
it('bugfix table alias2', function() {
412412
testParser('select a.* from a t1 join b t2 on t1.a = t2.a')
413-
})
414-
413+
});
415414
it('place holder support', function() {
416415
testParser(
417416
"select sum(quota_value) value, busi_col2 as sh, ${a} as a, YEAR(now()) from der_quota_summary where table_ename = 'gshmyyszje_derivedidx' and cd = (select id from t1 where a = ${t1})"
418417
)
419-
})
418+
});
419+
420+
it('support quoted alias: multiple alias and orderby support', function () {
421+
testParser('select a as `A A`, b as `B B` from z');
422+
testParser('select a as `A A` from z order by `A A` desc');
423+
testParser('select a as `A A`, b as `B B` from z group by `A A`, `B B` order by `A A` desc');
424+
});
425+
426+
it('support double quoted alias', function () {
427+
testParser('select a as "A A" from z');
428+
testParser('select a as "A A" from z order by "A A" desc');
429+
});
430+
431+
it('support quoted alias', function () {
432+
testParser('select a as \'A A\' from z');
433+
testParser('select a as \'"A#A\' from z order by \'"A#A\' desc');
434+
});
435+
436+
it('test IDENTIFIER', function () {
437+
testParser('select `aa#sfs`(a) as \'A A\' from z');
438+
});
420439
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /