Skip to content

Commit

Permalink
Fixed blankspace padding in char datatype for multibyte characters (b…
Browse files Browse the repository at this point in the history
…abelfish-for-postgresql#2167)

Currently when multi-byte character is casted to char(1) space padding was not done properly. This PR will fix this issue.

Task: BABEL-4638
Signed-off-by: Rohit Bhagat <[email protected]>
  • Loading branch information
rohit01010 authored and ritanwar committed Jan 8, 2024
1 parent 8d9e8a1 commit 1a5c560
Show file tree
Hide file tree
Showing 7 changed files with 692 additions and 0 deletions.
1 change: 1 addition & 0 deletions contrib/babelfishpg_common/src/varchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ bpchar(PG_FUNCTION_ARGS)
size_t maxmblen;

maxmblen = pg_encoding_mbcliplen(collInfo.enc, tmp, byteLen, maxByteLen);
blankSpace = maxByteLen - maxmblen;

if (!isExplicit &&
!(suppress_string_truncation_error_hook && (*suppress_string_truncation_error_hook) ()))
Expand Down
16 changes: 16 additions & 0 deletions test/JDBC/expected/BABEL-4638-vu-cleanup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DROP TABLE babel_4638_t1
DROP TABLE babel_4638_t2
DROP TABLE babel_4638_t3
DROP TABLE babel_4638_t4
DROP TABLE babel_4638_t5
DROP TABLE babel_4638_char_t1
DROP TABLE babel_4638_char_t2
DROP TABLE babel_4638_char_t3
DROP TABLE babel_4638_char_t4
DROP TABLE babel_4638_char_t5
DROP TABLE babel_4638_nchar_t1
DROP TABLE babel_4638_nchar_t2
DROP TABLE babel_4638_nchar_t3
DROP TABLE babel_4638_nchar_t4
DROP TABLE babel_4638_nchar_t5
GO
37 changes: 37 additions & 0 deletions test/JDBC/expected/BABEL-4638-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE TABLE babel_4638_t1(a VARCHAR(10) COLLATE arabic_ci_as);
CREATE TABLE babel_4638_t2(a VARCHAR(10) COLLATE chinese_prc_ci_as);
CREATE TABLE babel_4638_t3(a VARCHAR(10) COLLATE japanese_ci_as);
CREATE TABLE babel_4638_t4(a VARCHAR(10) COLLATE hebrew_ci_as);
CREATE TABLE babel_4638_t5(a VARCHAR(10));
GO

CREATE TABLE babel_4638_char_t1(a CHAR(10) COLLATE arabic_ci_as);
CREATE TABLE babel_4638_char_t2(a CHAR(10) COLLATE chinese_prc_ci_as);
CREATE TABLE babel_4638_char_t3(a CHAR(10) COLLATE japanese_ci_as);
CREATE TABLE babel_4638_char_t4(a CHAR(10) COLLATE hebrew_ci_as);
CREATE TABLE babel_4638_char_t5(a CHAR(10));
GO

CREATE TABLE babel_4638_nchar_t1(a NCHAR(10) COLLATE arabic_ci_as);
CREATE TABLE babel_4638_nchar_t2(a NCHAR(10) COLLATE chinese_prc_ci_as);
CREATE TABLE babel_4638_nchar_t3(a NCHAR(10) COLLATE japanese_ci_as);
CREATE TABLE babel_4638_nchar_t4(a NCHAR(10) COLLATE hebrew_ci_as);
CREATE TABLE babel_4638_nchar_t5(a NCHAR(10));
GO

INSERT INTO babel_4638_t1 VALUES('ح'), ('غ'), ('سسس'), ('للل');
INSERT INTO babel_4638_t2 VALUES('五'), ('九'), ('乙乙乙'), ('魚魚魚');
INSERT INTO babel_4638_t3 VALUES('あ'), ('九'), ('ちちち'), ('さささ');
INSERT INTO babel_4638_t4 VALUES('ב'), ('א'), ('קקק'), ('מממ');
INSERT INTO babel_4638_t5 VALUES('a'), ('🙂'), ('🙂🙂🙂'), ('さささ');
GO
~~ROW COUNT: 4~~

~~ROW COUNT: 4~~

~~ROW COUNT: 4~~

~~ROW COUNT: 4~~

~~ROW COUNT: 4~~

Loading

0 comments on commit 1a5c560

Please sign in to comment.