1998-07-24 05:32:46 +02:00
|
|
|
/*
|
|
|
|
* This file contains public functions for conversion between
|
|
|
|
* client encoding and server internal encoding.
|
|
|
|
* (currently mule internal code (mic) is used)
|
|
|
|
* Tatsuo Ishii
|
2002-11-02 19:41:22 +01:00
|
|
|
*
|
2007-09-24 16:59:37 +02:00
|
|
|
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.65 2007/09/24 14:59:37 adunstan Exp $
|
2001-02-10 03:31:31 +01:00
|
|
|
*/
|
1999-07-17 18:25:28 +02:00
|
|
|
#include "postgres.h"
|
2002-11-02 19:41:22 +01:00
|
|
|
|
2002-07-25 12:07:13 +02:00
|
|
|
#include "access/xact.h"
|
2006-01-12 23:04:02 +01:00
|
|
|
#include "catalog/namespace.h"
|
1998-07-24 05:32:46 +02:00
|
|
|
#include "mb/pg_wchar.h"
|
2000-06-13 09:35:40 +02:00
|
|
|
#include "utils/builtins.h"
|
2002-08-08 08:35:26 +02:00
|
|
|
#include "utils/memutils.h"
|
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
2002-07-18 04:02:30 +02:00
|
|
|
#include "utils/syscache.h"
|
1998-07-24 05:32:46 +02:00
|
|
|
|
2007-05-28 18:43:24 +02:00
|
|
|
/*
|
|
|
|
* When converting strings between different encodings, we assume that space
|
|
|
|
* for converted result is 4-to-1 growth in the worst case. The rate for
|
|
|
|
* currently supported encoding pairs are within 3 (SJIS JIS X0201 half width
|
|
|
|
* kanna -> UTF8 is the worst case). So "4" should be enough for the moment.
|
|
|
|
*
|
|
|
|
* Note that this is not the same as the maximum character width in any
|
|
|
|
* particular encoding.
|
|
|
|
*/
|
|
|
|
#define MAX_CONVERSION_GROWTH 4
|
|
|
|
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
/*
|
2001-10-25 07:50:21 +02:00
|
|
|
* We handle for actual FE and BE encoding setting encoding-identificator
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
* and encoding-name too. It prevent searching and conversion from encoding
|
|
|
|
* to encoding name in getdatabaseencoding() and other routines.
|
|
|
|
*/
|
2001-10-25 07:50:21 +02:00
|
|
|
static pg_enc2name *ClientEncoding = &pg_enc2name_tbl[PG_SQL_ASCII];
|
|
|
|
static pg_enc2name *DatabaseEncoding = &pg_enc2name_tbl[PG_SQL_ASCII];
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
|
2001-08-15 09:07:40 +02:00
|
|
|
/*
|
2006-01-12 23:04:02 +01:00
|
|
|
* Caches for conversion function info. These values are allocated in
|
|
|
|
* MbProcContext. That context is a child of TopMemoryContext,
|
|
|
|
* which allows these values to survive across transactions. See
|
|
|
|
* SetClientEncoding() for more details.
|
2001-08-15 09:07:40 +02:00
|
|
|
*/
|
2006-01-12 23:04:02 +01:00
|
|
|
static MemoryContext MbProcContext = NULL;
|
2002-11-02 19:41:22 +01:00
|
|
|
static FmgrInfo *ToServerConvProc = NULL;
|
|
|
|
static FmgrInfo *ToClientConvProc = NULL;
|
2002-08-08 08:35:26 +02:00
|
|
|
|
2003-04-27 19:31:25 +02:00
|
|
|
/*
|
|
|
|
* During backend startup we can't set client encoding because we (a)
|
|
|
|
* can't look up the conversion functions, and (b) may not know the database
|
|
|
|
* encoding yet either. So SetClientEncoding() just accepts anything and
|
|
|
|
* remembers it for InitializeClientEncoding() to apply later.
|
|
|
|
*/
|
|
|
|
static bool backend_startup_complete = false;
|
|
|
|
static int pending_client_encoding = PG_SQL_ASCII;
|
|
|
|
|
|
|
|
|
2002-08-08 08:35:26 +02:00
|
|
|
/* Internal functions */
|
2005-09-24 19:53:28 +02:00
|
|
|
static char *perform_default_encoding_conversion(const char *src,
|
2002-11-02 19:41:22 +01:00
|
|
|
int len, bool is_client_to_server);
|
2005-09-24 19:53:28 +02:00
|
|
|
static int cliplen(const char *str, int len, int limit);
|
2002-08-08 08:35:26 +02:00
|
|
|
|
2002-08-29 09:22:30 +02:00
|
|
|
|
2002-08-08 08:35:26 +02:00
|
|
|
/*
|
2003-03-10 23:28:22 +01:00
|
|
|
* Set the client encoding and save fmgrinfo for the conversion
|
2003-04-27 19:31:25 +02:00
|
|
|
* function if necessary. Returns 0 if okay, -1 if not (bad encoding
|
|
|
|
* or can't support conversion)
|
|
|
|
*/
|
2001-08-15 09:07:40 +02:00
|
|
|
int
|
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
2002-07-18 04:02:30 +02:00
|
|
|
SetClientEncoding(int encoding, bool doit)
|
2001-08-15 09:07:40 +02:00
|
|
|
{
|
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
2002-07-18 04:02:30 +02:00
|
|
|
int current_server_encoding;
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid to_server_proc,
|
|
|
|
to_client_proc;
|
2003-04-27 19:31:25 +02:00
|
|
|
FmgrInfo *to_server;
|
|
|
|
FmgrInfo *to_client;
|
2002-08-08 08:35:26 +02:00
|
|
|
MemoryContext oldcontext;
|
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
2002-07-18 04:02:30 +02:00
|
|
|
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
if (!PG_VALID_FE_ENCODING(encoding))
|
2006-01-11 09:43:13 +01:00
|
|
|
return -1;
|
2001-08-15 09:07:40 +02:00
|
|
|
|
2003-04-27 19:31:25 +02:00
|
|
|
/* Can't do anything during startup, per notes above */
|
|
|
|
if (!backend_startup_complete)
|
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
2002-07-18 04:02:30 +02:00
|
|
|
{
|
2003-04-27 19:31:25 +02:00
|
|
|
if (doit)
|
|
|
|
pending_client_encoding = encoding;
|
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
2002-07-18 04:02:30 +02:00
|
|
|
return 0;
|
|
|
|
}
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
|
2003-04-27 19:31:25 +02:00
|
|
|
current_server_encoding = GetDatabaseEncoding();
|
|
|
|
|
2002-09-04 22:31:48 +02:00
|
|
|
/*
|
2003-04-27 19:31:25 +02:00
|
|
|
* Check for cases that require no conversion function.
|
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
2002-07-18 04:02:30 +02:00
|
|
|
*/
|
2003-04-27 19:31:25 +02:00
|
|
|
if (current_server_encoding == encoding ||
|
2006-01-11 07:59:22 +01:00
|
|
|
current_server_encoding == PG_SQL_ASCII ||
|
|
|
|
encoding == PG_SQL_ASCII)
|
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
2002-07-18 04:02:30 +02:00
|
|
|
{
|
2003-04-27 19:31:25 +02:00
|
|
|
if (doit)
|
|
|
|
{
|
|
|
|
ClientEncoding = &pg_enc2name_tbl[encoding];
|
|
|
|
ToServerConvProc = NULL;
|
|
|
|
ToClientConvProc = NULL;
|
2006-01-12 23:04:02 +01:00
|
|
|
if (MbProcContext)
|
|
|
|
MemoryContextReset(MbProcContext);
|
2003-04-27 19:31:25 +02:00
|
|
|
}
|
|
|
|
return 0;
|
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
2002-07-18 04:02:30 +02:00
|
|
|
}
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
|
2003-04-27 20:01:46 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* If we're not inside a transaction then we can't do catalog lookups, so
|
|
|
|
* fail. After backend startup, this could only happen if we are
|
2003-08-04 02:43:34 +02:00
|
|
|
* re-reading postgresql.conf due to SIGHUP --- so basically this just
|
|
|
|
* constrains the ability to change client_encoding on the fly from
|
2005-10-15 04:49:52 +02:00
|
|
|
* postgresql.conf. Which would probably be a stupid thing to do anyway.
|
2003-04-27 20:01:46 +02:00
|
|
|
*/
|
|
|
|
if (!IsTransactionState())
|
|
|
|
return -1;
|
|
|
|
|
2003-04-27 19:31:25 +02:00
|
|
|
/*
|
|
|
|
* Look up the conversion functions.
|
|
|
|
*/
|
|
|
|
to_server_proc = FindDefaultConversionProc(encoding,
|
|
|
|
current_server_encoding);
|
|
|
|
if (!OidIsValid(to_server_proc))
|
|
|
|
return -1;
|
|
|
|
to_client_proc = FindDefaultConversionProc(current_server_encoding,
|
|
|
|
encoding);
|
|
|
|
if (!OidIsValid(to_client_proc))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Done if not wanting to actually apply setting.
|
|
|
|
*/
|
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
2002-07-18 04:02:30 +02:00
|
|
|
if (!doit)
|
|
|
|
return 0;
|
|
|
|
|
2006-01-12 23:04:02 +01:00
|
|
|
/* Before loading the new fmgr info, remove the old info, if any */
|
|
|
|
ToServerConvProc = NULL;
|
|
|
|
ToClientConvProc = NULL;
|
|
|
|
if (MbProcContext != NULL)
|
|
|
|
{
|
|
|
|
MemoryContextReset(MbProcContext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2006-10-04 02:30:14 +02:00
|
|
|
* This is the first time through, so create the context. Make it a
|
|
|
|
* child of TopMemoryContext so that these values survive across
|
|
|
|
* transactions.
|
2006-01-12 23:04:02 +01:00
|
|
|
*/
|
|
|
|
MbProcContext = AllocSetContextCreate(TopMemoryContext,
|
|
|
|
"MbProcContext",
|
|
|
|
ALLOCSET_SMALL_MINSIZE,
|
|
|
|
ALLOCSET_SMALL_INITSIZE,
|
|
|
|
ALLOCSET_SMALL_MAXSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the fmgr info into MbProcContext */
|
|
|
|
oldcontext = MemoryContextSwitchTo(MbProcContext);
|
2003-04-27 19:31:25 +02:00
|
|
|
to_server = palloc(sizeof(FmgrInfo));
|
|
|
|
to_client = palloc(sizeof(FmgrInfo));
|
|
|
|
fmgr_info(to_server_proc, to_server);
|
|
|
|
fmgr_info(to_client_proc, to_client);
|
|
|
|
MemoryContextSwitchTo(oldcontext);
|
2002-08-14 07:33:34 +02:00
|
|
|
|
2003-04-27 19:31:25 +02:00
|
|
|
ClientEncoding = &pg_enc2name_tbl[encoding];
|
|
|
|
ToServerConvProc = to_server;
|
|
|
|
ToClientConvProc = to_client;
|
|
|
|
|
2001-08-15 09:07:40 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-27 19:31:25 +02:00
|
|
|
/*
|
|
|
|
* Initialize client encoding if necessary.
|
|
|
|
* called from InitPostgres() once during backend starting up.
|
2003-02-19 15:31:26 +01:00
|
|
|
*/
|
|
|
|
void
|
2003-04-27 19:31:25 +02:00
|
|
|
InitializeClientEncoding(void)
|
2003-02-19 15:31:26 +01:00
|
|
|
{
|
2003-04-27 19:31:25 +02:00
|
|
|
Assert(!backend_startup_complete);
|
|
|
|
backend_startup_complete = true;
|
|
|
|
|
|
|
|
if (SetClientEncoding(pending_client_encoding, true) < 0)
|
2003-02-19 15:31:26 +01:00
|
|
|
{
|
2003-04-27 19:31:25 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Oops, the requested conversion is not available. We couldn't fail
|
|
|
|
* before, but we can now.
|
2003-04-27 19:31:25 +02:00
|
|
|
*/
|
2003-07-25 22:18:01 +02:00
|
|
|
ereport(FATAL,
|
|
|
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
|
|
errmsg("conversion between %s and %s is not supported",
|
|
|
|
pg_enc2name_tbl[pending_client_encoding].name,
|
|
|
|
GetDatabaseEncodingName())));
|
2003-02-19 15:31:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-24 05:32:46 +02:00
|
|
|
/*
|
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
2002-07-18 04:02:30 +02:00
|
|
|
* returns the current client encoding */
|
1998-09-01 06:40:42 +02:00
|
|
|
int
|
2001-09-21 17:27:38 +02:00
|
|
|
pg_get_client_encoding(void)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
2001-09-09 03:15:11 +02:00
|
|
|
Assert(ClientEncoding);
|
2006-01-11 09:43:13 +01:00
|
|
|
return ClientEncoding->encoding;
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns the current client encoding name
|
|
|
|
*/
|
|
|
|
const char *
|
2001-09-21 17:27:38 +02:00
|
|
|
pg_get_client_encoding_name(void)
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
{
|
2001-09-09 03:15:11 +02:00
|
|
|
Assert(ClientEncoding);
|
2006-01-11 09:43:13 +01:00
|
|
|
return ClientEncoding->name;
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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
2002-07-18 04:02:30 +02:00
|
|
|
* 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,
|
2007-05-28 18:43:24 +02:00
|
|
|
* warn and return src.
|
1999-09-12 00:28:11 +02:00
|
|
|
*
|
2003-03-10 23:28:22 +01:00
|
|
|
* In the case of no conversion, src is returned.
|
1999-09-12 00:28:11 +02:00
|
|
|
*
|
2007-05-28 18:43:24 +02:00
|
|
|
* Note: we try to avoid raising error, since that could get us into
|
|
|
|
* infinite recursion when this function is invoked during error message
|
|
|
|
* sending. It should be OK to raise error for overlength strings though,
|
|
|
|
* since the recursion will come with a shorter message.
|
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
2002-07-18 04:02:30 +02:00
|
|
|
*/
|
1998-09-01 06:40:42 +02:00
|
|
|
unsigned char *
|
2001-09-21 17:27:38 +02:00
|
|
|
pg_do_encoding_conversion(unsigned char *src, int len,
|
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
2002-07-18 04:02:30 +02:00
|
|
|
int src_encoding, int dest_encoding)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
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
2002-07-18 04:02:30 +02:00
|
|
|
unsigned char *result;
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid proc;
|
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
2002-07-18 04:02:30 +02:00
|
|
|
|
2002-07-25 12:07:13 +02:00
|
|
|
if (!IsTransactionState())
|
|
|
|
return src;
|
2002-09-04 22:31:48 +02:00
|
|
|
|
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
2002-07-18 04:02:30 +02:00
|
|
|
if (src_encoding == dest_encoding)
|
|
|
|
return src;
|
1998-09-01 06:40:42 +02:00
|
|
|
|
2002-07-25 12:07:13 +02:00
|
|
|
if (src_encoding == PG_SQL_ASCII || dest_encoding == PG_SQL_ASCII)
|
|
|
|
return src;
|
|
|
|
|
2002-11-26 03:22:29 +01:00
|
|
|
if (len <= 0)
|
|
|
|
return src;
|
|
|
|
|
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
2002-07-18 04:02:30 +02:00
|
|
|
proc = FindDefaultConversionProc(src_encoding, dest_encoding);
|
|
|
|
if (!OidIsValid(proc))
|
1998-09-01 06:40:42 +02:00
|
|
|
{
|
2003-07-25 22:18:01 +02:00
|
|
|
ereport(LOG,
|
|
|
|
(errcode(ERRCODE_UNDEFINED_FUNCTION),
|
2004-08-29 07:07:03 +02:00
|
|
|
errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
|
|
|
|
pg_encoding_to_char(src_encoding),
|
|
|
|
pg_encoding_to_char(dest_encoding))));
|
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
2002-07-18 04:02:30 +02:00
|
|
|
return src;
|
1998-09-01 06:40:42 +02:00
|
|
|
}
|
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
2002-07-18 04:02:30 +02:00
|
|
|
|
2002-09-04 22:31:48 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* XXX we should avoid throwing errors in OidFunctionCall. Otherwise we
|
|
|
|
* are going into infinite loop! So we have to make sure that the
|
2002-09-04 22:31:48 +02:00
|
|
|
* function exists before calling OidFunctionCall.
|
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
2002-07-18 04:02:30 +02:00
|
|
|
*/
|
|
|
|
if (!SearchSysCacheExists(PROCOID,
|
2002-09-04 22:31:48 +02:00
|
|
|
ObjectIdGetDatum(proc),
|
|
|
|
0, 0, 0))
|
1998-09-01 06:40:42 +02:00
|
|
|
{
|
2003-07-25 22:18:01 +02:00
|
|
|
elog(LOG, "cache lookup failed for function %u", proc);
|
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
2002-07-18 04:02:30 +02:00
|
|
|
return src;
|
1998-09-01 06:40:42 +02:00
|
|
|
}
|
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
2002-07-18 04:02:30 +02:00
|
|
|
|
2007-05-28 18:43:24 +02:00
|
|
|
/*
|
|
|
|
* Allocate space for conversion result, being wary of integer overflow
|
|
|
|
*/
|
|
|
|
if ((Size) len >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
|
|
|
errmsg("out of memory"),
|
|
|
|
errdetail("String of %d bytes is too long for encoding conversion.",
|
|
|
|
len)));
|
|
|
|
|
|
|
|
result = palloc(len * MAX_CONVERSION_GROWTH + 1);
|
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
2002-07-18 04:02:30 +02:00
|
|
|
|
|
|
|
OidFunctionCall5(proc,
|
|
|
|
Int32GetDatum(src_encoding),
|
|
|
|
Int32GetDatum(dest_encoding),
|
|
|
|
CStringGetDatum(src),
|
|
|
|
CStringGetDatum(result),
|
|
|
|
Int32GetDatum(len));
|
1999-09-12 00:28:11 +02:00
|
|
|
return result;
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
2001-08-15 09:07:40 +02:00
|
|
|
/*
|
2007-09-18 19:41:17 +02:00
|
|
|
* Convert string using encoding_name. The source
|
|
|
|
* encoding is the DB encoding.
|
2001-08-15 09:07:40 +02:00
|
|
|
*
|
2007-09-18 19:41:17 +02:00
|
|
|
* BYTEA convert_to(TEXT string, NAME encoding_name) */
|
2001-08-15 09:07:40 +02:00
|
|
|
Datum
|
2007-09-18 19:41:17 +02:00
|
|
|
pg_convert_to(PG_FUNCTION_ARGS)
|
2001-08-15 09:07:40 +02:00
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
Datum string = PG_GETARG_DATUM(0);
|
|
|
|
Datum dest_encoding_name = PG_GETARG_DATUM(1);
|
|
|
|
Datum src_encoding_name = DirectFunctionCall1(
|
2005-10-15 04:49:52 +02:00
|
|
|
namein, CStringGetDatum(DatabaseEncoding->name));
|
2002-09-04 22:31:48 +02:00
|
|
|
Datum result;
|
2001-08-15 09:07:40 +02:00
|
|
|
|
2001-11-20 02:32:29 +01:00
|
|
|
result = DirectFunctionCall3(
|
2007-09-18 19:41:17 +02:00
|
|
|
pg_convert, string, src_encoding_name, dest_encoding_name);
|
|
|
|
|
|
|
|
/* free memory allocated by namein */
|
|
|
|
pfree((void *) src_encoding_name);
|
|
|
|
|
|
|
|
PG_RETURN_BYTEA_P(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert string using encoding_name. The destination
|
|
|
|
* encoding is the DB encoding.
|
|
|
|
*
|
|
|
|
* TEXT convert_from(BYTEA string, NAME encoding_name) */
|
|
|
|
Datum
|
|
|
|
pg_convert_from(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Datum string = PG_GETARG_DATUM(0);
|
|
|
|
Datum src_encoding_name = PG_GETARG_DATUM(1);
|
|
|
|
Datum dest_encoding_name = DirectFunctionCall1(
|
|
|
|
namein, CStringGetDatum(DatabaseEncoding->name));
|
|
|
|
Datum result;
|
|
|
|
|
|
|
|
result = DirectFunctionCall3(
|
|
|
|
pg_convert, string, src_encoding_name, dest_encoding_name);
|
2001-08-15 09:07:40 +02:00
|
|
|
|
2001-11-20 02:32:29 +01:00
|
|
|
/* free memory allocated by namein */
|
2002-09-04 22:31:48 +02:00
|
|
|
pfree((void *) src_encoding_name);
|
2001-08-15 09:07:40 +02:00
|
|
|
|
2001-11-20 02:32:29 +01:00
|
|
|
PG_RETURN_TEXT_P(result);
|
2001-08-15 09:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-09-18 19:41:17 +02:00
|
|
|
* Convert string using encoding_names.
|
2001-08-15 09:07:40 +02:00
|
|
|
*
|
2007-09-18 19:41:17 +02:00
|
|
|
* BYTEA convert(BYTEA string, NAME src_encoding_name, NAME dest_encoding_name)
|
2001-08-15 09:07:40 +02:00
|
|
|
*/
|
|
|
|
Datum
|
2007-09-18 19:41:17 +02:00
|
|
|
pg_convert(PG_FUNCTION_ARGS)
|
2001-08-15 09:07:40 +02:00
|
|
|
{
|
2007-09-24 16:59:37 +02:00
|
|
|
bytea *string = PG_GETARG_BYTEA_P(0);
|
2001-10-25 07:50:21 +02:00
|
|
|
char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
|
|
|
|
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);
|
|
|
|
unsigned char *result;
|
2007-09-18 19:41:17 +02:00
|
|
|
bytea *retval;
|
2001-11-19 07:48:39 +01:00
|
|
|
unsigned char *str;
|
2002-09-04 22:31:48 +02:00
|
|
|
int len;
|
2001-08-15 09:07:40 +02:00
|
|
|
|
|
|
|
if (src_encoding < 0)
|
2003-07-25 22:18:01 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
|
|
errmsg("invalid source encoding name \"%s\"",
|
|
|
|
src_encoding_name)));
|
2001-08-15 09:07:40 +02:00
|
|
|
if (dest_encoding < 0)
|
2003-07-25 22:18:01 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
|
|
errmsg("invalid destination encoding name \"%s\"",
|
|
|
|
dest_encoding_name)));
|
2001-08-15 09:07:40 +02:00
|
|
|
|
2007-09-18 19:41:17 +02:00
|
|
|
/* make sure that source string is valid and null terminated */
|
2001-11-19 07:48:39 +01:00
|
|
|
len = VARSIZE(string) - VARHDRSZ;
|
2007-09-18 19:41:17 +02:00
|
|
|
pg_verify_mbstr(src_encoding,VARDATA(string),len,false);
|
2001-11-19 07:48:39 +01:00
|
|
|
str = palloc(len + 1);
|
|
|
|
memcpy(str, VARDATA(string), len);
|
|
|
|
*(str + len) = '\0';
|
|
|
|
|
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
2002-07-18 04:02:30 +02:00
|
|
|
result = pg_do_encoding_conversion(str, len, src_encoding, dest_encoding);
|
2001-08-15 09:07:40 +02:00
|
|
|
if (result == NULL)
|
2003-07-25 22:18:01 +02:00
|
|
|
elog(ERROR, "encoding conversion failed");
|
2001-08-15 09:07:40 +02:00
|
|
|
|
2002-09-04 22:31:48 +02:00
|
|
|
/*
|
2007-09-18 19:41:17 +02:00
|
|
|
* build bytea data type structure.
|
2002-09-04 22:31:48 +02:00
|
|
|
*/
|
2005-09-24 19:53:28 +02:00
|
|
|
len = strlen((char *) result) + VARHDRSZ;
|
2001-11-19 07:48:39 +01:00
|
|
|
retval = palloc(len);
|
2007-02-28 00:48:10 +01:00
|
|
|
SET_VARSIZE(retval, len);
|
2001-11-19 07:48:39 +01:00
|
|
|
memcpy(VARDATA(retval), result, len - VARHDRSZ);
|
|
|
|
|
|
|
|
if (result != str)
|
2001-10-25 07:50:21 +02:00
|
|
|
pfree(result);
|
2002-09-04 22:31:48 +02:00
|
|
|
pfree(str);
|
2001-08-15 09:07:40 +02:00
|
|
|
|
|
|
|
/* free memory if allocated by the toaster */
|
|
|
|
PG_FREE_IF_COPY(string, 0);
|
|
|
|
|
2007-09-18 19:41:17 +02:00
|
|
|
PG_RETURN_BYTEA_P(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get the length of the string considered as text in the specified
|
|
|
|
* encoding. Raises an error if the data is not valid in that
|
|
|
|
* encoding.
|
|
|
|
*
|
|
|
|
* INT4 length (BYTEA string, NAME src_encoding_name)
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
length_in_encoding(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
bytea *string = PG_GETARG_BYTEA_P(0);
|
|
|
|
char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
|
|
|
|
int src_encoding = pg_char_to_encoding(src_encoding_name);
|
|
|
|
int len = VARSIZE(string) - VARHDRSZ;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = pg_verify_mbstr_len(src_encoding, VARDATA(string), len, false);
|
|
|
|
PG_RETURN_INT32(retval);
|
|
|
|
|
2001-08-15 09:07:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* convert client encoding to server encoding.
|
|
|
|
*/
|
2005-09-24 19:53:28 +02:00
|
|
|
char *
|
|
|
|
pg_client_to_server(const char *s, int len)
|
2001-08-15 09:07:40 +02:00
|
|
|
{
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
Assert(DatabaseEncoding);
|
2001-09-09 03:15:11 +02:00
|
|
|
Assert(ClientEncoding);
|
2001-09-08 16:30:15 +02:00
|
|
|
|
2006-05-21 22:05:21 +02:00
|
|
|
if (len <= 0)
|
|
|
|
return (char *) s;
|
|
|
|
|
|
|
|
if (ClientEncoding->encoding == DatabaseEncoding->encoding ||
|
|
|
|
ClientEncoding->encoding == PG_SQL_ASCII)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No conversion is needed, but we must still validate the data.
|
|
|
|
*/
|
|
|
|
(void) pg_verify_mbstr(DatabaseEncoding->encoding, s, len, false);
|
|
|
|
return (char *) s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DatabaseEncoding->encoding == PG_SQL_ASCII)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No conversion is possible, but we must still validate the data,
|
2006-10-04 02:30:14 +02:00
|
|
|
* because the client-side code might have done string escaping using
|
|
|
|
* the selected client_encoding. If the client encoding is ASCII-safe
|
|
|
|
* then we just do a straight validation under that encoding. For an
|
|
|
|
* ASCII-unsafe encoding we have a problem: we dare not pass such data
|
|
|
|
* to the parser but we have no way to convert it. We compromise by
|
|
|
|
* rejecting the data if it contains any non-ASCII characters.
|
2006-05-21 22:05:21 +02:00
|
|
|
*/
|
|
|
|
if (PG_VALID_BE_ENCODING(ClientEncoding->encoding))
|
|
|
|
(void) pg_verify_mbstr(ClientEncoding->encoding, s, len, false);
|
|
|
|
else
|
|
|
|
{
|
2006-10-04 02:30:14 +02:00
|
|
|
int i;
|
2006-05-21 22:05:21 +02:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (s[i] == '\0' || IS_HIGHBIT_SET(s[i]))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
|
2006-10-04 02:30:14 +02:00
|
|
|
errmsg("invalid byte value for encoding \"%s\": 0x%02x",
|
|
|
|
pg_enc2name_tbl[PG_SQL_ASCII].name,
|
|
|
|
(unsigned char) s[i])));
|
2006-05-21 22:05:21 +02:00
|
|
|
}
|
|
|
|
}
|
2005-09-24 19:53:28 +02:00
|
|
|
return (char *) s;
|
2006-05-21 22:05:21 +02:00
|
|
|
}
|
2001-08-15 09:07:40 +02:00
|
|
|
|
2002-08-08 08:35:26 +02:00
|
|
|
return perform_default_encoding_conversion(s, len, true);
|
2001-08-15 09:07:40 +02:00
|
|
|
}
|
|
|
|
|
1998-07-24 05:32:46 +02:00
|
|
|
/*
|
1999-09-12 00:28:11 +02:00
|
|
|
* convert server encoding to client encoding.
|
1998-07-24 05:32:46 +02:00
|
|
|
*/
|
2005-09-24 19:53:28 +02:00
|
|
|
char *
|
|
|
|
pg_server_to_client(const char *s, int len)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
Assert(DatabaseEncoding);
|
2001-09-09 03:15:11 +02:00
|
|
|
Assert(ClientEncoding);
|
2001-09-08 16:30:15 +02:00
|
|
|
|
2006-05-21 22:05:21 +02:00
|
|
|
if (len <= 0)
|
2005-09-24 19:53:28 +02:00
|
|
|
return (char *) s;
|
2001-08-15 09:07:40 +02:00
|
|
|
|
2006-05-21 22:05:21 +02:00
|
|
|
if (ClientEncoding->encoding == DatabaseEncoding->encoding ||
|
|
|
|
ClientEncoding->encoding == PG_SQL_ASCII ||
|
|
|
|
DatabaseEncoding->encoding == PG_SQL_ASCII)
|
|
|
|
return (char *) s; /* assume data is valid */
|
|
|
|
|
2002-08-08 08:35:26 +02:00
|
|
|
return perform_default_encoding_conversion(s, len, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-04 22:31:48 +02:00
|
|
|
* Perform default encoding conversion using cached FmgrInfo. Since
|
|
|
|
* this function does not access database at all, it is safe to call
|
|
|
|
* outside transactions. Explicit setting client encoding required
|
|
|
|
* before calling this function. Otherwise no conversion is
|
|
|
|
* performed.
|
2002-08-08 08:35:26 +02:00
|
|
|
*/
|
2005-09-24 19:53:28 +02:00
|
|
|
static char *
|
|
|
|
perform_default_encoding_conversion(const char *src, int len, bool is_client_to_server)
|
2002-08-08 08:35:26 +02:00
|
|
|
{
|
2005-09-24 19:53:28 +02:00
|
|
|
char *result;
|
2002-09-04 22:31:48 +02:00
|
|
|
int src_encoding,
|
|
|
|
dest_encoding;
|
|
|
|
FmgrInfo *flinfo;
|
2002-11-26 03:22:29 +01:00
|
|
|
|
2002-08-08 08:35:26 +02:00
|
|
|
if (is_client_to_server)
|
|
|
|
{
|
|
|
|
src_encoding = ClientEncoding->encoding;
|
|
|
|
dest_encoding = DatabaseEncoding->encoding;
|
2002-11-02 19:41:22 +01:00
|
|
|
flinfo = ToServerConvProc;
|
2002-08-08 08:35:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src_encoding = DatabaseEncoding->encoding;
|
|
|
|
dest_encoding = ClientEncoding->encoding;
|
2002-11-02 19:41:22 +01:00
|
|
|
flinfo = ToClientConvProc;
|
2002-08-08 08:35:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flinfo == NULL)
|
2005-09-24 19:53:28 +02:00
|
|
|
return (char *) src;
|
2002-08-08 08:35:26 +02:00
|
|
|
|
2007-05-28 18:43:24 +02:00
|
|
|
/*
|
|
|
|
* Allocate space for conversion result, being wary of integer overflow
|
|
|
|
*/
|
|
|
|
if ((Size) len >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
|
|
|
errmsg("out of memory"),
|
|
|
|
errdetail("String of %d bytes is too long for encoding conversion.",
|
|
|
|
len)));
|
|
|
|
|
|
|
|
result = palloc(len * MAX_CONVERSION_GROWTH + 1);
|
2002-08-08 08:35:26 +02:00
|
|
|
|
|
|
|
FunctionCall5(flinfo,
|
|
|
|
Int32GetDatum(src_encoding),
|
|
|
|
Int32GetDatum(dest_encoding),
|
|
|
|
CStringGetDatum(src),
|
|
|
|
CStringGetDatum(result),
|
|
|
|
Int32GetDatum(len));
|
|
|
|
return result;
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
2002-09-03 23:45:44 +02:00
|
|
|
/* convert a multibyte string to a wchar */
|
2000-08-27 12:40:48 +02:00
|
|
|
int
|
2005-09-24 19:53:28 +02:00
|
|
|
pg_mb2wchar(const char *from, pg_wchar *to)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
2005-09-24 19:53:28 +02:00
|
|
|
return (*pg_wchar_table[DatabaseEncoding->encoding].mb2wchar_with_len) ((const unsigned char *) from, to, strlen(from));
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
2002-09-03 23:45:44 +02:00
|
|
|
/* convert a multibyte string to a wchar with a limited length */
|
2000-08-27 12:40:48 +02:00
|
|
|
int
|
2005-09-24 19:53:28 +02:00
|
|
|
pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
2005-09-24 19:53:28 +02:00
|
|
|
return (*pg_wchar_table[DatabaseEncoding->encoding].mb2wchar_with_len) ((const unsigned char *) from, to, len);
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
2006-12-24 01:57:48 +01:00
|
|
|
/* same, with any encoding */
|
|
|
|
int
|
|
|
|
pg_encoding_mb2wchar_with_len(int encoding,
|
|
|
|
const char *from, pg_wchar *to, int len)
|
|
|
|
{
|
|
|
|
return (*pg_wchar_table[encoding].mb2wchar_with_len) ((const unsigned char *) from, to, len);
|
|
|
|
}
|
|
|
|
|
2002-09-03 23:45:44 +02:00
|
|
|
/* returns the byte length of a multibyte word */
|
1998-09-01 06:40:42 +02:00
|
|
|
int
|
2005-09-24 19:53:28 +02:00
|
|
|
pg_mblen(const char *mbstr)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
2005-09-24 19:53:28 +02:00
|
|
|
return ((*pg_wchar_table[DatabaseEncoding->encoding].mblen) ((const unsigned char *) mbstr));
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
2004-03-15 11:41:26 +01:00
|
|
|
/* returns the display length of a multibyte word */
|
|
|
|
int
|
2005-09-24 19:53:28 +02:00
|
|
|
pg_dsplen(const char *mbstr)
|
2004-03-15 11:41:26 +01:00
|
|
|
{
|
2005-09-24 19:53:28 +02:00
|
|
|
return ((*pg_wchar_table[DatabaseEncoding->encoding].dsplen) ((const unsigned char *) mbstr));
|
2004-03-15 11:41:26 +01:00
|
|
|
}
|
|
|
|
|
2005-09-24 19:53:28 +02:00
|
|
|
/* returns the length (counted in wchars) of a multibyte string */
|
1998-09-01 06:40:42 +02:00
|
|
|
int
|
2005-09-24 19:53:28 +02:00
|
|
|
pg_mbstrlen(const char *mbstr)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
int len = 0;
|
|
|
|
|
2002-08-29 09:22:30 +02:00
|
|
|
/* optimization for single byte encoding */
|
|
|
|
if (pg_database_encoding_max_length() == 1)
|
2005-09-24 19:53:28 +02:00
|
|
|
return strlen(mbstr);
|
2002-08-29 09:22:30 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
while (*mbstr)
|
|
|
|
{
|
|
|
|
mbstr += pg_mblen(mbstr);
|
|
|
|
len++;
|
|
|
|
}
|
2006-01-11 09:43:13 +01:00
|
|
|
return len;
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
2005-09-24 19:53:28 +02:00
|
|
|
/* returns the length (counted in wchars) of a multibyte string
|
2005-07-10 23:14:00 +02:00
|
|
|
* (not necessarily NULL terminated)
|
|
|
|
*/
|
1998-09-01 06:40:42 +02:00
|
|
|
int
|
2005-09-24 19:53:28 +02:00
|
|
|
pg_mbstrlen_with_len(const char *mbstr, int limit)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
1998-09-01 06:40:42 +02:00
|
|
|
int len = 0;
|
2005-07-10 23:14:00 +02:00
|
|
|
|
|
|
|
/* optimization for single byte encoding */
|
|
|
|
if (pg_database_encoding_max_length() == 1)
|
|
|
|
return limit;
|
1998-09-01 06:40:42 +02:00
|
|
|
|
2001-03-08 01:24:34 +01:00
|
|
|
while (limit > 0 && *mbstr)
|
1998-09-01 06:40:42 +02:00
|
|
|
{
|
2005-10-15 04:49:52 +02:00
|
|
|
int l = pg_mblen(mbstr);
|
2005-07-10 23:14:00 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
limit -= l;
|
|
|
|
mbstr += l;
|
|
|
|
len++;
|
|
|
|
}
|
2006-01-11 09:43:13 +01:00
|
|
|
return len;
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
1998-09-25 03:46:25 +02:00
|
|
|
/*
|
2002-09-03 23:45:44 +02:00
|
|
|
* returns the byte length of a multibyte string
|
1998-09-25 03:46:25 +02:00
|
|
|
* (not necessarily NULL terminated)
|
2001-07-15 13:07:37 +02:00
|
|
|
* that is no longer than limit.
|
2002-09-03 23:45:44 +02:00
|
|
|
* this function does not break multibyte word boundary.
|
1998-09-25 03:46:25 +02:00
|
|
|
*/
|
|
|
|
int
|
2005-09-24 19:53:28 +02:00
|
|
|
pg_mbcliplen(const char *mbstr, int len, int limit)
|
1998-09-25 03:46:25 +02:00
|
|
|
{
|
|
|
|
int clen = 0;
|
|
|
|
int l;
|
|
|
|
|
2002-08-29 09:22:30 +02:00
|
|
|
/* optimization for single byte encoding */
|
|
|
|
if (pg_database_encoding_max_length() == 1)
|
|
|
|
return cliplen(mbstr, len, limit);
|
|
|
|
|
2001-03-08 01:24:34 +01:00
|
|
|
while (len > 0 && *mbstr)
|
1998-09-25 03:46:25 +02:00
|
|
|
{
|
|
|
|
l = pg_mblen(mbstr);
|
1999-05-25 18:15:34 +02:00
|
|
|
if ((clen + l) > limit)
|
1998-09-25 03:46:25 +02:00
|
|
|
break;
|
|
|
|
clen += l;
|
1999-05-25 18:15:34 +02:00
|
|
|
if (clen == limit)
|
1998-09-25 03:46:25 +02:00
|
|
|
break;
|
|
|
|
len -= l;
|
|
|
|
mbstr += l;
|
|
|
|
}
|
2006-01-11 09:43:13 +01:00
|
|
|
return clen;
|
1998-09-25 03:46:25 +02:00
|
|
|
}
|
|
|
|
|
1998-07-24 05:32:46 +02:00
|
|
|
/*
|
2002-08-29 09:22:30 +02:00
|
|
|
* Similar to pg_mbcliplen except the limit parameter specifies the
|
2001-07-15 13:07:37 +02:00
|
|
|
* character length, not the byte length. */
|
|
|
|
int
|
2005-09-24 19:53:28 +02:00
|
|
|
pg_mbcharcliplen(const char *mbstr, int len, int limit)
|
2001-07-15 13:07:37 +02:00
|
|
|
{
|
|
|
|
int clen = 0;
|
|
|
|
int nch = 0;
|
|
|
|
int l;
|
|
|
|
|
2002-08-29 09:22:30 +02:00
|
|
|
/* optimization for single byte encoding */
|
|
|
|
if (pg_database_encoding_max_length() == 1)
|
|
|
|
return cliplen(mbstr, len, limit);
|
|
|
|
|
2001-07-15 13:07:37 +02:00
|
|
|
while (len > 0 && *mbstr)
|
|
|
|
{
|
|
|
|
l = pg_mblen(mbstr);
|
|
|
|
nch++;
|
|
|
|
if (nch > limit)
|
|
|
|
break;
|
|
|
|
clen += l;
|
|
|
|
len -= l;
|
|
|
|
mbstr += l;
|
|
|
|
}
|
2006-01-11 09:43:13 +01:00
|
|
|
return clen;
|
2001-07-15 13:07:37 +02:00
|
|
|
}
|
|
|
|
|
1998-07-24 05:32:46 +02:00
|
|
|
void
|
|
|
|
SetDatabaseEncoding(int encoding)
|
|
|
|
{
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
if (!PG_VALID_BE_ENCODING(encoding))
|
2006-12-21 17:05:16 +01:00
|
|
|
elog(ERROR, "invalid database encoding: %d", encoding);
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
DatabaseEncoding = &pg_enc2name_tbl[encoding];
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
Assert(DatabaseEncoding->encoding == encoding);
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
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
2002-07-18 04:02:30 +02:00
|
|
|
void
|
2004-10-13 03:25:13 +02:00
|
|
|
SetDefaultClientEncoding(void)
|
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
2002-07-18 04:02:30 +02:00
|
|
|
{
|
|
|
|
ClientEncoding = &pg_enc2name_tbl[GetDatabaseEncoding()];
|
|
|
|
}
|
|
|
|
|
1998-07-24 05:32:46 +02:00
|
|
|
int
|
2001-09-21 17:27:38 +02:00
|
|
|
GetDatabaseEncoding(void)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
Assert(DatabaseEncoding);
|
2006-01-11 09:43:13 +01:00
|
|
|
return DatabaseEncoding->encoding;
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2001-09-21 17:27:38 +02:00
|
|
|
GetDatabaseEncodingName(void)
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
{
|
|
|
|
Assert(DatabaseEncoding);
|
2006-01-11 09:43:13 +01:00
|
|
|
return DatabaseEncoding->name;
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
|
|
|
|
2000-06-13 09:35:40 +02:00
|
|
|
Datum
|
|
|
|
getdatabaseencoding(PG_FUNCTION_ARGS)
|
1998-07-24 05:32:46 +02:00
|
|
|
{
|
Commit Karel's patch.
-------------------------------------------------------------------
Subject: Re: [PATCHES] encoding names
From: Karel Zak <zakkr@zf.jcu.cz>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-patches <pgsql-patches@postgresql.org>
Date: Fri, 31 Aug 2001 17:24:38 +0200
On Thu, Aug 30, 2001 at 01:30:40AM +0200, Peter Eisentraut wrote:
> > - convert encoding 'name' to 'id'
>
> I thought we decided not to add functions returning "new" names until we
> know exactly what the new names should be, and pending schema
Ok, the patch not to add functions.
> better
>
> ...(): encoding name too long
Fixed.
I found new bug in command/variable.c in parse_client_encoding(), nobody
probably never see this error:
if (pg_set_client_encoding(encoding))
{
elog(ERROR, "Conversion between %s and %s is not supported",
value, GetDatabaseEncodingName());
}
because pg_set_client_encoding() returns -1 for error and 0 as true.
It's fixed too.
IMHO it can be apply.
Karel
PS:
* following files are renamed:
src/utils/mb/Unicode/KOI8_to_utf8.map -->
src/utils/mb/Unicode/koi8r_to_utf8.map
src/utils/mb/Unicode/WIN_to_utf8.map -->
src/utils/mb/Unicode/win1251_to_utf8.map
src/utils/mb/Unicode/utf8_to_KOI8.map -->
src/utils/mb/Unicode/utf8_to_koi8r.map
src/utils/mb/Unicode/utf8_to_WIN.map -->
src/utils/mb/Unicode/utf8_to_win1251.map
* new file:
src/utils/mb/encname.c
* removed file:
src/utils/mb/common.c
--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/
C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz
2001-09-06 06:57:30 +02:00
|
|
|
Assert(DatabaseEncoding);
|
|
|
|
return DirectFunctionCall1(namein, CStringGetDatum(DatabaseEncoding->name));
|
1998-07-24 05:32:46 +02:00
|
|
|
}
|
2001-10-12 04:08:34 +02:00
|
|
|
|
|
|
|
Datum
|
|
|
|
pg_client_encoding(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Assert(ClientEncoding);
|
|
|
|
return DirectFunctionCall1(namein, CStringGetDatum(ClientEncoding->name));
|
|
|
|
}
|
2002-08-29 09:22:30 +02:00
|
|
|
|
|
|
|
static int
|
2005-09-24 19:53:28 +02:00
|
|
|
cliplen(const char *str, int len, int limit)
|
2002-08-29 09:22:30 +02:00
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
int l = 0;
|
2005-09-24 19:53:28 +02:00
|
|
|
const char *s;
|
2002-08-29 09:22:30 +02:00
|
|
|
|
|
|
|
for (s = str; *s; s++, l++)
|
|
|
|
{
|
|
|
|
if (l >= len || l >= limit)
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
return (s - str);
|
|
|
|
}
|