From 870ac7b20703b05e16edfb763176b976381adaee Mon Sep 17 00:00:00 2001 From: Riya Jain Date: Thu, 28 Sep 2023 07:24:38 +0000 Subject: [PATCH] Added test cases to all upgrade schedule files and Added test case including multibyte characters. Signed-off-by: Riya Jain --- contrib/babelfishpg_tsql/src/hooks.c | 29 ++++++++------------ test/JDBC/expected/BABEL-4279-vu-cleanup.out | 12 ++++++++ test/JDBC/expected/BABEL-4279-vu-prepare.out | 12 ++++++++ test/JDBC/expected/BABEL-4279-vu-verify.out | 16 +++++++++++ test/JDBC/input/BABEL-4279-vu-cleanup.mix | 14 +++++++++- test/JDBC/input/BABEL-4279-vu-prepare.mix | 14 +++++++++- test/JDBC/input/BABEL-4279-vu-verify.mix | 8 +++++- test/JDBC/upgrade/13_4/schedule | 3 +- test/JDBC/upgrade/13_5/schedule | 3 +- test/JDBC/upgrade/13_6/schedule | 1 + test/JDBC/upgrade/13_7/schedule | 3 +- test/JDBC/upgrade/13_8/schedule | 3 +- test/JDBC/upgrade/13_9/schedule | 1 + test/JDBC/upgrade/14_10/schedule | 1 + test/JDBC/upgrade/14_3/schedule | 1 + test/JDBC/upgrade/14_5/schedule | 1 + test/JDBC/upgrade/14_6/schedule | 1 + test/JDBC/upgrade/14_7/schedule | 3 +- test/JDBC/upgrade/14_8/schedule | 3 +- test/JDBC/upgrade/14_9/schedule | 1 + test/JDBC/upgrade/15_1/schedule | 3 +- test/JDBC/upgrade/15_2/schedule | 1 + test/JDBC/upgrade/15_3/schedule | 1 + test/JDBC/upgrade/15_4/schedule | 1 + test/JDBC/upgrade/latest/schedule | 1 + 25 files changed, 110 insertions(+), 27 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index 8921112c8db..d61ba92c390 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -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 && @@ -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. @@ -1633,20 +1632,16 @@ 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--; } @@ -1654,7 +1649,7 @@ pre_transform_target_entry(ResTarget *res, ParseState *pstate, * 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; } @@ -1662,7 +1657,7 @@ pre_transform_target_entry(ResTarget *res, ParseState *pstate, * 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; diff --git a/test/JDBC/expected/BABEL-4279-vu-cleanup.out b/test/JDBC/expected/BABEL-4279-vu-cleanup.out index 13d8267f4fa..0c55378c222 100644 --- a/test/JDBC/expected/BABEL-4279-vu-cleanup.out +++ b/test/JDBC/expected/BABEL-4279-vu-cleanup.out @@ -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 diff --git a/test/JDBC/expected/BABEL-4279-vu-prepare.out b/test/JDBC/expected/BABEL-4279-vu-prepare.out index 21667850552..2a66ad8fbe5 100644 --- a/test/JDBC/expected/BABEL-4279-vu-prepare.out +++ b/test/JDBC/expected/BABEL-4279-vu-prepare.out @@ -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 diff --git a/test/JDBC/expected/BABEL-4279-vu-verify.out b/test/JDBC/expected/BABEL-4279-vu-verify.out index 27cf799dfff..1f813417ca2 100644 --- a/test/JDBC/expected/BABEL-4279-vu-verify.out +++ b/test/JDBC/expected/BABEL-4279-vu-verify.out @@ -54,3 +54,19 @@ text SELECT "sc,sdg""fdsngjds'"."ab[c" AS "AB[C" 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" 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."ぁあ'""" FROM master_dbo.test_babel_4279_t4; +~~END~~ + diff --git a/test/JDBC/input/BABEL-4279-vu-cleanup.mix b/test/JDBC/input/BABEL-4279-vu-cleanup.mix index 947f6739c7d..0c55378c222 100644 --- a/test/JDBC/input/BABEL-4279-vu-cleanup.mix +++ b/test/JDBC/input/BABEL-4279-vu-cleanup.mix @@ -45,4 +45,16 @@ DROP TABLE "tngdf'".[sc,sdg"fdsngjds']; GO DROP SCHEMA "tngdf'"; -GO \ No newline at end of file +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 diff --git a/test/JDBC/input/BABEL-4279-vu-prepare.mix b/test/JDBC/input/BABEL-4279-vu-prepare.mix index 926fc74b3ee..2a66ad8fbe5 100644 --- a/test/JDBC/input/BABEL-4279-vu-prepare.mix +++ b/test/JDBC/input/BABEL-4279-vu-prepare.mix @@ -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 \ No newline at end of file +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 diff --git a/test/JDBC/input/BABEL-4279-vu-verify.mix b/test/JDBC/input/BABEL-4279-vu-verify.mix index 84bb9be2887..2988963e174 100644 --- a/test/JDBC/input/BABEL-4279-vu-verify.mix +++ b/test/JDBC/input/BABEL-4279-vu-verify.mix @@ -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 \ No newline at end of file +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 diff --git a/test/JDBC/upgrade/13_4/schedule b/test/JDBC/upgrade/13_4/schedule index ed11eb933d7..325a6a39164 100644 --- a/test/JDBC/upgrade/13_4/schedule +++ b/test/JDBC/upgrade/13_4/schedule @@ -215,4 +215,5 @@ TestXML timefromparts triggers_with_transaction BABEL-4046 -getdate \ No newline at end of file +getdate +BABEL-4279 diff --git a/test/JDBC/upgrade/13_5/schedule b/test/JDBC/upgrade/13_5/schedule index 1e224e0b435..cfee05dcc66 100644 --- a/test/JDBC/upgrade/13_5/schedule +++ b/test/JDBC/upgrade/13_5/schedule @@ -268,4 +268,5 @@ TestXML timefromparts triggers_with_transaction BABEL-4046 -getdate \ No newline at end of file +getdate +BABEL-4279 diff --git a/test/JDBC/upgrade/13_6/schedule b/test/JDBC/upgrade/13_6/schedule index 155e8462d0f..fcd8430162e 100644 --- a/test/JDBC/upgrade/13_6/schedule +++ b/test/JDBC/upgrade/13_6/schedule @@ -323,3 +323,4 @@ triggers_with_transaction BABEL-4046 getdate BABEL-4410 +BABEL-4279 diff --git a/test/JDBC/upgrade/13_7/schedule b/test/JDBC/upgrade/13_7/schedule index 474e6900d44..792a9862632 100644 --- a/test/JDBC/upgrade/13_7/schedule +++ b/test/JDBC/upgrade/13_7/schedule @@ -316,4 +316,5 @@ TestXML timefromparts triggers_with_transaction BABEL-4046 -getdate \ No newline at end of file +getdate +BABEL-4279 diff --git a/test/JDBC/upgrade/13_8/schedule b/test/JDBC/upgrade/13_8/schedule index 474e6900d44..792a9862632 100644 --- a/test/JDBC/upgrade/13_8/schedule +++ b/test/JDBC/upgrade/13_8/schedule @@ -316,4 +316,5 @@ TestXML timefromparts triggers_with_transaction BABEL-4046 -getdate \ No newline at end of file +getdate +BABEL-4279 diff --git a/test/JDBC/upgrade/13_9/schedule b/test/JDBC/upgrade/13_9/schedule index 435a447e884..f6696714ed1 100644 --- a/test/JDBC/upgrade/13_9/schedule +++ b/test/JDBC/upgrade/13_9/schedule @@ -319,3 +319,4 @@ triggers_with_transaction BABEL-4046 getdate BABEL-4410 +BABEL-4279 diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index c7c742fb8c2..ce9ad567e6f 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -409,3 +409,4 @@ smalldatetimefromparts-dep BABEL_4330 BABEL-4231 BABEL-4384 +BABEL-4279 diff --git a/test/JDBC/upgrade/14_3/schedule b/test/JDBC/upgrade/14_3/schedule index 4143a3eacf8..690ffc1d193 100644 --- a/test/JDBC/upgrade/14_3/schedule +++ b/test/JDBC/upgrade/14_3/schedule @@ -337,3 +337,4 @@ BABEL-4046 BABEL_4330 BABEL-2619 BABEL-4410 +BABEL-4279 diff --git a/test/JDBC/upgrade/14_5/schedule b/test/JDBC/upgrade/14_5/schedule index 5edcf1fea6e..e539839949a 100644 --- a/test/JDBC/upgrade/14_5/schedule +++ b/test/JDBC/upgrade/14_5/schedule @@ -352,3 +352,4 @@ getdate BABEL_4330 BABEL-2619 BABEL-4410 +BABEL-4279 diff --git a/test/JDBC/upgrade/14_6/schedule b/test/JDBC/upgrade/14_6/schedule index 901951aedcc..0949b8c8915 100644 --- a/test/JDBC/upgrade/14_6/schedule +++ b/test/JDBC/upgrade/14_6/schedule @@ -386,3 +386,4 @@ getdate BABEL_4330 BABEL-2619 BABEL-4410 +BABEL-4279 diff --git a/test/JDBC/upgrade/14_7/schedule b/test/JDBC/upgrade/14_7/schedule index b0fc3c87b85..036828e4ce1 100644 --- a/test/JDBC/upgrade/14_7/schedule +++ b/test/JDBC/upgrade/14_7/schedule @@ -407,4 +407,5 @@ datetimeoffset-timezone-before-15_3 BABEL-4046 getdate BABEL_4330 -BABEL-2619 \ No newline at end of file +BABEL-2619 +BABEL-4279 diff --git a/test/JDBC/upgrade/14_8/schedule b/test/JDBC/upgrade/14_8/schedule index b5aa90477e3..1e3dfa2bbfa 100644 --- a/test/JDBC/upgrade/14_8/schedule +++ b/test/JDBC/upgrade/14_8/schedule @@ -405,4 +405,5 @@ datetimeoffset-timezone-before-15_3 BABEL-4046 getdate BABEL_4330 -BABEL-2619 \ No newline at end of file +BABEL-2619 +BABEL-4279 diff --git a/test/JDBC/upgrade/14_9/schedule b/test/JDBC/upgrade/14_9/schedule index 356a58ce8ac..e049537ee4a 100644 --- a/test/JDBC/upgrade/14_9/schedule +++ b/test/JDBC/upgrade/14_9/schedule @@ -408,3 +408,4 @@ getdate BABEL_4330 BABEL-2619 BABEL-4410 +BABEL-4279 diff --git a/test/JDBC/upgrade/15_1/schedule b/test/JDBC/upgrade/15_1/schedule index abd07f86fb3..bd5bfa8f0f7 100644 --- a/test/JDBC/upgrade/15_1/schedule +++ b/test/JDBC/upgrade/15_1/schedule @@ -384,4 +384,5 @@ timefromparts triggers_with_transaction BABEL-4046 getdate -BABEL_4330 \ No newline at end of file +BABEL_4330 +BABEL-4279 diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index 7447637717d..5795e00e496 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -414,3 +414,4 @@ BABEL-4046 getdate BABEL_4330 BABEL-4410 +BABEL-4279 diff --git a/test/JDBC/upgrade/15_3/schedule b/test/JDBC/upgrade/15_3/schedule index 417a435ff57..358bc67f332 100644 --- a/test/JDBC/upgrade/15_3/schedule +++ b/test/JDBC/upgrade/15_3/schedule @@ -436,3 +436,4 @@ datetimeoffset-timezone BABEL-4046 getdate BABEL_4330 +BABEL-4279 diff --git a/test/JDBC/upgrade/15_4/schedule b/test/JDBC/upgrade/15_4/schedule index 79e053ce19e..439be5c2bca 100644 --- a/test/JDBC/upgrade/15_4/schedule +++ b/test/JDBC/upgrade/15_4/schedule @@ -448,3 +448,4 @@ BABEL-4175 sp_who BABEL_4330 BABEL-4410 +BABEL-4279 diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 6eb3d7d3e44..86558608cd6 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -462,3 +462,4 @@ Test_ISNULL BABEL-4270 BABEL-4410 BABEL-4231 +BABEL-4279