Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 06113a6

Browse files
committed
Fixed problem with sort order of some russian letters in the mchar module. PGPRO-1509
1 parent 23aa50b commit 06113a6

File tree

3 files changed

+79
-12
lines changed

3 files changed

+79
-12
lines changed

contrib/mchar/expected/mm.out

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,44 @@ SELECT * FROM a, c WHERE mvarchar255 = mchar2;
803803

804804
DROP TABLE a;
805805
DROP TABLE c;
806+
select * from (values ('е'::mchar),('ё'),('еа'),('еб'),('ее'),('еж'),('ёа'),('ёб'),('ёё'),('ёж'),('ёе'),('её')) z order by 1;
807+
column1
808+
---------
809+
е
810+
еа
811+
еб
812+
ее
813+
её
814+
еж
815+
ё
816+
ёа
817+
ёб
818+
ёе
819+
ёё
820+
ёж
821+
(12 rows)
822+
823+
select mvarchar_icase_cmp('ё', 'е');
824+
mvarchar_icase_cmp
825+
--------------------
826+
1
827+
(1 row)
828+
829+
select mvarchar_icase_cmp('Ё', 'Е');
830+
mvarchar_icase_cmp
831+
--------------------
832+
1
833+
(1 row)
834+
835+
select mvarchar_icase_cmp('й', 'и');
836+
mvarchar_icase_cmp
837+
--------------------
838+
1
839+
(1 row)
840+
841+
select mvarchar_icase_cmp('Й', 'И');
842+
mvarchar_icase_cmp
843+
--------------------
844+
1
845+
(1 row)
846+

contrib/mchar/mchar_recode.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ createUObjs() {
3131
elog(ERROR,"ICU ucol_open returns %d (%s)", err, u_errorName(err));
3232
}
3333

34+
/* UCOL_PRIMARY doesn't distinguish И & Й, Е & Ё */
3435
ucol_setStrength( colCaseInsensitive, UCOL_SECONDARY );
3536
}
3637

@@ -114,29 +115,49 @@ FillWhiteSpace( UChar *dst, int n ) {
114115
int
115116
UCharCaseCompare(UChar * a, int alen, UChar *b, int blen) {
116117
int len = Min(alen, blen);
117-
int res;
118+
int i, res;
118119

119120
createUObjs();
120121

121-
res = (int)ucol_strcoll( colCaseInsensitive,
122-
a, len,
123-
b, len);
124-
if ( res == 0 && alen != blen )
122+
/*
123+
* Preventing any influence of following characters to
124+
* current one, try
125+
* select * from (values ('е'::mchar),('ё'),('еа'),('еб'),('ее'),('еж'),
126+
* ('ёа'),('ёб'),('ёё'),('ёж'),('ёе'),('её')) z
127+
* order by 1;
128+
*/
129+
for (i=0; i<len; i++)
130+
{
131+
res = (int)ucol_strcoll(colCaseInsensitive,
132+
a + i, 1,
133+
b + i, 1);
134+
if (res)
135+
return res;
136+
}
137+
138+
if (alen != blen)
125139
return (alen > blen) ? 1 : - 1;
126-
return res;
140+
return 0;
127141
}
128142

129143
int
130144
UCharCompare(UChar * a, int alen, UChar *b, int blen) {
131145
int len = Min(alen, blen);
132-
int res;
146+
int i, res;
133147

134148
createUObjs();
135149

136-
res = (int)ucol_strcoll( colCaseSensitive,
137-
a, len,
138-
b, len);
139-
if ( res == 0 && alen != blen )
150+
/* see above */
151+
for (i=0; i<len; i++)
152+
{
153+
res = (int)ucol_strcoll(colCaseSensitive,
154+
a + i, 1,
155+
b + i, 1);
156+
if (res)
157+
return res;
158+
}
159+
160+
if (alen != blen)
140161
return (alen > blen) ? 1 : - 1;
141-
return res;
162+
return 0;
142163
}

contrib/mchar/sql/mm.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,8 @@ SELECT * FROM a, c WHERE mvarchar255 = mchar2;
183183
DROP TABLE a;
184184
DROP TABLE c;
185185

186+
select * from (values ('е'::mchar),('ё'),('еа'),('еб'),('ее'),('еж'),('ёа'),('ёб'),('ёё'),('ёж'),('ёе'),('её')) z order by 1;
187+
select mvarchar_icase_cmp('ё', 'е');
188+
select mvarchar_icase_cmp('Ё', 'Е');
189+
select mvarchar_icase_cmp('й', 'и');
190+
select mvarchar_icase_cmp('Й', 'И');

0 commit comments

Comments
 (0)