From 9003c6036d476b7cb5a333fcea6abf2a99b99cea Mon Sep 17 00:00:00 2001 From: Riya Jain <75467028+riyajain39@users.noreply.github.com> Date: Thu, 12 Oct 2023 20:04:04 +0530 Subject: [PATCH] Fix for both table and column aliases contains single and multibyte characters. (#1913) This commit fix the implementation for column and table aliases contain both single byte and multibyte characters whose length is more than 64 bytes. It also fixed the issue with aliases contain multibyte characters with 128 characters. Task: BABEL-4231 Signed-off-by: Riya Jain --- contrib/babelfishpg_tsql/src/hooks.c | 11 +++++------ test/JDBC/expected/BABEL-4231-vu-cleanup.out | 3 +++ test/JDBC/expected/BABEL-4231-vu-prepare.out | 13 +++++++++---- test/JDBC/expected/BABEL-4231-vu-verify.out | 18 ++++++++++++++++++ test/JDBC/input/BABEL-4231-vu-cleanup.mix | 5 ++++- test/JDBC/input/BABEL-4231-vu-prepare.mix | 15 ++++++++++----- test/JDBC/input/BABEL-4231-vu-verify.mix | 8 ++++++++ 7 files changed, 57 insertions(+), 16 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index f38ee92208..47d25d830a 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -910,12 +910,11 @@ extract_identifier(const char *start) * greater than 1 */ /* - * valid identifier cannot be longer than 258 (2*128+2) bytes. SQL server - * allows up to 128 bascially. And escape character can take additional - * one byte for each character in worst case. And additional 2 byes for - * delimiter + * Reaching here implies of valid identifier. It means we can reach + * identifier's end in both the cases of single and multibyte characters. + * If the identifier is not valid, the scanner should have already reported a syntax error. */ - while (i < 258) + while (true) { char c = start[i]; @@ -1404,7 +1403,7 @@ pre_transform_target_entry(ResTarget *res, ParseState *pstate, memcpy(alias + (alias_len) - 32, identifier_name + (alias_len) - 32, 32); - alias[alias_len+1] = '\0'; + alias[alias_len] = '\0'; } /* Identifier is not truncated. */ else diff --git a/test/JDBC/expected/BABEL-4231-vu-cleanup.out b/test/JDBC/expected/BABEL-4231-vu-cleanup.out index 58ab90f5ef..c949c9b902 100644 --- a/test/JDBC/expected/BABEL-4231-vu-cleanup.out +++ b/test/JDBC/expected/BABEL-4231-vu-cleanup.out @@ -154,3 +154,6 @@ DROP VIEW view_babel_4231_40; GO DROP TABLE table18_babel_4231; GO + +DROP VIEW view_babel_4231_41; +GO diff --git a/test/JDBC/expected/BABEL-4231-vu-prepare.out b/test/JDBC/expected/BABEL-4231-vu-prepare.out index 08a4c4156b..a2a9664c5d 100644 --- a/test/JDBC/expected/BABEL-4231-vu-prepare.out +++ b/test/JDBC/expected/BABEL-4231-vu-prepare.out @@ -238,22 +238,22 @@ CREATE VIEW view_babel_4231_35 AS SELECT * FROM table17_babel_4231 AS "αΒβΓ GO -- tsql --- table aliases which are not delimited by double quote, square bracket and length is less than 64 +-- column aliases which are not delimited by double quote, square bracket and length is less than 64 CREATE VIEW view_babel_4231_36 AS SELECT 1 AS ABCD; GO -- tsql --- table aliases with single byte characters which are not delimited by double quote, square bracket and length is more than or equals to 64 +-- column aliases with single byte characters which are not delimited by double quote, square bracket and length is more than or equals to 64 CREATE VIEW view_babel_4231_37 AS SELECT 1 AS ABCDbdjaBFWFGRUWlgrefwfiwuegfdvfwefgvggfedfudywtitewutgfdWUIF; GO -- tsql --- table aliases with single byte characters which are delimited by single quote and length is more than or equals to 64 +-- column aliases with single byte characters which are delimited by single quote and length is more than or equals to 64 CREATE VIEW view_babel_4231_38 AS SELECT 1 AS 'ABCDbdjaBFWFGRUWlgrefwfiwuegfdvfwefgvggfedfudywtitewutgfdWUIF'; GO -- tsql --- table aliases with single byte characters which are delimited by single quote and length is less than 64 +-- column aliases with single byte characters which are delimited by single quote and length is less than 64 CREATE VIEW view_babel_4231_39 AS SELECT 1 AS N'ANfjws'; GO @@ -263,3 +263,8 @@ CREATE TABLE table18_babel_4231(a INT , b INT); GO CREATE VIEW view_babel_4231_40 AS SELECT 您您对您对您对您对您对您对您对您对您对您您您.* FROM table18_babel_4231 AS 您您对您对您对您对您对您对您对您对您对您您您; GO + +-- tsql +-- column aliases with multibyte characters which are delimited by single quote and length is more than 128 +CREATE VIEW view_babel_4231_41 AS SELECT 1 AS '您对“数据一览“中的车型,颜色,内饰,选装, 您对“数据一览“中的车型,颜色,内饰,选装,您对“数据一览“中的车型,颜色,内饰,选装,您对“数据一览“中的车型,颜色,内饰,选装,'; +GO diff --git a/test/JDBC/expected/BABEL-4231-vu-verify.out b/test/JDBC/expected/BABEL-4231-vu-verify.out index c0f120357a..895108d30f 100644 --- a/test/JDBC/expected/BABEL-4231-vu-verify.out +++ b/test/JDBC/expected/BABEL-4231-vu-verify.out @@ -357,3 +357,21 @@ text SELECT "您您对您对您对您对您d60211ff7d947ff09db87babbf0cb9de".a, "您您对您对您对您对您d60211ff7d947ff09db87babbf0cb9de".b FROM master_dbo.table18_babel_4231 "您您对您对您对您对您d60211ff7d947ff09db87babbf0cb9de"; ~~END~~ + +-- psql +SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'view_babel_4231_41'; +GO +~~START~~ +text + SELECT 1 AS "您对“数据一览“中的e06f302024afe951b33a0978fde84988"; +~~END~~ + + +-- tsql +select 1 as '您对“数据一览“中的车型,颜色,内饰,选装, 您对“数据一览“中的车型,颜色,内饰,选装,您对“数据一览“中的车型,颜色,内饰,选装,您对“数据一览“中的车型,颜色,内饰,选装,'; +GO +~~START~~ +int +1 +~~END~~ + diff --git a/test/JDBC/input/BABEL-4231-vu-cleanup.mix b/test/JDBC/input/BABEL-4231-vu-cleanup.mix index 14b3637f08..c949c9b902 100644 --- a/test/JDBC/input/BABEL-4231-vu-cleanup.mix +++ b/test/JDBC/input/BABEL-4231-vu-cleanup.mix @@ -153,4 +153,7 @@ GO DROP VIEW view_babel_4231_40; GO DROP TABLE table18_babel_4231; -GO \ No newline at end of file +GO + +DROP VIEW view_babel_4231_41; +GO diff --git a/test/JDBC/input/BABEL-4231-vu-prepare.mix b/test/JDBC/input/BABEL-4231-vu-prepare.mix index 0b1a02d8a3..a2a9664c5d 100644 --- a/test/JDBC/input/BABEL-4231-vu-prepare.mix +++ b/test/JDBC/input/BABEL-4231-vu-prepare.mix @@ -238,22 +238,22 @@ CREATE VIEW view_babel_4231_35 AS SELECT * FROM table17_babel_4231 AS "αΒβΓ GO -- tsql --- table aliases which are not delimited by double quote, square bracket and length is less than 64 +-- column aliases which are not delimited by double quote, square bracket and length is less than 64 CREATE VIEW view_babel_4231_36 AS SELECT 1 AS ABCD; GO -- tsql --- table aliases with single byte characters which are not delimited by double quote, square bracket and length is more than or equals to 64 +-- column aliases with single byte characters which are not delimited by double quote, square bracket and length is more than or equals to 64 CREATE VIEW view_babel_4231_37 AS SELECT 1 AS ABCDbdjaBFWFGRUWlgrefwfiwuegfdvfwefgvggfedfudywtitewutgfdWUIF; GO -- tsql --- table aliases with single byte characters which are delimited by single quote and length is more than or equals to 64 +-- column aliases with single byte characters which are delimited by single quote and length is more than or equals to 64 CREATE VIEW view_babel_4231_38 AS SELECT 1 AS 'ABCDbdjaBFWFGRUWlgrefwfiwuegfdvfwefgvggfedfudywtitewutgfdWUIF'; GO -- tsql --- table aliases with single byte characters which are delimited by single quote and length is less than 64 +-- column aliases with single byte characters which are delimited by single quote and length is less than 64 CREATE VIEW view_babel_4231_39 AS SELECT 1 AS N'ANfjws'; GO @@ -262,4 +262,9 @@ GO CREATE TABLE table18_babel_4231(a INT , b INT); GO CREATE VIEW view_babel_4231_40 AS SELECT 您您对您对您对您对您对您对您对您对您对您您您.* FROM table18_babel_4231 AS 您您对您对您对您对您对您对您对您对您对您您您; -GO \ No newline at end of file +GO + +-- tsql +-- column aliases with multibyte characters which are delimited by single quote and length is more than 128 +CREATE VIEW view_babel_4231_41 AS SELECT 1 AS '您对“数据一览“中的车型,颜色,内饰,选装, 您对“数据一览“中的车型,颜色,内饰,选装,您对“数据一览“中的车型,颜色,内饰,选装,您对“数据一览“中的车型,颜色,内饰,选装,'; +GO diff --git a/test/JDBC/input/BABEL-4231-vu-verify.mix b/test/JDBC/input/BABEL-4231-vu-verify.mix index 25857eedcb..c29272baae 100644 --- a/test/JDBC/input/BABEL-4231-vu-verify.mix +++ b/test/JDBC/input/BABEL-4231-vu-verify.mix @@ -157,3 +157,11 @@ GO -- psql SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'view_babel_4231_40'; GO + +-- psql +SELECT pg_catalog.pg_get_viewdef(oid, true) FROM pg_class WHERE relname = 'view_babel_4231_41'; +GO + +-- tsql +select 1 as '您对“数据一览“中的车型,颜色,内饰,选装, 您对“数据一览“中的车型,颜色,内饰,选装,您对“数据一览“中的车型,颜色,内饰,选装,您对“数据一览“中的车型,颜色,内饰,选装,'; +GO