Skip to content

Commit

Permalink
Added test cases to all upgrade schedule files and Added test case in…
Browse files Browse the repository at this point in the history
…cluding multibyte characters.

Signed-off-by: Riya Jain <[email protected]>
  • Loading branch information
Riya Jain committed Sep 28, 2023
1 parent 9acfaec commit 870ac7b
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 27 deletions.
29 changes: 12 additions & 17 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,6 @@ pre_transform_target_entry(ResTarget *res, ParseState *pstate,
const char *identifier_name = NULL;
int open_square_bracket = 0;
int double_quotes = 0;
int single_quotes = 0;
const char *last_dot;

if (res->name == NULL && res->location != -1 &&
Expand All @@ -1612,15 +1611,15 @@ pre_transform_target_entry(ResTarget *res, ParseState *pstate,
}
/*
* This condition will preserve the case of column name when there are more than
* one cref->feilds. For instance, Queries like
* select [database].[schema].[table].[column] from table.
* select [schema].[table].[column] from table.
* selec [t].[column] from table as t
* one cref->fields. For instance, Queries like
* 1. select [database].[schema].[table].[column] from table.
* 2. select [schema].[table].[column] from table.
* 3. select [t].[column] from table as t
* Case 1: Handle the cases when column name is passed with no delimiters
* For example, select ABC from table
* Case 2: Handle the cases when column name is delimited with sq and dq.
* In such cases, we are checking if no. of dq or sq are even or not. When sq are odd,
* we are not tracing number of sqb and dq within sq, similar with the case of dq.
* Case 2: Handle the cases when column name is delimited with dq.
* In such cases, we are checking if no. of dq are even or not. When dq are odd,
* we are not tracing number of sqb and sq within dq.
* For instance, Queries like select "AF bjs'vs] " from table.
* Case 3: Handle the case when column name is delimited with sqb. When number of sqb
* are zero, it means we are out of sqb.
Expand All @@ -1633,36 +1632,32 @@ pre_transform_target_entry(ResTarget *res, ParseState *pstate,
colname_start = pstate->p_sourcetext + res->location;
while(true)
{
if(open_square_bracket == 0 && single_quotes % 2 == 0 && *colname_start == '"')
if(open_square_bracket == 0 && *colname_start == '"')
{
double_quotes++;
}
if(open_square_bracket == 0 && double_quotes % 2 == 0 && *colname_start == '\'')
{
single_quotes++;
}
/* To check how many open sqb are present in sourcetext. */
if(double_quotes % 2 == 0 && single_quotes % 2 == 0 && *colname_start == '[')
else if(double_quotes % 2 == 0 && *colname_start == '[')
{
open_square_bracket++;
}
if(double_quotes % 2 == 0 && single_quotes % 2 == 0 && *colname_start == ']')
else if(double_quotes % 2 == 0 && *colname_start == ']')
{
open_square_bracket--;
}
/*
* last_dot pointer is to trace the last dot in the sourcetext,
* as last dot indicates the starting of column name.
*/
if(open_square_bracket == 0 && double_quotes % 2 == 0 && single_quotes % 2 == 0 && *colname_start == '.')
else if(open_square_bracket == 0 && double_quotes % 2 == 0 && *colname_start == '.')
{
last_dot = colname_start;
}
/*
* If there is no open sqb, there are even no. of sq or dq and colname_start is at
* space or comma, it means colname_start is at the end of column name.
*/
if(open_square_bracket == 0 && double_quotes % 2 == 0 && single_quotes % 2 == 0 && open_square_bracket == 0 && (*colname_start == ' ' || *colname_start == ','))
else if(open_square_bracket == 0 && double_quotes % 2 == 0 && (*colname_start == ' ' || *colname_start == ','))
{
last_dot++;
colname_start = last_dot;
Expand Down
12 changes: 12 additions & 0 deletions test/JDBC/expected/BABEL-4279-vu-cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ GO

DROP SCHEMA "tngdf'";
GO

DROP VIEW test_babel_4279_v7;
GO

DROP TABLE test_babel_4279_t3;
GO

DROP VIEW test_babel_4279_v8;
GO

DROP TABLE test_babel_4279_t4;
GO
12 changes: 12 additions & 0 deletions test/JDBC/expected/BABEL-4279-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ GO

CREATE VIEW test_babel_4279_v6 AS SELECT "tngdf'".[sc,sdg"fdsngjds']."AB[C" from "tngdf'".[sc,sdg"fdsngjds'];
GO

CREATE TABLE test_babel_4279_t3(ABCD INT);
GO

CREATE VIEW test_babel_4279_v7 AS SELECT test_babel_4279_t3.ABCD FROM test_babel_4279_t3;
GO

CREATE TABLE test_babel_4279_t4([ぁあ'"] INT);
GO

CREATE VIEW test_babel_4279_v8 AS SELECT test_babel_4279_t4.[ぁあ'"] FROM test_babel_4279_t4;
GO
16 changes: 16 additions & 0 deletions test/JDBC/expected/BABEL-4279-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ text
SELECT "sc,sdg""fdsngjds'"."ab[c" AS "AB[C"<newline> FROM "master_tngdf'"."sc,sdg""fdsngjds'";
~~END~~


SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'test_babel_4279_v7';
GO
~~START~~
text
SELECT test_babel_4279_t3.abcd AS "ABCD"<newline> FROM master_dbo.test_babel_4279_t3;
~~END~~


SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'test_babel_4279_v8';
GO
~~START~~
text
SELECT test_babel_4279_t4."ぁあ'"""<newline> FROM master_dbo.test_babel_4279_t4;
~~END~~

14 changes: 13 additions & 1 deletion test/JDBC/input/BABEL-4279-vu-cleanup.mix
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ DROP TABLE "tngdf'".[sc,sdg"fdsngjds'];
GO

DROP SCHEMA "tngdf'";
GO
GO

DROP VIEW test_babel_4279_v7;
GO

DROP TABLE test_babel_4279_t3;
GO

DROP VIEW test_babel_4279_v8;
GO

DROP TABLE test_babel_4279_t4;
GO
14 changes: 13 additions & 1 deletion test/JDBC/input/BABEL-4279-vu-prepare.mix
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ CREATE TABLE "tngdf'".[sc,sdg"fdsngjds']("AB[C" INT);
GO

CREATE VIEW test_babel_4279_v6 AS SELECT "tngdf'".[sc,sdg"fdsngjds']."AB[C" from "tngdf'".[sc,sdg"fdsngjds'];
GO
GO

CREATE TABLE test_babel_4279_t3(ABCD INT);
GO

CREATE VIEW test_babel_4279_v7 AS SELECT test_babel_4279_t3.ABCD FROM test_babel_4279_t3;
GO

CREATE TABLE test_babel_4279_t4([ぁあ'"] INT);
GO

CREATE VIEW test_babel_4279_v8 AS SELECT test_babel_4279_t4.[ぁあ'"] FROM test_babel_4279_t4;
GO
8 changes: 7 additions & 1 deletion test/JDBC/input/BABEL-4279-vu-verify.mix
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'test_
GO

SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'test_babel_4279_v6';
GO
GO

SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'test_babel_4279_v7';
GO

SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'test_babel_4279_v8';
GO
3 changes: 2 additions & 1 deletion test/JDBC/upgrade/13_4/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,5 @@ TestXML
timefromparts
triggers_with_transaction
BABEL-4046
getdate
getdate
BABEL-4279
3 changes: 2 additions & 1 deletion test/JDBC/upgrade/13_5/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,5 @@ TestXML
timefromparts
triggers_with_transaction
BABEL-4046
getdate
getdate
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/13_6/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,4 @@ triggers_with_transaction
BABEL-4046
getdate
BABEL-4410
BABEL-4279
3 changes: 2 additions & 1 deletion test/JDBC/upgrade/13_7/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,5 @@ TestXML
timefromparts
triggers_with_transaction
BABEL-4046
getdate
getdate
BABEL-4279
3 changes: 2 additions & 1 deletion test/JDBC/upgrade/13_8/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,5 @@ TestXML
timefromparts
triggers_with_transaction
BABEL-4046
getdate
getdate
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/13_9/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,4 @@ triggers_with_transaction
BABEL-4046
getdate
BABEL-4410
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/14_10/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,4 @@ smalldatetimefromparts-dep
BABEL_4330
BABEL-4231
BABEL-4384
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/14_3/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,4 @@ BABEL-4046
BABEL_4330
BABEL-2619
BABEL-4410
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/14_5/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,4 @@ getdate
BABEL_4330
BABEL-2619
BABEL-4410
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/14_6/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,4 @@ getdate
BABEL_4330
BABEL-2619
BABEL-4410
BABEL-4279
3 changes: 2 additions & 1 deletion test/JDBC/upgrade/14_7/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,5 @@ datetimeoffset-timezone-before-15_3
BABEL-4046
getdate
BABEL_4330
BABEL-2619
BABEL-2619
BABEL-4279
3 changes: 2 additions & 1 deletion test/JDBC/upgrade/14_8/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,5 @@ datetimeoffset-timezone-before-15_3
BABEL-4046
getdate
BABEL_4330
BABEL-2619
BABEL-2619
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/14_9/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,4 @@ getdate
BABEL_4330
BABEL-2619
BABEL-4410
BABEL-4279
3 changes: 2 additions & 1 deletion test/JDBC/upgrade/15_1/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,5 @@ timefromparts
triggers_with_transaction
BABEL-4046
getdate
BABEL_4330
BABEL_4330
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/15_2/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,4 @@ BABEL-4046
getdate
BABEL_4330
BABEL-4410
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/15_3/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,4 @@ datetimeoffset-timezone
BABEL-4046
getdate
BABEL_4330
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/15_4/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,4 @@ BABEL-4175
sp_who
BABEL_4330
BABEL-4410
BABEL-4279
1 change: 1 addition & 0 deletions test/JDBC/upgrade/latest/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,4 @@ Test_ISNULL
BABEL-4270
BABEL-4410
BABEL-4231
BABEL-4279

0 comments on commit 870ac7b

Please sign in to comment.