33const debug = require ( 'debug' ) ( 'js-sql-parser' ) ;
44const 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