-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix syntax error when delimited column alias is used without precedin…
…g whitespace (#2512) When the alias is directly adjacent to a keyword (like END) or a non-delimited column name, the error message mentions AS, even though there is no AS keyword in the query. This bug is caused by ANTLR rewriting, we have added an extra space before 'AS' keyword when rewriting the query which which doesn't explicitly has 'AS' keyword before alias. # Input SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END[c] # previous output (wrong output) Msg 33557097, Level 16, State 1, Server persist-rcv-07mar-16-2-0-9, Line 1 syntax error at or near "ENDAS" # current output (correct output) ~~START~~ int 1 ~~END~~ # previous output (wrong output) SELECT 1c; Msg 33557097, Level 16, State 1, Server persist-rcv-07mar-16-2-0-9, Line 1 trailing junk after numeric literal at or near "1A" # current output (correct output) SELECT 1c; ~~START~~ int 1 ~~END~~ Added Test Cases for this issue 4_X PR: #2504 Task: BABEL-4863 Authored-by: Anikait Agrawal [email protected] Signed-off-by: Anikait Agrawal <[email protected]> Co-authored-by: Anikait Agrawal <[email protected]>
- Loading branch information
1 parent
8461054
commit 0efbb15
Showing
35 changed files
with
548 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/JDBC/expected/BABEL-4863-before-16_3-or-15_7-or-14_12-vu-cleanup.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
drop function if exists babel_4863_func | ||
GO | ||
drop function if exists babel_4863_func1 | ||
GO | ||
drop procedure if exists babel_4863_proc | ||
GO | ||
drop view if exists babel_4863_view | ||
GO |
26 changes: 26 additions & 0 deletions
26
test/JDBC/expected/BABEL-4863-before-16_3-or-15_7-or-14_12-vu-prepare.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
create function babel_4863_func() | ||
returns table as return | ||
( | ||
select '1' as val | ||
) | ||
go | ||
|
||
create function babel_4863_func1() | ||
returns table as return | ||
( | ||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END | ||
) | ||
GO | ||
|
||
CREATE PROCEDURE babel_4863_proc @a INT | ||
AS BEGIN | ||
DECLARE @v1 int = CASE WHEN @a=1 THEN 1 ELSE 0 END; | ||
DECLARE @v2 int = CASE WHEN @a=1 THEN 1 ELSE 0 END; | ||
DECLARE @v3 int = CASE WHEN @a=1 THEN 1 ELSE 0 END; | ||
SELECT @v1, @v2, @v3; | ||
END; | ||
GO | ||
|
||
CREATE VIEW babel_4863_view AS | ||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END; | ||
GO |
35 changes: 35 additions & 0 deletions
35
test/JDBC/expected/BABEL-4863-before-16_3-or-15_7-or-14_12-vu-verify.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
select babel_4863_func(); | ||
GO | ||
~~START~~ | ||
varchar | ||
1 | ||
~~END~~ | ||
|
||
select * from babel_4863_func1(); | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
exec babel_4863_proc 1; | ||
GO | ||
~~START~~ | ||
int#!#int#!#int | ||
1#!#1#!#1 | ||
~~END~~ | ||
|
||
exec babel_4863_proc 2; | ||
GO | ||
~~START~~ | ||
int#!#int#!#int | ||
0#!#0#!#0 | ||
~~END~~ | ||
|
||
SELECT * FROM babel_4863_view; | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
drop table if exists babel_4863_t1 | ||
GO | ||
drop function if exists babel_4863_func | ||
GO | ||
drop function if exists babel_4863_func1 | ||
GO | ||
drop procedure if exists babel_4863_proc | ||
GO | ||
drop view if exists babel_4863_view | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
create table babel_4863_t1 (a int) | ||
GO | ||
INSERT INTO babel_4863_t1 VALUES(1) | ||
GO | ||
~~ROW COUNT: 1~~ | ||
|
||
|
||
create function babel_4863_func() | ||
returns table as return | ||
( | ||
select 'value' = '1' | ||
) | ||
go | ||
|
||
create function babel_4863_func1() | ||
returns table as return | ||
( | ||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END[this is a $.^ test], | ||
CASE WHEN 1=1 THEN 1 ELSE 0 END'this is a $.^ test1', | ||
CASE WHEN 1=1 THEN 1 ELSE 0 END"this is a $.^ test2" | ||
) | ||
GO | ||
|
||
CREATE PROCEDURE babel_4863_proc @a INT | ||
AS BEGIN | ||
DECLARE @v1 int = CASE WHEN @a=1 THEN 1 ELSE 0 END; | ||
DECLARE @v2 int = CASE WHEN @a=1 THEN 1 ELSE 0 END; | ||
DECLARE @v3 int = CASE WHEN @a=1 THEN 1 ELSE 0 END; | ||
SELECT @v1[this is a $.^ test], @v2'this is a $.^ test1', @v3"this is a $.^ test2"; | ||
END; | ||
GO | ||
|
||
CREATE VIEW babel_4863_view AS | ||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END[this is a $.^ test], | ||
CASE WHEN 1=1 THEN 1 ELSE 0 END'this is a $.^ test1', | ||
CASE WHEN 1=1 THEN 1 ELSE 0 END"this is a $.^ test2"; | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
SELECT 123abc; | ||
GO | ||
~~START~~ | ||
int | ||
123 | ||
~~END~~ | ||
|
||
SELECT 0x0o; | ||
GO | ||
~~START~~ | ||
varbinary | ||
00 | ||
~~END~~ | ||
|
||
SELECT 1_2_3; | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
SELECT 0.a; | ||
GO | ||
~~START~~ | ||
numeric | ||
0 | ||
~~END~~ | ||
|
||
SELECT 0.0a; | ||
GO | ||
~~START~~ | ||
numeric | ||
0 | ||
~~END~~ | ||
|
||
SELECT .0a; | ||
GO | ||
~~START~~ | ||
numeric | ||
0 | ||
~~END~~ | ||
|
||
SELECT 0.0e1a; | ||
GO | ||
~~START~~ | ||
numeric | ||
0 | ||
~~END~~ | ||
|
||
SELECT $1a; | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END[c] | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END'c' | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END"c" | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
select a[c] from babel_4863_t1 | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
select a"c" from babel_4863_t1 | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
select a'c' from babel_4863_t1 | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
declare @v int=1 | ||
select @v[c] | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
declare @v int=1 | ||
select @v'c' | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
declare @v int=1 | ||
select @v"c" | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
select babel_4863_func()[a]; | ||
GO | ||
~~START~~ | ||
varchar | ||
1 | ||
~~END~~ | ||
|
||
select 1[c]; | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
select 1'c'; | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
select 1"c"; | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
select 'abc'[def]; | ||
GO | ||
~~START~~ | ||
varchar | ||
abc | ||
~~END~~ | ||
|
||
select 'abc''def'; | ||
GO | ||
~~START~~ | ||
varchar | ||
abc'def | ||
~~END~~ | ||
|
||
select 'abc'"def"; | ||
GO | ||
~~START~~ | ||
varchar | ||
abc | ||
~~END~~ | ||
|
||
select 123[this is a $.^ test] | ||
GO | ||
~~START~~ | ||
int | ||
123 | ||
~~END~~ | ||
|
||
select 123'this is a $.^ test' | ||
GO | ||
~~START~~ | ||
int | ||
123 | ||
~~END~~ | ||
|
||
select 123"this is a $.^ test" | ||
GO | ||
~~START~~ | ||
int | ||
123 | ||
~~END~~ | ||
|
||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END[this is a $.^ test] | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END'this is a $.^ test' | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END"this is a $.^ test" | ||
GO | ||
~~START~~ | ||
int | ||
1 | ||
~~END~~ | ||
|
||
select * from babel_4863_func1(); | ||
GO | ||
~~START~~ | ||
int#!#int#!#int | ||
1#!#1#!#1 | ||
~~END~~ | ||
|
||
exec babel_4863_proc 1; | ||
GO | ||
~~START~~ | ||
int#!#int#!#int | ||
1#!#1#!#1 | ||
~~END~~ | ||
|
||
exec babel_4863_proc 2; | ||
GO | ||
~~START~~ | ||
int#!#int#!#int | ||
0#!#0#!#0 | ||
~~END~~ | ||
|
||
SELECT * FROM babel_4863_view; | ||
GO | ||
~~START~~ | ||
int#!#int#!#int | ||
1#!#1#!#1 | ||
~~END~~ | ||
|
Oops, something went wrong.