From f426465ba911051fa9fce57c7c4b49350e9dbbd3 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Fri, 12 Oct 2001 02:08:34 +0000 Subject: [PATCH] Add a new function "pg_client_encoding" which returns the current client side encoding name. This is necessary for client API's such as JDBC to perform correct encoding conversions. See my email "[HACKERS] pg_client_encoding" 10 Sep 2001. --- doc/src/sgml/func.sgml | 12 +++++++++++- src/backend/utils/init/miscinit.c | 8 +++++++- src/backend/utils/mb/mbutils.c | 9 ++++++++- src/include/catalog/pg_proc.h | 8 ++++++-- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 334a8a9ee5..3cbd8cdf6b 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1,4 +1,4 @@ - + Functions and Operators @@ -1008,6 +1008,16 @@ trim + + pg_client_encoding() + name + + Returns current client encoding name. + + pg_client_encoding() + SQL_ASCII + + repeat(text, integer) text diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index e6da787bc4..6f6bc5f9fd 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.77 2001/09/08 15:24:00 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.78 2001/10/12 02:08:34 ishii Exp $ * *------------------------------------------------------------------------- */ @@ -197,6 +197,12 @@ getdatabaseencoding(PG_FUNCTION_ARGS) return DirectFunctionCall1(namein, CStringGetDatum("SQL_ASCII")); } +Datum +pg_client_encoding(PG_FUNCTION_ARGS) +{ + return DirectFunctionCall1(namein, CStringGetDatum("SQL_ASCII")); +} + Datum PG_encoding_to_char(PG_FUNCTION_ARGS) { diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index 177cd3a1d6..c0949a6324 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -3,7 +3,7 @@ * client encoding and server internal encoding. * (currently mule internal code (mic) is used) * Tatsuo Ishii - * $Id: mbutils.c,v 1.23 2001/09/21 15:27:38 tgl Exp $ + * $Id: mbutils.c,v 1.24 2001/10/12 02:08:34 ishii Exp $ */ #include "postgres.h" @@ -471,3 +471,10 @@ getdatabaseencoding(PG_FUNCTION_ARGS) Assert(DatabaseEncoding); return DirectFunctionCall1(namein, CStringGetDatum(DatabaseEncoding->name)); } + +Datum +pg_client_encoding(PG_FUNCTION_ARGS) +{ + Assert(ClientEncoding); + return DirectFunctionCall1(namein, CStringGetDatum(ClientEncoding->name)); +} diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 92a675174d..7f179d9630 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pg_proc.h,v 1.215 2001/10/03 17:22:05 tgl Exp $ + * $Id: pg_proc.h,v 1.216 2001/10/12 02:08:34 ishii Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -2140,10 +2140,14 @@ DESCR("return portion of string"); /* for multi-byte support */ -/* old encoding names - back compatibility only */ +/* return database encoding name */ DATA(insert OID = 1039 ( getdatabaseencoding PGUID 12 f t f t 0 f 19 "0" 100 0 0 100 getdatabaseencoding - )); DESCR("encoding name of current database"); +/* return client encoding name i.e. session encoding */ +DATA(insert OID = 810 ( pg_client_encoding PGUID 12 f t f t 0 f 19 "0" 100 0 0 100 pg_client_encoding - )); +DESCR("encoding name of current database"); + DATA(insert OID = 1717 ( convert PGUID 12 f t f t 2 f 25 "25 19" 100 0 0 100 pg_convert - )); DESCR("convert string with specified destination encoding name");