I have committed many support files for CREATE CONVERSION. Default

conversion procs and conversions are added in initdb. Currently
supported conversions are:

UTF-8(UNICODE) <--> SQL_ASCII, ISO-8859-1 to 16, EUC_JP, EUC_KR,
		    EUC_CN, EUC_TW, SJIS, BIG5, GBK, GB18030, UHC,
		    JOHAB, TCVN

EUC_JP <--> SJIS
EUC_TW <--> BIG5
MULE_INTERNAL <--> EUC_JP, SJIS, EUC_TW, BIG5

Note that initial contents of pg_conversion system catalog are created
in the initdb process. So doing initdb required is ideal, it's
possible to add them to your databases by hand, however. To accomplish
this:

psql -f your_postgresql_install_path/share/conversion_create.sql your_database

So I did not bump up the version in cataversion.h.

TODO:
Add more conversion procs
Add [CASCADE|RESTRICT] to DROP CONVERSION
Add tuples to pg_depend
Add regression tests
Write docs
Add SQL99 CONVERT command?
--
Tatsuo Ishii
This commit is contained in:
Tatsuo Ishii 2002-07-18 02:02:30 +00:00
parent df432df9fa
commit eb335a034b
13 changed files with 173 additions and 2276 deletions

View File

@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.80 2002/07/16 05:46:35 momjian Exp $
# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.81 2002/07/18 02:02:29 ishii Exp $
#
#-------------------------------------------------------------------------
@ -131,6 +131,7 @@ endif
ifeq ($(enable_nls), yes)
$(MAKE) -C po $@
endif
$(MAKE) -C utils/mb $@
install-bin: postgres $(POSTGRES_IMP) installdirs
$(INSTALL_PROGRAM) postgres$(X) $(DESTDIR)$(bindir)/postgres$(X)

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.69 2002/06/20 20:29:27 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.70 2002/07/18 02:02:29 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@ -27,15 +27,7 @@
#include "utils/guc.h"
#include "utils/syscache.h"
#include "utils/tqual.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#else
/* Grand unified hard-coded badness */
#define pg_get_client_encoding_name() "SQL_ASCII"
#define GetDatabaseEncodingName() "SQL_ASCII"
#endif
/*
* DATESTYLE
@ -472,43 +464,30 @@ show_random_seed(void)
/*
* MULTIBYTE-related functions
*
* If MULTIBYTE support was not compiled, we still allow these variables
* to exist, but you can't set them to anything but "SQL_ASCII". This
* minimizes interoperability problems between non-MB servers and MB-enabled
* clients.
* encoding handling functions
*/
const char *
assign_client_encoding(const char *value, bool doit, bool interactive)
{
#ifdef MULTIBYTE
int encoding;
int old_encoding = 0;
encoding = pg_valid_client_encoding(value);
if (encoding < 0)
return NULL;
/*
* Ugly API here ... can't test validity without setting new encoding...
/* XXX SetClientEncoding depends on namespace functions which are
* not available at startup time. So we accept requested client
* encoding anyway which might not be valid (e.g. no conversion
* procs available).
*/
if (!doit)
old_encoding = pg_get_client_encoding();
if (pg_set_client_encoding(encoding) < 0)
if (SetClientEncoding(encoding, doit) < 0)
{
if (interactive)
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
return NULL;
}
if (!doit)
pg_set_client_encoding(old_encoding);
#else
if (strcasecmp(value, pg_get_client_encoding_name()) != 0)
return NULL;
#endif
return value;
}

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.341 2002/07/16 22:12:20 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.342 2002/07/18 02:02:30 ishii Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@ -62,13 +62,7 @@
#include "utils/numeric.h"
#include "utils/datetime.h"
#include "utils/date.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#else
#define GetStandardEncoding() 0 /* PG_SQL_ASCII */
#define GetStandardEncodingName() "SQL_ASCII"
#endif
extern List *parsetree; /* final parse result is delivered here */
@ -3570,28 +3564,23 @@ createdb_opt_item:
| ENCODING opt_equal Sconst
{
int encoding;
#ifdef MULTIBYTE
encoding = pg_char_to_encoding($3);
if (encoding == -1)
if (pg_valid_server_encoding($3) < 0)
elog(ERROR, "%s is not a valid encoding name", $3);
#else
if (strcasecmp($3, GetStandardEncodingName()) != 0)
elog(ERROR, "Multi-byte support is not enabled");
encoding = GetStandardEncoding();
#endif
encoding = pg_char_to_encoding($3);
$$ = makeNode(DefElem);
$$->defname = "encoding";
$$->arg = (Node *)makeInteger(encoding);
}
| ENCODING opt_equal Iconst
{
#ifdef MULTIBYTE
if (!pg_get_enconv_by_encoding($3))
const char *encoding_name;
encoding_name = pg_encoding_to_char($3);
if (!strcmp(encoding_name,"") ||
pg_valid_server_encoding(encoding_name) < 0)
elog(ERROR, "%d is not a valid encoding code", $3);
#else
if ($3 != GetStandardEncoding())
elog(ERROR, "Multi-byte support is not enabled");
#endif
$$ = makeNode(DefElem);
$$->defname = "encoding";
$$->arg = (Node *)makeInteger($3);

View File

@ -4,7 +4,7 @@
# Makefile for utils/mb
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.17 2001/09/22 08:44:47 ishii Exp $
# $Header: /cvsroot/pgsql/src/backend/utils/mb/Makefile,v 1.18 2002/07/18 02:02:30 ishii Exp $
#
#-------------------------------------------------------------------------
@ -12,19 +12,23 @@ subdir = src/backend/utils/mb
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
OBJS = encnames.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o big5.o
OBJS = encnames.o conv.o mbutils.o wchar.o wstrcmp.o wstrncmp.o
DIRS = conversion_procs
all: SUBSYS.o
all install installdirs uninstal distprep: SUBSYS.o
@for dir in $(DIRS); do $(MAKE) -C $$dir $@ || exit; done
clean distclean maintainer-clean:
rm -f SUBSYS.o $(OBJS)
@for dir in $(DIRS); do $(MAKE) -C $$dir $@; done
SUBSYS.o: $(OBJS)
@for dir in $(DIRS); do $(MAKE) -C $$dir all || exit; done
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
depend dep:
$(CC) -MM $(CFLAGS) *.c >depend
clean:
rm -f SUBSYS.o $(OBJS)
ifeq (depend,$(wildcard depend))
include depend
endif

View File

@ -1,378 +0,0 @@
/*
* conversion between BIG5 and Mule Internal Code(CNS 116643-1992
* plane 1 and plane 2).
* This program is partially copied from lv(Multilingual file viewer)
* and slightly modified. lv is written and copyrighted by NARITA Tomio
* (nrt@web.ad.jp).
*
* 1999/1/15 Tatsuo Ishii
*
* $Id: big5.c,v 1.8 2001/10/25 05:49:51 momjian Exp $
*/
/* can be used in either frontend or backend */
#include "postgres_fe.h"
#include "mb/pg_wchar.h"
typedef struct
{
unsigned short code,
peer;
} codes_t;
/* map Big5 Level 1 to CNS 11643-1992 Plane 1 */
static codes_t big5Level1ToCnsPlane1[25] = { /* range */
{0xA140, 0x2121},
{0xA1F6, 0x2258},
{0xA1F7, 0x2257},
{0xA1F8, 0x2259},
{0xA2AF, 0x2421},
{0xA3C0, 0x4221},
{0xa3e1, 0x0000},
{0xA440, 0x4421},
{0xACFE, 0x5753},
{0xacff, 0x0000},
{0xAD40, 0x5323},
{0xAFD0, 0x5754},
{0xBBC8, 0x6B51},
{0xBE52, 0x6B50},
{0xBE53, 0x6F5C},
{0xC1AB, 0x7536},
{0xC2CB, 0x7535},
{0xC2CC, 0x7737},
{0xC361, 0x782E},
{0xC3B9, 0x7865},
{0xC3BA, 0x7864},
{0xC3BB, 0x7866},
{0xC456, 0x782D},
{0xC457, 0x7962},
{0xc67f, 0x0000}
};
/* map CNS 11643-1992 Plane 1 to Big5 Level 1 */
static codes_t cnsPlane1ToBig5Level1[26] = { /* range */
{0x2121, 0xA140},
{0x2257, 0xA1F7},
{0x2258, 0xA1F6},
{0x2259, 0xA1F8},
{0x234f, 0x0000},
{0x2421, 0xA2AF},
{0x2571, 0x0000},
{0x4221, 0xA3C0},
{0x4242, 0x0000},
{0x4421, 0xA440},
{0x5323, 0xAD40},
{0x5753, 0xACFE},
{0x5754, 0xAFD0},
{0x6B50, 0xBE52},
{0x6B51, 0xBBC8},
{0x6F5C, 0xBE53},
{0x7535, 0xC2CB},
{0x7536, 0xC1AB},
{0x7737, 0xC2CC},
{0x782D, 0xC456},
{0x782E, 0xC361},
{0x7864, 0xC3BA},
{0x7865, 0xC3B9},
{0x7866, 0xC3BB},
{0x7962, 0xC457},
{0x7d4c, 0x0000}
};
/* map Big5 Level 2 to CNS 11643-1992 Plane 2 */
static codes_t big5Level2ToCnsPlane2[48] = { /* range */
{0xC940, 0x2121},
{0xc94a, 0x0000},
{0xC94B, 0x212B},
{0xC96C, 0x214D},
{0xC9BE, 0x214C},
{0xC9BF, 0x217D},
{0xC9ED, 0x224E},
{0xCAF7, 0x224D},
{0xCAF8, 0x2439},
{0xD77A, 0x3F6A},
{0xD77B, 0x387E},
{0xDBA7, 0x3F6B},
{0xDDFC, 0x4176},
{0xDDFD, 0x4424},
{0xE8A3, 0x554C},
{0xE976, 0x5723},
{0xEB5B, 0x5A29},
{0xEBF1, 0x554B},
{0xEBF2, 0x5B3F},
{0xECDE, 0x5722},
{0xECDF, 0x5C6A},
{0xEDAA, 0x5D75},
{0xEEEB, 0x642F},
{0xEEEC, 0x6039},
{0xF056, 0x5D74},
{0xF057, 0x6243},
{0xF0CB, 0x5A28},
{0xF0CC, 0x6337},
{0xF163, 0x6430},
{0xF16B, 0x6761},
{0xF16C, 0x6438},
{0xF268, 0x6934},
{0xF269, 0x6573},
{0xF2C3, 0x664E},
{0xF375, 0x6762},
{0xF466, 0x6935},
{0xF4B5, 0x664D},
{0xF4B6, 0x6962},
{0xF4FD, 0x6A4C},
{0xF663, 0x6A4B},
{0xF664, 0x6C52},
{0xF977, 0x7167},
{0xF9C4, 0x7166},
{0xF9C5, 0x7234},
{0xF9C6, 0x7240},
{0xF9C7, 0x7235},
{0xF9D2, 0x7241},
{0xf9d6, 0x0000}
};
/* map CNS 11643-1992 Plane 2 to Big5 Level 2 */
static codes_t cnsPlane2ToBig5Level2[49] = { /* range */
{0x2121, 0xC940},
{0x212B, 0xC94B},
{0x214C, 0xC9BE},
{0x214D, 0xC96C},
{0x217D, 0xC9BF},
{0x224D, 0xCAF7},
{0x224E, 0xC9ED},
{0x2439, 0xCAF8},
{0x387E, 0xD77B},
{0x3F6A, 0xD77A},
{0x3F6B, 0xDBA7},
{0x4424, 0x0000},
{0x4176, 0xDDFC},
{0x4177, 0x0000},
{0x4424, 0xDDFD},
{0x554B, 0xEBF1},
{0x554C, 0xE8A3},
{0x5722, 0xECDE},
{0x5723, 0xE976},
{0x5A28, 0xF0CB},
{0x5A29, 0xEB5B},
{0x5B3F, 0xEBF2},
{0x5C6A, 0xECDF},
{0x5D74, 0xF056},
{0x5D75, 0xEDAA},
{0x6039, 0xEEEC},
{0x6243, 0xF057},
{0x6337, 0xF0CC},
{0x642F, 0xEEEB},
{0x6430, 0xF163},
{0x6438, 0xF16C},
{0x6573, 0xF269},
{0x664D, 0xF4B5},
{0x664E, 0xF2C3},
{0x6761, 0xF16B},
{0x6762, 0xF375},
{0x6934, 0xF268},
{0x6935, 0xF466},
{0x6962, 0xF4B6},
{0x6A4B, 0xF663},
{0x6A4C, 0xF4FD},
{0x6C52, 0xF664},
{0x7166, 0xF9C4},
{0x7167, 0xF977},
{0x7234, 0xF9C5},
{0x7235, 0xF9C7},
{0x7240, 0xF9C6},
{0x7241, 0xF9D2},
{0x7245, 0x0000}
};
/* Big Five Level 1 Correspondence to CNS 11643-1992 Plane 4 */
static unsigned short b1c4[][2] = {
{0xC879, 0x2123},
{0xC87B, 0x2124},
{0xC87D, 0x212A},
{0xC8A2, 0x2152}
};
/* Big Five Level 2 Correspondence to CNS 11643-1992 Plane 3 */
static unsigned short b2c3[][2] = {
{0xF9D6, 0x4337},
{0xF9D7, 0x4F50},
{0xF9D8, 0x444E},
{0xF9D9, 0x504A},
{0xF9DA, 0x2C5D},
{0xF9DB, 0x3D7E},
{0xF9DC, 0x4B5C}
};
static unsigned short BinarySearchRange
(codes_t *array, int high, unsigned short code)
{
int low,
mid,
distance,
tmp;
low = 0;
mid = high >> 1;
for (; low <= high; mid = (low + high) >> 1)
{
if ((array[mid].code <= code) && (array[mid + 1].code > code))
{
if (0 == array[mid].peer)
return 0;
if (code >= 0xa140U)
{
/* big5 to cns */
tmp = ((code & 0xff00) - (array[mid].code & 0xff00)) >> 8;
high = code & 0x00ff;
low = array[mid].code & 0x00ff;
/*
* NOTE: big5 high_byte: 0xa1-0xfe, low_byte: 0x40-0x7e,
* 0xa1-0xfe (radicals: 0x00-0x3e, 0x3f-0x9c) big5 radix
* is 0x9d. [region_low, region_high]
* We should remember big5 has two different regions
* (above). There is a bias for the distance between these
* regions. 0xa1 - 0x7e + bias = 1 (Distance between 0xa1
* and 0x7e is 1.) bias = - 0x22.
*/
distance = tmp * 0x9d + high - low +
(high >= 0xa1 ? (low >= 0xa1 ? 0 : -0x22)
: (low >= 0xa1 ? +0x22 : 0));
/*
* NOTE: we have to convert the distance into a code
* point. The code point's low_byte is 0x21 plus mod_0x5e.
* In the first, we extract the mod_0x5e of the starting
* code point, subtracting 0x21, and add distance to it.
* Then we calculate again mod_0x5e of them, and restore
* the final codepoint, adding 0x21.
*/
tmp = (array[mid].peer & 0x00ff) + distance - 0x21;
tmp = (array[mid].peer & 0xff00) + ((tmp / 0x5e) << 8)
+ 0x21 + tmp % 0x5e;
return tmp;
}
else
{
/* cns to big5 */
tmp = ((code & 0xff00) - (array[mid].code & 0xff00)) >> 8;
/*
* NOTE: ISO charsets ranges between 0x21-0xfe
* (94charset). Its radix is 0x5e. But there is no
* distance bias like big5.
*/
distance = tmp * 0x5e
+ ((int) (code & 0x00ff) - (int) (array[mid].code & 0x00ff));
/*
* NOTE: Similar to big5 to cns conversion, we extract
* mod_0x9d and restore mod_0x9d into a code point.
*/
low = array[mid].peer & 0x00ff;
tmp = low + distance - (low >= 0xa1 ? 0x62 : 0x40);
low = tmp % 0x9d;
tmp = (array[mid].peer & 0xff00) + ((tmp / 0x9d) << 8)
+ (low > 0x3e ? 0x62 : 0x40) + low;
return tmp;
}
}
else if (array[mid].code > code)
high = mid - 1;
else
low = mid + 1;
}
return 0;
}
unsigned short
BIG5toCNS(unsigned short big5, unsigned char *lc)
{
unsigned short cns = 0;
int i;
if (big5 < 0xc940U)
{
/* level 1 */
for (i = 0; i < sizeof(b1c4) / sizeof(unsigned short); i++)
{
if (b1c4[i][0] == big5)
{
*lc = LC_CNS11643_4;
return (b1c4[i][1] | 0x8080U);
}
}
if (0 < (cns = BinarySearchRange(big5Level1ToCnsPlane1, 23, big5)))
*lc = LC_CNS11643_1;
}
else if (big5 == 0xc94aU)
{
/* level 2 */
*lc = LC_CNS11643_1;
cns = 0x4442;
}
else
{
/* level 2 */
for (i = 0; i < sizeof(b2c3) / sizeof(unsigned short); i++)
{
if (b2c3[i][0] == big5)
{
*lc = LC_CNS11643_3;
return (b2c3[i][1] | 0x8080U);
}
}
if (0 < (cns = BinarySearchRange(big5Level2ToCnsPlane2, 46, big5)))
*lc = LC_CNS11643_2;
}
if (0 == cns)
{ /* no mapping Big5 to CNS 11643-1992 */
*lc = 0;
return (unsigned short) '?';
}
return cns | 0x8080;
}
unsigned short
CNStoBIG5(unsigned short cns, unsigned char lc)
{
int i;
unsigned int big5 = 0;
cns &= 0x7f7f;
switch (lc)
{
case LC_CNS11643_1:
big5 = BinarySearchRange(cnsPlane1ToBig5Level1, 24, cns);
break;
case LC_CNS11643_2:
big5 = BinarySearchRange(cnsPlane2ToBig5Level2, 47, cns);
break;
case LC_CNS11643_3:
for (i = 0; i < sizeof(b2c3) / sizeof(unsigned short); i++)
{
if (b2c3[i][1] == cns)
return (b2c3[i][0]);
}
break;
case LC_CNS11643_4:
for (i = 0; i < sizeof(b1c4) / sizeof(unsigned short); i++)
{
if (b1c4[i][1] == cns)
return (b1c4[i][0]);
}
default:
break;
}
return big5;
}

File diff suppressed because it is too large Load Diff

View File

@ -3,136 +3,65 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: mbutils.c,v 1.27 2001/11/20 01:32:29 ishii Exp $
* $Id: mbutils.c,v 1.28 2002/07/18 02:02:30 ishii Exp $
*/
#include "postgres.h"
#include "miscadmin.h"
#include "mb/pg_wchar.h"
#include "utils/builtins.h"
#include "utils/syscache.h"
#include "catalog/namespace.h"
/*
* We handle for actual FE and BE encoding setting encoding-identificator
* and encoding-name too. It prevent searching and conversion from encoding
* to encoding name in getdatabaseencoding() and other routines.
*
* Default is PG_SQL_ASCII encoding (but this is never used, because
* backend during startup init it by SetDatabaseEncoding()).
*
* Karel Zak (Aug 2001)
*/
static pg_enc2name *ClientEncoding = &pg_enc2name_tbl[PG_SQL_ASCII];
static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[PG_SQL_ASCII];
static to_mic_converter client_to_mic; /* something to MIC */
static from_mic_converter client_from_mic; /* MIC to something */
static to_mic_converter server_to_mic; /* something to MIC */
static from_mic_converter server_from_mic; /* MIC to something */
/*
* find encoding table entry by encoding
*/
pg_enconv *
pg_get_enconv_by_encoding(int encoding)
{
if (PG_VALID_ENCODING(encoding))
{
Assert((&pg_enconv_tbl[encoding])->encoding == encoding);
return &pg_enconv_tbl[encoding];
}
return 0;
}
/*
* Find appropriate encoding conversion functions. If no such
* functions found, returns -1.
*
* Arguments:
*
* src, dest (in): source and destination encoding ids
*
* src_to_mic (out): pointer to a function which converts src to
* mic/unicode according to dest. if src == mic/unicode or no
* appropriate function found, set to 0.
*
* dest_from_mic (out): pointer to a function which converts
* mic/unicode to dest according to src. if dest == mic/unicode or no
* appropriate function found, set to 0.
*/
int
pg_find_encoding_converters(int src, int dest,
to_mic_converter *src_to_mic,
from_mic_converter *dest_from_mic)
{
if (src == dest)
{ /* src == dest? */
*src_to_mic = *dest_from_mic = 0;
}
else if (src == PG_MULE_INTERNAL)
{ /* src == MULE_INETRNAL? */
*dest_from_mic = pg_get_enconv_by_encoding(dest)->from_mic;
if (*dest_from_mic == 0)
return (-1);
*src_to_mic = 0;
}
else if (dest == PG_MULE_INTERNAL)
{ /* dest == MULE_INETRNAL? */
*src_to_mic = pg_get_enconv_by_encoding(src)->to_mic;
if (*src_to_mic == 0)
return (-1);
*dest_from_mic = 0;
}
else if (src == PG_UTF8)
{ /* src == UNICODE? */
*dest_from_mic = pg_get_enconv_by_encoding(dest)->from_unicode;
if (*dest_from_mic == 0)
return (-1);
*src_to_mic = 0;
}
else if (dest == PG_UTF8)
{ /* dest == UNICODE? */
*src_to_mic = pg_get_enconv_by_encoding(src)->to_unicode;
if (*src_to_mic == 0)
return (-1);
*dest_from_mic = 0;
}
else
{
*src_to_mic = pg_get_enconv_by_encoding(src)->to_mic;
*dest_from_mic = pg_get_enconv_by_encoding(dest)->from_mic;
if (*src_to_mic == 0 || *dest_from_mic == 0)
return (-1);
}
return (0);
}
/*
* set the client encoding. if encoding conversion between
* client/server encoding is not supported, returns -1
*/
int
pg_set_client_encoding(int encoding)
SetClientEncoding(int encoding, bool doit)
{
int current_server_encoding = DatabaseEncoding->encoding;
int current_server_encoding;
current_server_encoding = GetDatabaseEncoding();
if (!PG_VALID_FE_ENCODING(encoding))
return (-1);
if (pg_find_encoding_converters(encoding, current_server_encoding, &client_to_mic, &server_from_mic) < 0)
return (-1);
if (current_server_encoding == encoding)
{
ClientEncoding = &pg_enc2name_tbl[encoding];
return 0;
}
/* XXX We cannot use FindDefaultConversionProc() while in
* bootstrap or initprocessing mode since namespace functions will
* not work.
*/
if (IsNormalProcessingMode())
{
if (!OidIsValid(FindDefaultConversionProc(encoding, current_server_encoding)) ||
!OidIsValid(FindDefaultConversionProc(current_server_encoding, encoding)))
return (-1);
}
if (!doit)
return 0;
ClientEncoding = &pg_enc2name_tbl[encoding];
Assert(ClientEncoding->encoding == encoding);
if (pg_find_encoding_converters(current_server_encoding, encoding, &server_to_mic, &client_from_mic) < 0)
return (-1);
return 0;
}
/*
* returns the current client encoding
*/
* returns the current client encoding */
int
pg_get_client_encoding(void)
{
@ -151,55 +80,61 @@ pg_get_client_encoding_name(void)
}
/*
* Convert src encoding and returns it. Actual conversion is done by
* src_to_mic and dest_from_mic, which can be obtained by
* pg_find_encoding_converters(). The reason we require two conversion
* functions is that we have an intermediate encoding: MULE_INTERNAL
* Using intermediate encodings will reduce the number of functions
* doing encoding conversions. Special case is either src or dest is
* the intermediate encoding itself. In this case, you don't need src
* or dest (setting 0 will indicate there's no conversion
* function). Another case is you have direct-conversion function from
* src to dest. In this case either src_to_mic or dest_from_mic could
* be set to 0 also.
* Apply encoding conversion on src and return it. The encoding
* conversion function is chosen from the pg_conversion system catalog
* marked as "default". If it is not found in the schema search path,
* it's taken from pg_catalog schema. If it even is not in the schema,
* warn and returns src. We cannot raise an error, since it will cause
* an infinit loop in error message sending.
*
* Note that If src or dest is UNICODE, we have to do
* direct-conversion, since we don't support conversion bwteen UNICODE
* and MULE_INTERNAL, we cannot go through MULE_INTERNAL.
* In the case of no coversion, src is returned.
*
* CASE 1: if no conversion is required, then the given pointer s is returned.
*
* CASE 2: if conversion is required, a palloc'd string is returned.
*
* Callers must check whether return value differs from passed value
* to determine whether to pfree the result or not!
*
* Note: we assume that conversion cannot cause more than a 4-to-1 growth
* in the length of the string --- is this enough? */
* XXX We assume that storage for converted result is 4-to-1 growth in
* the worst case. The rate for currently supported encoding pares are within 3
* (SJIS JIS X0201 half width kanna -> UTF-8 is the worst case).
* So "4" should be enough for the moment.
*/
unsigned char *
pg_do_encoding_conversion(unsigned char *src, int len,
to_mic_converter src_to_mic,
from_mic_converter dest_from_mic)
int src_encoding, int dest_encoding)
{
unsigned char *result = src;
unsigned char *buf;
unsigned char *result;
Oid proc;
if (src_to_mic)
if (src_encoding == dest_encoding)
return src;
proc = FindDefaultConversionProc(src_encoding, dest_encoding);
if (!OidIsValid(proc))
{
buf = (unsigned char *) palloc(len * 4 + 1);
(*src_to_mic) (result, buf, len);
result = buf;
len = strlen(result);
elog(LOG, "default conversion proc for %s to %s not found",
pg_encoding_to_char(src_encoding), pg_encoding_to_char(dest_encoding));
return src;
}
if (dest_from_mic)
/* XXX we shoud avoid throwing errors in OidFuctionCall. Otherwise
* we are going into inifinite loop! So we have to make sure that
* the function exists before calling OidFunctionCall.
*/
if (!SearchSysCacheExists(PROCOID,
ObjectIdGetDatum(proc),
0, 0, 0))
{
buf = (unsigned char *) palloc(len * 4 + 1);
(*dest_from_mic) (result, buf, len);
if (result != src)
pfree(result); /* release first buffer */
result = buf;
elog(LOG, "default conversion proc %u for %s to %s not found in pg_proc",
proc,
pg_encoding_to_char(src_encoding), pg_encoding_to_char(dest_encoding));
return src;
}
result = palloc(len * 4 + 1);
OidFunctionCall5(proc,
Int32GetDatum(src_encoding),
Int32GetDatum(dest_encoding),
CStringGetDatum(src),
CStringGetDatum(result),
Int32GetDatum(len));
return result;
}
@ -207,8 +142,7 @@ pg_do_encoding_conversion(unsigned char *src, int len,
* Convert string using encoding_nanme. We assume that string's
* encoding is same as DB encoding.
*
* TEXT convert(TEXT string, NAME encoding_name)
*/
* TEXT convert(TEXT string, NAME encoding_name) */
Datum
pg_convert(PG_FUNCTION_ARGS)
{
@ -230,7 +164,7 @@ pg_convert(PG_FUNCTION_ARGS)
/*
* Convert string using encoding_nanme.
*
* TEXT convert(TEXT string, NAME src_encoding_name, NAME dest_encoding_name)
* TEXT convert2(TEXT string, NAME src_encoding_name, NAME dest_encoding_name)
*/
Datum
pg_convert2(PG_FUNCTION_ARGS)
@ -240,8 +174,6 @@ pg_convert2(PG_FUNCTION_ARGS)
int src_encoding = pg_char_to_encoding(src_encoding_name);
char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
int dest_encoding = pg_char_to_encoding(dest_encoding_name);
to_mic_converter src;
from_mic_converter dest;
unsigned char *result;
text *retval;
unsigned char *str;
@ -252,19 +184,13 @@ pg_convert2(PG_FUNCTION_ARGS)
if (dest_encoding < 0)
elog(ERROR, "Invalid destination encoding name %s", dest_encoding_name);
if (pg_find_encoding_converters(src_encoding, dest_encoding, &src, &dest) < 0)
{
elog(ERROR, "Conversion from %s to %s is not possible",
src_encoding_name, dest_encoding_name);
}
/* make sure that source string is null terminated */
len = VARSIZE(string) - VARHDRSZ;
str = palloc(len + 1);
memcpy(str, VARDATA(string), len);
*(str + len) = '\0';
result = pg_do_encoding_conversion(str, len, src, dest);
result = pg_do_encoding_conversion(str, len, src_encoding, dest_encoding);
if (result == NULL)
elog(ERROR, "Encoding conversion failed");
@ -288,16 +214,6 @@ pg_convert2(PG_FUNCTION_ARGS)
/*
* convert client encoding to server encoding.
*
* CASE 1: if no conversion is required, then the given pointer s is returned.
*
* CASE 2: if conversion is required, a palloc'd string is returned.
*
* Callers must check whether return value differs from passed value
* to determine whether to pfree the result or not!
*
* Note: we assume that conversion cannot cause more than a 4-to-1 growth
* in the length of the string --- is this enough?
*/
unsigned char *
pg_client_to_server(unsigned char *s, int len)
@ -308,21 +224,12 @@ pg_client_to_server(unsigned char *s, int len)
if (ClientEncoding->encoding == DatabaseEncoding->encoding)
return s;
return pg_do_encoding_conversion(s, len, client_to_mic, server_from_mic);
return pg_do_encoding_conversion(s, len, ClientEncoding->encoding,
DatabaseEncoding->encoding);
}
/*
* convert server encoding to client encoding.
*
* CASE 1: if no conversion is required, then the given pointer s is returned.
*
* CASE 2: if conversion is required, a palloc'd string is returned.
*
* Callers must check whether return value differs from passed value
* to determine whether to pfree the result or not!
*
* Note: we assume that conversion cannot cause more than a 4-to-1 growth
* in the length of the string --- is this enough?
*/
unsigned char *
pg_server_to_client(unsigned char *s, int len)
@ -333,7 +240,8 @@ pg_server_to_client(unsigned char *s, int len)
if (ClientEncoding->encoding == DatabaseEncoding->encoding)
return s;
return pg_do_encoding_conversion(s, len, server_to_mic, client_from_mic);
return pg_do_encoding_conversion(s, len, DatabaseEncoding->encoding,
ClientEncoding->encoding);
}
/* convert a multi-byte string to a wchar */
@ -448,6 +356,12 @@ SetDatabaseEncoding(int encoding)
Assert(DatabaseEncoding->encoding == encoding);
}
void
SetDefaultClientEncoding()
{
ClientEncoding = &pg_enc2name_tbl[GetDatabaseEncoding()];
}
int
GetDatabaseEncoding(void)
{

View File

@ -1,396 +0,0 @@
static struct
{
unsigned short int nec; /* SJIS UDC (NEC selection IBM kanji) */
unsigned short int sjis; /* SJIS UDC (IBM kanji) */
int euc; /* EUC_JP */
} ibmkanji[] = {
{ 0xEEEF , 0xfa40 , 0x8ff3f3 },
{ 0xEEF0 , 0xfa41 , 0x8ff3f4 },
{ 0xEEF1 , 0xfa42 , 0x8ff3f5 },
{ 0xEEF2 , 0xfa43 , 0x8ff3f6 },
{ 0xEEF3 , 0xfa44 , 0x8ff3f7 },
{ 0xEEF4 , 0xfa45 , 0x8ff3f8 },
{ 0xEEF5 , 0xfa46 , 0x8ff3f9 },
{ 0xEEF6 , 0xfa47 , 0x8ff3fa },
{ 0xEEF7 , 0xfa48 , 0x8ff3fb },
{ 0xEEF8 , 0xfa49 , 0x8ff3fc },
{ 0x8754 , 0xfa4a , 0x8ff3fd },
{ 0x8755 , 0xfa4b , 0x8ff3fe },
{ 0x8756 , 0xfa4c , 0x8ff4a1 },
{ 0x8757 , 0xfa4d , 0x8ff4a2 },
{ 0x8758 , 0xfa4e , 0x8ff4a3 },
{ 0x8759 , 0xfa4f , 0x8ff4a4 },
{ 0x875A , 0xfa50 , 0x8ff4a5 },
{ 0x875B , 0xfa51 , 0x8ff4a6 },
{ 0x875C , 0xfa52 , 0x8ff4a7 },
{ 0x875D , 0xfa53 , 0x8ff4a8 },
{ 0xEEF9 , 0xfa54 , 0xa2cc },
{ 0xEEFA , 0xfa55 , 0x8fa2c3 },
{ 0xEEFB , 0xfa56 , 0x8ff4a9 },
{ 0xEEFC , 0xfa57 , 0x8ff4aa },
{ 0x878A , 0xfa58 , 0x8ff4ab },
{ 0x8782 , 0xfa59 , 0x8ff4ac },
{ 0x8784 , 0xfa5a , 0x8ff4ad },
{ 0x879A , 0xfa5b , 0xa2e8 },
{ 0xED40 , 0xfa5c , 0x8fd4e3 },
{ 0xED41 , 0xfa5d , 0x8fdcdf },
{ 0xED42 , 0xfa5e , 0x8fe4e9 },
{ 0xED43 , 0xfa5f , 0x8fe3f8 },
{ 0xED44 , 0xfa60 , 0x8fd9a1 },
{ 0xED45 , 0xfa61 , 0x8fb1bb },
{ 0xED46 , 0xfa62 , 0x8ff4ae },
{ 0xED47 , 0xfa63 , 0x8fc2ad },
{ 0xED48 , 0xfa64 , 0x8fc3fc },
{ 0xED49 , 0xfa65 , 0x8fe4d0 },
{ 0xED4A , 0xfa66 , 0x8fc2bf },
{ 0xED4B , 0xfa67 , 0x8fbcf4 },
{ 0xED4C , 0xfa68 , 0x8fb0a9 },
{ 0xED4D , 0xfa69 , 0x8fb0c8 },
{ 0xED4E , 0xfa6a , 0x8ff4af },
{ 0xED4F , 0xfa6b , 0x8fb0d2 },
{ 0xED50 , 0xfa6c , 0x8fb0d4 },
{ 0xED51 , 0xfa6d , 0x8fb0e3 },
{ 0xED52 , 0xfa6e , 0x8fb0ee },
{ 0xED53 , 0xfa6f , 0x8fb1a7 },
{ 0xED54 , 0xfa70 , 0x8fb1a3 },
{ 0xED55 , 0xfa71 , 0x8fb1ac },
{ 0xED56 , 0xfa72 , 0x8fb1a9 },
{ 0xED57 , 0xfa73 , 0x8fb1be },
{ 0xED58 , 0xfa74 , 0x8fb1df },
{ 0xED59 , 0xfa75 , 0x8fb1d8 },
{ 0xED5A , 0xfa76 , 0x8fb1c8 },
{ 0xED5B , 0xfa77 , 0x8fb1d7 },
{ 0xED5C , 0xfa78 , 0x8fb1e3 },
{ 0xED5D , 0xfa79 , 0x8fb1f4 },
{ 0xED5E , 0xfa7a , 0x8fb1e1 },
{ 0xED5F , 0xfa7b , 0x8fb2a3 },
{ 0xED60 , 0xfa7c , 0x8ff4b0 },
{ 0xED61 , 0xfa7d , 0x8fb2bb },
{ 0xED62 , 0xfa7e , 0x8fb2e6 },
{ 0xED63 , 0xfa80 , 0x8fb2ed },
{ 0xED64 , 0xfa81 , 0x8fb2f5 },
{ 0xED65 , 0xfa82 , 0x8fb2fc },
{ 0xED66 , 0xfa83 , 0x8ff4b1 },
{ 0xED67 , 0xfa84 , 0x8fb3b5 },
{ 0xED68 , 0xfa85 , 0x8fb3d8 },
{ 0xED69 , 0xfa86 , 0x8fb3db },
{ 0xED6A , 0xfa87 , 0x8fb3e5 },
{ 0xED6B , 0xfa88 , 0x8fb3ee },
{ 0xED6C , 0xfa89 , 0x8fb3fb },
{ 0xED6D , 0xfa8a , 0x8ff4b2 },
{ 0xED6E , 0xfa8b , 0x8ff4b3 },
{ 0xED6F , 0xfa8c , 0x8fb4c0 },
{ 0xED70 , 0xfa8d , 0x8fb4c7 },
{ 0xED71 , 0xfa8e , 0x8fb4d0 },
{ 0xED72 , 0xfa8f , 0x8fb4de },
{ 0xED73 , 0xfa90 , 0x8ff4b4 },
{ 0xED74 , 0xfa91 , 0x8fb5aa },
{ 0xED75 , 0xfa92 , 0x8ff4b5 },
{ 0xED76 , 0xfa93 , 0x8fb5af },
{ 0xED77 , 0xfa94 , 0x8fb5c4 },
{ 0xED78 , 0xfa95 , 0x8fb5e8 },
{ 0xED79 , 0xfa96 , 0x8ff4b6 },
{ 0xED7A , 0xfa97 , 0x8fb7c2 },
{ 0xED7B , 0xfa98 , 0x8fb7e4 },
{ 0xED7C , 0xfa99 , 0x8fb7e8 },
{ 0xED7D , 0xfa9a , 0x8fb7e7 },
{ 0xED7E , 0xfa9b , 0x8ff4b7 },
{ 0xED80 , 0xfa9c , 0x8ff4b8 },
{ 0xED81 , 0xfa9d , 0x8ff4b9 },
{ 0xED82 , 0xfa9e , 0x8fb8ce },
{ 0xED83 , 0xfa9f , 0x8fb8e1 },
{ 0xED84 , 0xfaa0 , 0x8fb8f5 },
{ 0xED85 , 0xfaa1 , 0x8fb8f7 },
{ 0xED86 , 0xfaa2 , 0x8fb8f8 },
{ 0xED87 , 0xfaa3 , 0x8fb8fc },
{ 0xED88 , 0xfaa4 , 0x8fb9af },
{ 0xED89 , 0xfaa5 , 0x8fb9b7 },
{ 0xED8A , 0xfaa6 , 0x8fbabe },
{ 0xED8B , 0xfaa7 , 0x8fbadb },
{ 0xED8C , 0xfaa8 , 0x8fcdaa },
{ 0xED8D , 0xfaa9 , 0x8fbae1 },
{ 0xED8E , 0xfaaa , 0x8ff4ba },
{ 0xED8F , 0xfaab , 0x8fbaeb },
{ 0xED90 , 0xfaac , 0x8fbbb3 },
{ 0xED91 , 0xfaad , 0x8fbbb8 },
{ 0xED92 , 0xfaae , 0x8ff4bb },
{ 0xED93 , 0xfaaf , 0x8fbbca },
{ 0xED94 , 0xfab0 , 0x8ff4bc },
{ 0xED95 , 0xfab1 , 0x8ff4bd },
{ 0xED96 , 0xfab2 , 0x8fbbd0 },
{ 0xED97 , 0xfab3 , 0x8fbbde },
{ 0xED98 , 0xfab4 , 0x8fbbf4 },
{ 0xED99 , 0xfab5 , 0x8fbbf5 },
{ 0xED9A , 0xfab6 , 0x8fbbf9 },
{ 0xED9B , 0xfab7 , 0x8fbce4 },
{ 0xED9C , 0xfab8 , 0x8fbced },
{ 0xED9D , 0xfab9 , 0x8fbcfe },
{ 0xED9E , 0xfaba , 0x8ff4be },
{ 0xED9F , 0xfabb , 0x8fbdc2 },
{ 0xEDA0 , 0xfabc , 0x8fbde7 },
{ 0xEDA1 , 0xfabd , 0x8ff4bf },
{ 0xEDA2 , 0xfabe , 0x8fbdf0 },
{ 0xEDA3 , 0xfabf , 0x8fbeb0 },
{ 0xEDA4 , 0xfac0 , 0x8fbeac },
{ 0xEDA5 , 0xfac1 , 0x8ff4c0 },
{ 0xEDA6 , 0xfac2 , 0x8fbeb3 },
{ 0xEDA7 , 0xfac3 , 0x8fbebd },
{ 0xEDA8 , 0xfac4 , 0x8fbecd },
{ 0xEDA9 , 0xfac5 , 0x8fbec9 },
{ 0xEDAA , 0xfac6 , 0x8fbee4 },
{ 0xEDAB , 0xfac7 , 0x8fbfa8 },
{ 0xEDAC , 0xfac8 , 0x8fbfc9 },
{ 0xEDAD , 0xfac9 , 0x8fc0c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e9ed },
{ 0xEEE2 , 0xfc41 , 0x8feacd },
{ 0xEEE3 , 0xfc42 , 0x8ff4fc },
{ 0xEEE4 , 0xfc43 , 0x8feadb },
{ 0xEEE5 , 0xfc44 , 0x8feae6 },
{ 0xEEE6 , 0xfc45 , 0x8feaea },
{ 0xEEE7 , 0xfc46 , 0x8feba5 },
{ 0xEEE8 , 0xfc47 , 0x8febfb },
{ 0xEEE9 , 0xfc48 , 0x8febfa },
{ 0xEEEA , 0xfc49 , 0x8ff4fd },
{ 0xEEEB , 0xfc4a , 0x8fecd6 },
{ 0xEEEC , 0xfc4b , 0x8ff4fe },
{ 0xffff , 0xffff , 0xffff } /* Stop code */
};

View File

@ -5,7 +5,7 @@
* command, configuration file, and command line options.
* See src/backend/utils/misc/README for more information.
*
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.71 2002/07/13 01:02:14 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.72 2002/07/18 02:02:30 ishii Exp $
*
* Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>.
@ -28,6 +28,7 @@
#include "fmgr.h"
#include "libpq/auth.h"
#include "libpq/pqcomm.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "optimizer/cost.h"
#include "optimizer/geqo.h"
@ -1115,11 +1116,9 @@ InitializeGUCOptions(void)
if (env != NULL)
SetConfigOption("timezone", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
#ifdef MULTIBYTE
env = getenv("PGCLIENTENCODING");
if (env != NULL)
SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
#endif
}

View File

@ -27,7 +27,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.158 2002/07/16 17:48:46 tgl Exp $
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.159 2002/07/18 02:02:30 ishii Exp $
#
#-------------------------------------------------------------------------
@ -994,6 +994,11 @@ EOF
| "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
echo "ok"
# Create pg_conversion and support functions
$ECHO_N "creating conversions... "$ECHO_C
cat $datadir/conversion_create.sql | "$PGPATH"/postgres $PGSQL_OPT template1 > /dev/null || exit_nicely
echo "ok"
# Set most system catalogs and built-in functions as world-accessible.
# Some objects may require different permissions by default, so we
# make sure we don't overwrite privilege sets that have already been

View File

@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.73 2002/07/15 01:56:25 momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.74 2002/07/18 02:02:30 ishii Exp $
*/
#include "postgres_fe.h"
#include "command.h"
@ -38,14 +38,7 @@
#include "print.h"
#include "settings.h"
#include "variables.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#else
/* Grand unified hard-coded badness */
#define pg_encoding_to_char(x) "SQL_ASCII"
#endif
/* functions for use in this file */
@ -457,10 +450,9 @@ exec_command(const char *cmd,
puts(pg_encoding_to_char(pset.encoding));
else
{
#ifdef MULTIBYTE
/* set encoding */
if (PQsetClientEncoding(pset.db, encoding) == -1)
psql_error("%s: invalid encoding name\n", encoding);
psql_error("%s: invalid encoding name or conversion proc not found\n", encoding);
else
{
@ -468,9 +460,6 @@ exec_command(const char *cmd,
pset.encoding = PQclientEncoding(pset.db);
SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
}
#else
psql_error("\\%s: multibyte support is not enabled\n", cmd);
#endif
free(encoding);
}
}

View File

@ -1,4 +1,4 @@
/* $Id: pg_wchar.h,v 1.39 2002/06/13 08:30:22 ishii Exp $ */
/* $Id: pg_wchar.h,v 1.40 2002/07/18 02:02:30 ishii Exp $ */
#ifndef PG_WCHAR_H
#define PG_WCHAR_H
@ -145,7 +145,7 @@ typedef unsigned int pg_wchar;
* Encoding numeral identificators
*
* WARNING: the order of this table must be same as order
* in the pg_enconv[] (mb/conv.c) and pg_enc2name[] (mb/encnames.c) array!
* in the pg_enc2name[] (mb/encnames.c) array!
*
* If you add some encoding don'y forget check
* PG_ENCODING_[BE|FE]_LAST macros.
@ -248,30 +248,6 @@ extern pg_encname *pg_char_to_encname_struct(const char *name);
extern int pg_char_to_encoding(const char *s);
extern const char *pg_encoding_to_char(int encoding);
typedef void (*to_mic_converter) (unsigned char *l, unsigned char *p, int len);
typedef void (*from_mic_converter) (unsigned char *mic, unsigned char *p, int len);
/*
* The backend encoding conversion routines
* Careful:
*
* if (PG_VALID_ENCODING(enc))
* pg_encconv_tbl[ enc ]->foo
*/
#ifndef FRONTEND
typedef struct pg_enconv
{
pg_enc encoding; /* encoding identifier */
to_mic_converter to_mic; /* client encoding to MIC */
from_mic_converter from_mic; /* MIC to client encoding */
to_mic_converter to_unicode; /* client encoding to UTF-8 */
from_mic_converter from_unicode; /* UTF-8 to client encoding */
} pg_enconv;
extern pg_enconv pg_enconv_tbl[];
extern pg_enconv *pg_get_enconv_by_encoding(int encoding);
#endif /* FRONTEND */
/*
* pg_wchar stuff
*/
@ -325,7 +301,8 @@ extern int pg_mbcharcliplen(const unsigned char *, int, int);
extern int pg_encoding_max_length(int);
extern int pg_database_encoding_max_length(void);
extern int pg_set_client_encoding(int);
extern void SetDefaultClientEncoding(void);
extern int SetClientEncoding(int encoding, bool doit);
extern int pg_get_client_encoding(void);
extern const char *pg_get_client_encoding_name(void);
@ -337,12 +314,9 @@ extern int pg_valid_client_encoding(const char *name);
extern int pg_valid_server_encoding(const char *name);
extern int pg_utf_mblen(const unsigned char *);
extern int pg_find_encoding_converters(int src, int dest,
to_mic_converter *src_to_mic,
from_mic_converter *dest_from_mic);
extern unsigned char *pg_do_encoding_conversion(unsigned char *src, int len,
to_mic_converter src_to_mic,
from_mic_converter dest_from_mic);
int src_encoding,
int dest_encoding);
extern unsigned char *pg_client_to_server(unsigned char *, int);
extern unsigned char *pg_server_to_client(unsigned char *, int);
@ -350,7 +324,18 @@ extern unsigned char *pg_server_to_client(unsigned char *, int);
extern unsigned short BIG5toCNS(unsigned short, unsigned char *);
extern unsigned short CNStoBIG5(unsigned short, unsigned char);
extern void LocalToUtf(unsigned char *iso, unsigned char *utf,
pg_local_to_utf *map, int size, int encoding, int len);
extern void UtfToLocal(unsigned char *utf, unsigned char *iso,
pg_utf_to_local *map, int size, int len);
char *pg_verifymbstr(const unsigned char *, int);
void pg_ascii2mic(unsigned char *src, unsigned char *dest, int len);
void pg_mic2ascii(unsigned char *src, unsigned char *dest, int len);
void pg_print_bogus_char(unsigned char **mic, unsigned char **p);
#endif /* MULTIBYTE */
#endif /* PG_WCHAR_H */

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.188 2002/06/20 20:29:53 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.189 2002/07/18 02:02:30 ishii Exp $
*
*-------------------------------------------------------------------------
*/
@ -2714,7 +2714,6 @@ PQclientEncoding(const PGconn *conn)
return conn->client_encoding;
}
#ifdef MULTIBYTE
int
PQsetClientEncoding(PGconn *conn, const char *encoding)
{
@ -2751,15 +2750,6 @@ PQsetClientEncoding(PGconn *conn, const char *encoding)
return (status);
}
#else /* without multibytle support */
int
PQsetClientEncoding(PGconn *conn, const char *encoding)
{
return -1;
}
#endif
void
PQtrace(PGconn *conn, FILE *debug_port)
{