diff options
author | Bruce Momjian | 1998-06-16 06:42:02 +0000 |
---|---|---|
committer | Bruce Momjian | 1998-06-16 06:42:02 +0000 |
commit | 8d8bcda2531bbae665c2cbe57dade4271b0eb087 (patch) | |
tree | 1cb88a3b8fc135e89d6a070dff2244656696c90a | |
parent | 67a636918a85fb29333d6b3c8d576ffe62f7df9a (diff) |
Hello!
Attached to the mail is locale-patch.tar.gz. In the archive
there are:
file README.locale
short description
directory src/test/locale
test suite; currently only koi8-r tests, but the suite can be
easily extended
file locale.patch
the very patch; to apply: patch < locale.patch; should be applied
to postgres-6.3.2 (at least I created it with 6.3.2 without any
additional
patches)
Files touched by the patch: src/include/utils/builtins.h
src/backend/utils/adt/char.c src/backend/utils/adt/varchar.c
src/backend/utils/adt/varlena.c
Oleg
21 files changed, 815 insertions, 90 deletions
diff --git a/doc/README.locale b/doc/README.locale new file mode 100644 index 00000000000..2bd6af24320 --- /dev/null +++ b/doc/README.locale @@ -0,0 +1,17 @@ + +1998 May 25 + + I extended locale support. Now ORDER BY (if PostgreSQL configured with +--enable-locale) uses strcoll() for all text fields: char(n), varchar(n), +text. (I am not sure about ORDER BY char2/char4/etc.) + + I included test suite .../src/test/locale. I didn't include this in +the regression test because not so much people require locale support. Read +.../src/test/locale/README for details on the test suite. + + Many thanks to Oleg Bartunov ([email protected]) and Thomas G. Lockhart +([email protected]) for hints, tips, help and discussion. + +Oleg. +---- + Oleg Broytmann http://members.tripod.com/~phd2/ [email protected] diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 863e21e2cce..be7130896ef 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.33 1998/06/15 19:29:38 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.34 1998/06/16 06:41:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -475,7 +475,7 @@ bpcharlt(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if (cmp == 0) return (len1 < len2); else @@ -494,7 +494,7 @@ bpcharle(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if (0 == cmp) return (bool) (len1 <= len2 ? 1 : 0); else @@ -513,7 +513,7 @@ bpchargt(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if (cmp == 0) return (len1 > len2); else @@ -532,7 +532,7 @@ bpcharge(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if (0 == cmp) return (bool) (len1 >= len2 ? 1 : 0); else @@ -549,7 +549,7 @@ bpcharcmp(char *arg1, char *arg2) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if ((0 == cmp) && (len1 != len2)) return (int32) (len1 < len2 ? -1 : 1); else @@ -641,7 +641,7 @@ varcharlt(char *arg1, char *arg2) len1 = VARSIZE(arg1) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ; - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if (cmp == 0) return (len1 < len2); else @@ -660,7 +660,7 @@ varcharle(char *arg1, char *arg2) len1 = VARSIZE(arg1) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ; - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if (0 == cmp) return (bool) (len1 <= len2 ? 1 : 0); else @@ -679,7 +679,7 @@ varchargt(char *arg1, char *arg2) len1 = VARSIZE(arg1) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ; - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if (cmp == 0) return (len1 > len2); else @@ -698,7 +698,7 @@ varcharge(char *arg1, char *arg2) len1 = VARSIZE(arg1) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ; - cmp = strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if (0 == cmp) return (bool) (len1 >= len2 ? 1 : 0); else @@ -715,7 +715,7 @@ varcharcmp(char *arg1, char *arg2) len1 = VARSIZE(arg1) - VARHDRSZ; len2 = VARSIZE(arg2) - VARHDRSZ; - cmp = (strncmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2))); + cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); if ((0 == cmp) && (len1 != len2)) return (int32) (len1 < len2 ? -1 : 1); else diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 46f74c41442..596863dd876 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.36 1998/06/15 19:29:38 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.37 1998/06/16 06:41:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -468,116 +468,87 @@ textne(text *arg1, text *arg2) return ((bool) !texteq(arg1, arg2)); } -/* text_lt() - * Comparison function for text strings. +/* varstr_cmp() + * Comparison function for text strings with given lengths. * Includes locale support, but must copy strings to temporary memory * to allow null-termination for inputs to strcoll(). - * XXX HACK code for textlen() indicates that there can be embedded nulls - * but it appears that most routines (incl. this one) assume not! - tgl 97/04/07 + * Returns -1, 0 or 1 */ -bool -text_lt(text *arg1, text *arg2) +int +varstr_cmp(unsigned char *arg1, int len1, unsigned char *arg2, int len2) { - bool result; - -#ifdef USE_LOCALE - int cval; - -#endif - int len; - unsigned char *a1p, - *a2p; - - if (arg1 == NULL || arg2 == NULL) - return ((bool) FALSE); - - len = (((VARSIZE(arg1) <= VARSIZE(arg2)) ? VARSIZE(arg1) : VARSIZE(arg2)) - VARHDRSZ); + int result; + unsigned char *a1p, *a2p; #ifdef USE_LOCALE - a1p = (unsigned char *) palloc(len + 1); - a2p = (unsigned char *) palloc(len + 1); + a1p = (unsigned char *) palloc(len1 + 1); + a2p = (unsigned char *) palloc(len2 + 1); - memcpy(a1p, VARDATA(arg1), len); - *(a1p + len) = '\0'; - memcpy(a2p, VARDATA(arg2), len); - *(a2p + len) = '\0'; + memcpy(a1p, arg1, len1); + *(a1p + len1) = '\0'; + memcpy(a2p, arg2, len2); + *(a2p + len2) = '\0'; - cval = strcoll(a1p, a2p); - result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) < VARSIZE(arg2)))); + result = strcoll(a1p, a2p); pfree(a1p); pfree(a2p); + #else - a1p = (unsigned char *) VARDATA(arg1); - a2p = (unsigned char *) VARDATA(arg2); - while (len != 0 && *a1p == *a2p) - { - a1p++; - a2p++; - len--; - }; + a1p = arg1; + a2p = arg2; - result = (len ? (*a1p < *a2p) : (VARSIZE(arg1) < VARSIZE(arg2))); + result = strncmp(a1p, a2p, Min(len1, len2)); + if ((result == 0) && (len1 != len2)) + result = (len1 < len2) ? -1 : 1; #endif return (result); -} /* text_lt() */ +} /* varstr_cmp() */ -/* text_le() +/* text_cmp() * Comparison function for text strings. * Includes locale support, but must copy strings to temporary memory * to allow null-termination for inputs to strcoll(). * XXX HACK code for textlen() indicates that there can be embedded nulls * but it appears that most routines (incl. this one) assume not! - tgl 97/04/07 + * Returns -1, 0 or 1 */ -bool -text_le(text *arg1, text *arg2) +int +text_cmp(text *arg1, text *arg2) { - bool result; - -#ifdef USE_LOCALE - int cval; - -#endif - int len; - unsigned char *a1p, - *a2p; + unsigned char *a1p, *a2p; + int len1, len2; if (arg1 == NULL || arg2 == NULL) - return ((bool) 0); - - len = (((VARSIZE(arg1) <= VARSIZE(arg2)) ? VARSIZE(arg1) : VARSIZE(arg2)) - VARHDRSZ); - -#ifdef USE_LOCALE - a1p = (unsigned char *) palloc(len + 1); - a2p = (unsigned char *) palloc(len + 1); - - memcpy(a1p, VARDATA(arg1), len); - *(a1p + len) = '\0'; - memcpy(a2p, VARDATA(arg2), len); - *(a2p + len) = '\0'; - - cval = strcoll(a1p, a2p); - result = ((cval < 0) || ((cval == 0) && (VARSIZE(arg1) <= VARSIZE(arg2)))); + return ((bool) FALSE); - pfree(a1p); - pfree(a2p); -#else a1p = (unsigned char *) VARDATA(arg1); a2p = (unsigned char *) VARDATA(arg2); - while (len != 0 && *a1p == *a2p) - { - a1p++; - a2p++; - len--; - }; + len1 = VARSIZE(arg1) - VARHDRSZ; + len2 = VARSIZE(arg2) - VARHDRSZ; - result = (len ? (*a1p <= *a2p) : (VARSIZE(arg1) <= VARSIZE(arg2))); -#endif + return varstr_cmp(a1p, len1, a2p, len2); +} /* text_cmp() */ - return (result); +/* text_lt() + * Comparison function for text strings. + */ +bool +text_lt(text *arg1, text *arg2) +{ + return (bool)(text_cmp(arg1, arg2) < 0); +} /* text_lt() */ + +/* text_le() + * Comparison function for text strings. + */ +bool +text_le(text *arg1, text *arg2) +{ + return (bool)(text_cmp(arg1, arg2) <= 0); } /* text_le() */ bool diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index b334996f19f..323a42ea70b 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: builtins.h,v 1.43 1998/05/29 13:37:29 thomas Exp $ + * $Id: builtins.h,v 1.44 1998/06/16 06:41:51 momjian Exp $ * * NOTES * This should normally only be included by fmgr.h. @@ -428,6 +428,8 @@ extern char *textout(text *vlena); extern text *textcat(text *arg1, text *arg2); extern bool texteq(text *arg1, text *arg2); extern bool textne(text *arg1, text *arg2); +extern int varstr_cmp(unsigned char *arg1, int len1, unsigned char *arg2, int len2); +extern int text_cmp(text *arg1, text *arg2); extern bool text_lt(text *arg1, text *arg2); extern bool text_le(text *arg1, text *arg2); extern bool text_gt(text *arg1, text *arg2); diff --git a/src/test/locale/Makefile b/src/test/locale/Makefile new file mode 100644 index 00000000000..36c951c5d09 --- /dev/null +++ b/src/test/locale/Makefile @@ -0,0 +1,33 @@ +# +# Makefile for example programs +# + +SRCDIR= ../.. +include ../../Makefile.global + +# +# And where libpq goes, so goes the authentication stuff... +# +ifdef KRBVERS +LDFLAGS+= $(KRBLIBS) +CFLAGS+= $(KRBFLAGS) +endif + +PROGS = test-pgsql-locale test-ctype +DIRS = koi8-r + +all: $(PROGS) + +$(PROGS): % : %.c + $(CC) $(CFLAGS) -o $@ [email protected] $(LDFLAGS) + +clean: + rm -f $(PROGS) *.out + for d in $(DIRS); do \ + cd $$d; \ + $(MAKE) clean; \ + cd ..; \ + done + +test-%: all + @cd `echo $@ | sed s/^test-//` && $(MAKE) test diff --git a/src/test/locale/README b/src/test/locale/README new file mode 100644 index 00000000000..9cdf64ac23b --- /dev/null +++ b/src/test/locale/README @@ -0,0 +1,27 @@ + +1998 May 25 + + This directory contains a set of tests for locales. I provided one C +program test-ctype.c to test CTYPE support in libc and installed +localedata. Then there are test-sort.pl and test-sort.py that tests +collating. (Also there is test-sort.py but it is commented out in scripts; +uncomment it if you have Python interpreter installed). + To run a test for some locale (koi8, e.g) run +make all test-$locale + (for example) +make all test-koi8 + + Currently, only tests for koi8 locale (russian cyrillic for UN*X) +provided in koi8 directory. Script `runall' calls test-pgsql-locale to test +whether locale support had been compiled into PotgreSQL, test-ctype to test +libc and localedata, test-sort.pl (uncomment test-sort.py, if you have +Python interpreter installed) and does tests on PostgreSQL with +test-koi8*.sql.in. + + To add locale tests one need to create directory $locale and create +Makefile (and other files) similar to koi8-r/*. Actually, the simplest (I +think) method is just copy koi8-r directory and edit/replace files. + +Oleg. +---- + Oleg Broytmann http://members.tripod.com/~phd2/ [email protected] diff --git a/src/test/locale/koi8-r/Makefile b/src/test/locale/koi8-r/Makefile new file mode 100644 index 00000000000..281014521ef --- /dev/null +++ b/src/test/locale/koi8-r/Makefile @@ -0,0 +1,12 @@ +# +# Makefile for example programs +# + +all: + -@echo "make: Nothing to be done for \`all'." + +test: + @./runall + +clean: + rm -f *.out diff --git a/src/test/locale/koi8-r/expected/koi8-ctype.out b/src/test/locale/koi8-r/expected/koi8-ctype.out new file mode 100644 index 00000000000..9b1d9d41a18 --- /dev/null +++ b/src/test/locale/koi8-r/expected/koi8-ctype.out @@ -0,0 +1,257 @@ +char# char alnum alpha cntrl digit lower graph print punct space upper xdigit lo up +chr#0 + +chr#1 + +chr#2 + +chr#3 + +chr#4 + +chr#5 + +chr#6 + +chr#7 + +chr#8 + +chr#9 + + +chr#10 + + +chr#11 + + +chr#12 + + +chr#13 + + +chr#14 + +chr#15 + +chr#16 + +chr#17 + +chr#18 + +chr#19 + +chr#20 + +chr#21 + +chr#22 + +chr#23 + +chr#24 + +chr#25 + +chr#26 + +chr#27 + +chr#28 + +chr#29 + +chr#30 + +chr#31 + +chr#32 + + +chr#33 ! + + + ! ! +chr#34 " + + + " " +chr#35 # + + + # # +chr#36 $ + + + $ $ +chr#37 % + + + % % +chr#38 & + + + & & +chr#39 ' + + + ' ' +chr#40 ( + + + ( ( +chr#41 ) + + + ) ) +chr#42 * + + + * * +chr#43 + + + + + + +chr#44 , + + + , , +chr#45 - + + + - - +chr#46 . + + + . . +chr#47 / + + + / / +chr#48 0 + + + + + 0 0 +chr#49 1 + + + + + 1 1 +chr#50 2 + + + + + 2 2 +chr#51 3 + + + + + 3 3 +chr#52 4 + + + + + 4 4 +chr#53 5 + + + + + 5 5 +chr#54 6 + + + + + 6 6 +chr#55 7 + + + + + 7 7 +chr#56 8 + + + + + 8 8 +chr#57 9 + + + + + 9 9 +chr#58 : + + + : : +chr#59 ; + + + ; ; +chr#60 < + + + < < +chr#61 = + + + = = +chr#62 > + + + > > +chr#63 ? + + + ? ? +chr#64 @ + + + @ @ +chr#65 A + + + + + + a A +chr#66 B + + + + + + b B +chr#67 C + + + + + + c C +chr#68 D + + + + + + d D +chr#69 E + + + + + + e E +chr#70 F + + + + + + f F +chr#71 G + + + + + g G +chr#72 H + + + + + h H +chr#73 I + + + + + i I +chr#74 J + + + + + j J +chr#75 K + + + + + k K +chr#76 L + + + + + l L +chr#77 M + + + + + m M +chr#78 N + + + + + n N +chr#79 O + + + + + o O +chr#80 P + + + + + p P +chr#81 Q + + + + + q Q +chr#82 R + + + + + r R +chr#83 S + + + + + s S +chr#84 T + + + + + t T +chr#85 U + + + + + u U +chr#86 V + + + + + v V +chr#87 W + + + + + w W +chr#88 X + + + + + x X +chr#89 Y + + + + + y Y +chr#90 Z + + + + + z Z +chr#91 [ + + + [ [ +chr#92 \ + + + \ \ +chr#93 ] + + + ] ] +chr#94 ^ + + + ^ ^ +chr#95 _ + + + _ _ +chr#96 ` + + + ` ` +chr#97 a + + + + + + a A +chr#98 b + + + + + + b B +chr#99 c + + + + + + c C +chr#100 d + + + + + + d D +chr#101 e + + + + + + e E +chr#102 f + + + + + + f F +chr#103 g + + + + + g G +chr#104 h + + + + + h H +chr#105 i + + + + + i I +chr#106 j + + + + + j J +chr#107 k + + + + + k K +chr#108 l + + + + + l L +chr#109 m + + + + + m M +chr#110 n + + + + + n N +chr#111 o + + + + + o O +chr#112 p + + + + + p P +chr#113 q + + + + + q Q +chr#114 r + + + + + r R +chr#115 s + + + + + s S +chr#116 t + + + + + t T +chr#117 u + + + + + u U +chr#118 v + + + + + v V +chr#119 w + + + + + w W +chr#120 x + + + + + x X +chr#121 y + + + + + y Y +chr#122 z + + + + + z Z +chr#123 { + + + { { +chr#124 | + + + | | +chr#125 } + + + } } +chr#126 ~ + + + ~ ~ +chr#127 + +chr#128 � + + + � � +chr#129 � + + + � � +chr#130 � + + + � � +chr#131 � + + + � � +chr#132 � + + + � � +chr#133 � + + + � � +chr#134 � + + + � � +chr#135 � + + + � � +chr#136 � + + + � � +chr#137 � + + + � � +chr#138 � + + + � � +chr#139 � + + + � � +chr#140 � + + + � � +chr#141 � + + + � � +chr#142 � + + + � � +chr#143 � + + + � � +chr#144 � + + + � � +chr#145 � + + + � � +chr#146 � + + + � � +chr#147 � + + + � � +chr#148 � + + + � � +chr#149 � + + + � � +chr#150 � + + + � � +chr#151 � + + + � � +chr#152 � + + + � � +chr#153 � + + + � � +chr#154 + +chr#155 � + + + � � +chr#156 � + + + � � +chr#157 � + + + � � +chr#158 � + + + � � +chr#159 � + + + � � +chr#160 � + + + � � +chr#161 � + + + � � +chr#162 � + + + � � +chr#163 � + + + + + � � +chr#164 � + + + � � +chr#165 � + + + � � +chr#166 � + + + � � +chr#167 � + + + � � +chr#168 � + + + � � +chr#169 � + + + � � +chr#170 � + + + � � +chr#171 � + + + � � +chr#172 � + + + � � +chr#173 � + + + � � +chr#174 � + + + � � +chr#175 � + + + � � +chr#176 � + + + � � +chr#177 � + + + � � +chr#178 � + + + � � +chr#179 � + + + + + � � +chr#180 � + + + � � +chr#181 � + + + � � +chr#182 � + + + � � +chr#183 � + + + � � +chr#184 � + + + � � +chr#185 � + + + � � +chr#186 � + + + � � +chr#187 � + + + � � +chr#188 � + + + � � +chr#189 � + + + � � +chr#190 � + + + � � +chr#191 � + + + � � +chr#192 � + + + + + � � +chr#193 � + + + + + � � +chr#194 � + + + + + � � +chr#195 � + + + + + � � +chr#196 � + + + + + � � +chr#197 � + + + + + � � +chr#198 � + + + + + � � +chr#199 � + + + + + � � +chr#200 � + + + + + � � +chr#201 � + + + + + � � +chr#202 � + + + + + � � +chr#203 � + + + + + � � +chr#204 � + + + + + � � +chr#205 � + + + + + � � +chr#206 � + + + + + � � +chr#207 � + + + + + � � +chr#208 � + + + + + � � +chr#209 � + + + + + � � +chr#210 � + + + + + � � +chr#211 � + + + + + � � +chr#212 � + + + + + � � +chr#213 � + + + + + � � +chr#214 � + + + + + � � +chr#215 � + + + + + � � +chr#216 � + + + + + � � +chr#217 � + + + + + � � +chr#218 � + + + + + � � +chr#219 � + + + + + � � +chr#220 � + + + + + � � +chr#221 � + + + + + � � +chr#222 � + + + + + � � +chr#223 � + + + + + � +chr#224 � + + + + + � � +chr#225 � + + + + + � � +chr#226 � + + + + + � � +chr#227 � + + + + + � � +chr#228 � + + + + + � � +chr#229 � + + + + + � � +chr#230 � + + + + + � � +chr#231 � + + + + + � � +chr#232 � + + + + + � � +chr#233 � + + + + + � � +chr#234 � + + + + + � � +chr#235 � + + + + + � � +chr#236 � + + + + + � � +chr#237 � + + + + + � � +chr#238 � + + + + + � � +chr#239 � + + + + + � � +chr#240 � + + + + + � � +chr#241 � + + + + + � � +chr#242 � + + + + + � � +chr#243 � + + + + + � � +chr#244 � + + + + + � � +chr#245 � + + + + + � � +chr#246 � + + + + + � � +chr#247 � + + + + + � � +chr#248 � + + + + + � � +chr#249 � + + + + + � � +chr#250 � + + + + + � � +chr#251 � + + + + + � � +chr#252 � + + + + + � � +chr#253 � + + + + + � � +chr#254 � + + + + + � � +chr#255 + + + + + � diff --git a/src/test/locale/koi8-r/expected/test-koi8-char.sql.out b/src/test/locale/koi8-r/expected/test-koi8-char.sql.out new file mode 100644 index 00000000000..c574ff06776 --- /dev/null +++ b/src/test/locale/koi8-r/expected/test-koi8-char.sql.out @@ -0,0 +1,55 @@ +abbrev|name_en |name_ru +------+--------------------+------------------------------------------------------------ +ID |Idaho |������ +IA |Iowa |����� +AL |Alabama |������� +AK |Alaska |������ +AZ |Arizona |������� +AR |Arkansas |�������� +WY |Wyoming |�������� +WA |Washington |��������� +VT |Vermont |������� +VA |Virginia |��������� +WI |Wisconsin |��������� +DE |Delaware |������� +GA |Georgia |�������� +WV |West Virginia |�������� ��������� +IL |Illinois |�������� +IN |Indiana |������� +CA |California |���������� +KA |Kansas |������ +KY |Kentucky |�������� +CO |Colorado |�������� +CT |Connecticut |����������� +LA |Louisiana |�������� +MA |Massachusetts |����������� +MN |Minnesota |��������� +MS |Mississippi |��������� +MO |Missouri |������� +MI |Michigan |������� +MT |Montana |������� +ME |Maine |��� +MD |Maryland |�������� +NE |Nebraska |�������� +NV |Nevada |������ +NH |New Hampshire |���-������� +NJ |New Jersey |���-������ +NY |New York |���-���� +NM |New Mexico |���-������� +OH |Ohio |����� +OK |Oklahoma |�������� +DC |Washington DC |����� �������� (������ ���������� ��� �������) +OR |Oregon |������ +PA |Pennsylvania |������������ +RI |Rhode Island |���-������ +ND |North Dakota |�������� ������ +NC |North Carolina |�������� �������� +TN |Tennessee |�������� +TX |Texas |����� +FL |Florida |������� +SD |South Dakota |����� ������ +SC |South Carolina |����� �������� +UT |Utah |��� +(50 rows) + +EOF diff --git a/src/test/locale/koi8-r/expected/test-koi8-select.sql.out b/src/test/locale/koi8-r/expected/test-koi8-select.sql.out new file mode 100644 index 00000000000..1e9f97de3c6 --- /dev/null +++ b/src/test/locale/koi8-r/expected/test-koi8-select.sql.out @@ -0,0 +1,9 @@ +abbrev|name_en |name_ru +------+--------------------+---------------------------------------------- +OH |Ohio |����� +OK |Oklahoma |�������� +DC |Washington DC |����� �������� (������ ���������� ��� �������) +OR |Oregon |������ +(4 rows) + +EOF diff --git a/src/test/locale/koi8-r/expected/test-koi8-sort.out b/src/test/locale/koi8-r/expected/test-koi8-sort.out new file mode 100644 index 00000000000..0089f41b6a4 --- /dev/null +++ b/src/test/locale/koi8-r/expected/test-koi8-sort.out @@ -0,0 +1,9 @@ +Bording +hoarding +Vesta +vesta +������ +������ +����� +����� +�� diff --git a/src/test/locale/koi8-r/expected/test-koi8-text.sql.out b/src/test/locale/koi8-r/expected/test-koi8-text.sql.out new file mode 100644 index 00000000000..210a8e2b683 --- /dev/null +++ b/src/test/locale/koi8-r/expected/test-koi8-text.sql.out @@ -0,0 +1,55 @@ +abbrev|name_en |name_ru +------+--------------------+---------------------------------------------- +ID |Idaho |������ +IA |Iowa |����� +AL |Alabama |������� +AK |Alaska |������ +AZ |Arizona |������� +AR |Arkansas |�������� +WY |Wyoming |�������� +WA |Washington |��������� +VT |Vermont |������� +VA |Virginia |��������� +WI |Wisconsin |��������� +DE |Delaware |������� +GA |Georgia |�������� +WV |West Virginia |�������� ��������� +IL |Illinois |�������� +IN |Indiana |������� +CA |California |���������� +KA |Kansas |������ +KY |Kentucky |�������� +CO |Colorado |�������� +CT |Connecticut |����������� +LA |Louisiana |�������� +MA |Massachusetts |����������� +MN |Minnesota |��������� +MS |Mississippi |��������� +MO |Missouri |������� +MI |Michigan |������� +MT |Montana |������� +ME |Maine |��� +MD |Maryland |�������� +NE |Nebraska |�������� +NV |Nevada |������ +NH |New Hampshire |���-������� +NJ |New Jersey |���-������ +NY |New York |���-���� +NM |New Mexico |���-������� +OH |Ohio |����� +OK |Oklahoma |�������� +DC |Washington DC |����� �������� (������ ���������� ��� �������) +OR |Oregon |������ +PA |Pennsylvania |������������ +RI |Rhode Island |���-������ +ND |North Dakota |�������� ������ +NC |North Carolina |�������� �������� +TN |Tennessee |�������� +TX |Texas |����� +FL |Florida |������� +SD |South Dakota |����� ������ +SC |South Carolina |����� �������� +UT |Utah |��� +(50 rows) + +EOF diff --git a/src/test/locale/koi8-r/expected/test-koi8-varchar.sql.out b/src/test/locale/koi8-r/expected/test-koi8-varchar.sql.out new file mode 100644 index 00000000000..210a8e2b683 --- /dev/null +++ b/src/test/locale/koi8-r/expected/test-koi8-varchar.sql.out @@ -0,0 +1,55 @@ +abbrev|name_en |name_ru +------+--------------------+---------------------------------------------- +ID |Idaho |������ +IA |Iowa |����� +AL |Alabama |������� +AK |Alaska |������ +AZ |Arizona |������� +AR |Arkansas |�������� +WY |Wyoming |�������� +WA |Washington |��������� +VT |Vermont |������� +VA |Virginia |��������� +WI |Wisconsin |��������� +DE |Delaware |������� +GA |Georgia |�������� +WV |West Virginia |�������� ��������� +IL |Illinois |�������� +IN |Indiana |������� +CA |California |���������� +KA |Kansas |������ +KY |Kentucky |�������� +CO |Colorado |�������� +CT |Connecticut |����������� +LA |Louisiana |�������� +MA |Massachusetts |����������� +MN |Minnesota |��������� +MS |Mississippi |��������� +MO |Missouri |������� +MI |Michigan |������� +MT |Montana |������� +ME |Maine |��� +MD |Maryland |�������� +NE |Nebraska |�������� +NV |Nevada |������ +NH |New Hampshire |���-������� +NJ |New Jersey |���-������ +NY |New York |���-���� +NM |New Mexico |���-������� +OH |Ohio |����� +OK |Oklahoma |�������� +DC |Washington DC |����� �������� (������ ���������� ��� �������) +OR |Oregon |������ +PA |Pennsylvania |������������ +RI |Rhode Island |���-������ +ND |North Dakota |�������� ������ +NC |North Carolina |�������� �������� +TN |Tennessee |�������� +TX |Texas |����� +FL |Florida |������� +SD |South Dakota |����� ������ +SC |South Carolina |����� �������� +UT |Utah |��� +(50 rows) + +EOF diff --git a/src/test/locale/koi8-r/runall b/src/test/locale/koi8-r/runall new file mode 100755 index 00000000000..cf6e3b77c30 --- /dev/null +++ b/src/test/locale/koi8-r/runall @@ -0,0 +1,52 @@ +#! /bin/sh + +PATH=..:$PATH + +echo "Testing PostgreSQL compilation..." +if ! test-pgsql-locale; then + exit 1 +fi + +LC_CTYPE=ru_RU.KOI8-R +LC_COLLATE=$LC_CTYPE +export LC_CTYPE LC_COLLATE + +echo "Testing LC_CTYPE..." +if ! test-ctype > koi8-ctype.out; then + exit 1 +fi +diff expected/koi8-ctype.out koi8-ctype.out + +echo "Testing LC_COLLATE..." +perl ../sort-test.pl test-koi8-sort.in > test-koi8-sort.out +diff expected/test-koi8-sort.out test-koi8-sort.out + +### If you have Python - uncomment the following two lines +#python ../sort-test.py test-koi8-sort.in > test-koi8-sort.out +#diff expected/test-koi8-sort.out test-koi8-sort.out + + +abort() { + [ "$1" ] && echo "$*" + exit 1 +} + +for f in char varchar text; do + if echo $f | grep -q char; then + ftype="$f(60)" + else + ftype="$f" + fi + echo "Testing PgSQL: sort on $ftype type..." + + destroydb testlocale >/dev/null 2>&1 + createdb testlocale || abort "createdb failed" + psql -d testlocale -c "CREATE TABLE usastates (abbrev char2, name_en char(20), name_ru $ftype);" >/dev/null 2>&1 || abort "createtable failed" + psql testlocale < test-koi8.sql.in > test-koi8-$f.sql.out 2>/dev/null || abort "test query failed" + diff expected/test-koi8-$f.sql.out test-koi8-$f.sql.out +done +echo "Testing PgSQL: select on regexp..." +psql testlocale < test-koi8-select.sql.in > test-koi8-select.sql.out 2>/dev/null || abort "select query failed" +diff expected/test-koi8-select.sql.out test-koi8-select.sql.out +destroydb testlocale || abort "destroydb failed" +echo "Finished." diff --git a/src/test/locale/koi8-r/test-koi8-select.sql.in b/src/test/locale/koi8-r/test-koi8-select.sql.in new file mode 100644 index 00000000000..5cda505c3d2 --- /dev/null +++ b/src/test/locale/koi8-r/test-koi8-select.sql.in @@ -0,0 +1 @@ +SELECT * FROM usastates WHERE name_ru ~* '^�.*' ORDER BY name_ru; diff --git a/src/test/locale/koi8-r/test-koi8-sort.in b/src/test/locale/koi8-r/test-koi8-sort.in new file mode 100644 index 00000000000..3394e59d619 --- /dev/null +++ b/src/test/locale/koi8-r/test-koi8-sort.in @@ -0,0 +1,9 @@ +Vesta +vesta +�� +������ +������ +����� +����� +Bording +hoarding diff --git a/src/test/locale/koi8-r/test-koi8.sql.in b/src/test/locale/koi8-r/test-koi8.sql.in new file mode 100644 index 00000000000..784d440d2f3 --- /dev/null +++ b/src/test/locale/koi8-r/test-koi8.sql.in @@ -0,0 +1,53 @@ +COPY usastates FROM stdin USING DELIMITERS '|'; +AK|Alaska |������ +WA|Washington |��������� +OR|Oregon |������ +CA|California |���������� +NV|Nevada |������ +ID|Idaho |������ +UT|Utah |��� +AZ|Arizona |������� +MT|Montana |������� +WY|Wyoming |�������� +CO|Colorado |�������� +NM|New Mexico |���-������� +ND|North Dakota |�������� ������ +SD|South Dakota |����� ������ +NE|Nebraska |�������� +KA|Kansas |������ +OK|Oklahoma |�������� +TX|Texas |����� +MN|Minnesota |��������� +IA|Iowa |����� +MO|Missouri |������� +AR|Arkansas |�������� +LA|Louisiana |�������� +WI|Wisconsin |��������� +IL|Illinois |�������� +IN|Indiana |������� +MS|Mississippi |��������� +AL|Alabama |������� +MI|Michigan |������� +OH|Ohio |����� +KY|Kentucky |�������� +TN|Tennessee |�������� +GA|Georgia |�������� +FL|Florida |������� +PA|Pennsylvania |������������ +WV|West Virginia |�������� ��������� +VA|Virginia |��������� +NC|North Carolina|�������� �������� +SC|South Carolina|����� �������� +NY|New York |���-���� +NJ|New Jersey |���-������ +DE|Delaware |������� +MD|Maryland |�������� +DC|Washington DC |����� �������� (������ ���������� ��� �������) +VT|Vermont |������� +MA|Massachusetts |����������� +CT|Connecticut |����������� +ME|Maine |��� +NH|New Hampshire |���-������� +RI|Rhode Island |���-������ +\. +SELECT * FROM usastates ORDER BY name_ru; diff --git a/src/test/locale/sort-test.pl b/src/test/locale/sort-test.pl new file mode 100755 index 00000000000..7d9b8ef0340 --- /dev/null +++ b/src/test/locale/sort-test.pl @@ -0,0 +1,12 @@ +#!/usr/local/bin/perl -w +use locale; + +open(INFILE, "<$ARGV[0]"); +chop(my(@words) = <INFILE>); +close(INFILE); + +$"="\n"; +my(@result) = sort @words; + +print "@result\n"; + diff --git a/src/test/locale/sort-test.py b/src/test/locale/sort-test.py new file mode 100755 index 00000000000..112dd2d5f75 --- /dev/null +++ b/src/test/locale/sort-test.py @@ -0,0 +1,18 @@ +#! /usr/local/bin/python + +import sys, string, locale +locale.setlocale(locale.LC_ALL, "") + +if len(sys.argv) <> 2: + sys.stderr.write("Usage: sort.py filename\n") + sys.exit(1) + +infile = open(sys.argv[1], 'r') +list = infile.readlines() +infile.close() + +for i in range(0, len(list)): + list[i] = list[i][:-1] # chop! + +list.sort(locale.strcoll) +print string.join(list, '\n') diff --git a/src/test/locale/test-ctype.c b/src/test/locale/test-ctype.c new file mode 100644 index 00000000000..c16f1710928 --- /dev/null +++ b/src/test/locale/test-ctype.c @@ -0,0 +1,65 @@ + +/* + + test-ctype.c + +Written by Oleg BroytMann, [email protected] + with help from Oleg Bartunov, [email protected] +Copyright (C) 1998 PhiloSoft Design + +This is copyrighted but free software. You can use it, modify and distribute +in original or modified form providing that the author's names and the above +copyright notice will remain. + +Disclaimer, legal notice and absence of warranty. + This software provided "as is" without any kind of warranty. In no event +the author shall be liable for any damage, etc. + +*/ + +#include <stdio.h> +#include <locale.h> +#include <ctype.h> + +char * flag(int b); +void describe_char(int c); + +#undef LONG_FLAG + +char * flag(int b) +{ +#ifdef LONG_FLAG + return b ? "yes" : "no"; +#else + return b ? "+" : " "; +#endif +} + +void describe_char(int c) +{ + char cp = c, up = toupper(c), lo = tolower(c); + if (!isprint(cp)) cp = ' '; + if (!isprint(up)) up = ' '; + if (!isprint(lo)) lo = ' '; + + printf("chr#%-4d%2c%6s%6s%6s%6s%6s%6s%6s%6s%6s%6s%6s%4c%4c\n", c, cp, flag(isalnum(c)), flag(isalpha(c)), flag(iscntrl(c)), flag(isdigit(c)), flag(islower(c)), flag(isgraph(c)), flag(isprint(c)), flag(ispunct(c)), flag(isspace(c)), flag(isupper(c)), flag(isxdigit(c)), lo, up); +} + +int main() { + short c; + char * cur_locale; + + cur_locale = setlocale(LC_ALL, ""); + if (cur_locale) { + fprintf(stderr, "Successfulle set locale to %s\n", cur_locale); + } else { + fprintf(stderr, "Cannot setup locale. Either your libc does not provide\nlocale support, or your locale data is corrupt, or you have not set\nLANG or LC_CTYPE environment variable to proper value. Program aborted.\n"); + return 1; + } + + printf("char# char alnum alpha cntrl digit lower graph print punct space upper xdigit lo up\n"); + for (c = 0; c <= 255; c++) + describe_char(c); + + return 0; +} diff --git a/src/test/locale/test-pgsql-locale.c b/src/test/locale/test-pgsql-locale.c new file mode 100644 index 00000000000..acae1a2aeec --- /dev/null +++ b/src/test/locale/test-pgsql-locale.c @@ -0,0 +1,13 @@ + +#include <stdio.h> +#include "postgres.h" + +int main() { + #ifdef USE_LOCALE + printf("PostgreSQL compiled with locale support\n"); + return 0; + #else + printf("PostgreSQL compiled without locale support\n"); + return 1; + #endif +} |