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.
This commit is contained in:
Tatsuo Ishii 2001-10-12 02:08:34 +00:00
parent 9d13fcf0af
commit f426465ba9
4 changed files with 32 additions and 5 deletions

View File

@ -1,4 +1,4 @@
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.77 2001/10/10 00:02:42 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.78 2001/10/12 02:08:34 ishii Exp $ -->
<chapter id="functions"> <chapter id="functions">
<title>Functions and Operators</title> <title>Functions and Operators</title>
@ -1008,6 +1008,16 @@
<entry><literal>trim</literal></entry> <entry><literal>trim</literal></entry>
</row> </row>
<row>
<entry><function>pg_client_encoding</function>()</entry>
<entry><type>name</type></entry>
<entry>
Returns current client encoding name.
</entry>
<entry><literal>pg_client_encoding()</literal></entry>
<entry><literal>SQL_ASCII</literal></entry>
</row>
<row> <row>
<entry><function>repeat</function>(<type>text</type>, <type>integer</type>)</entry> <entry><function>repeat</function>(<type>text</type>, <type>integer</type>)</entry>
<entry><type>text</type></entry> <entry><type>text</type></entry>

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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")); return DirectFunctionCall1(namein, CStringGetDatum("SQL_ASCII"));
} }
Datum
pg_client_encoding(PG_FUNCTION_ARGS)
{
return DirectFunctionCall1(namein, CStringGetDatum("SQL_ASCII"));
}
Datum Datum
PG_encoding_to_char(PG_FUNCTION_ARGS) PG_encoding_to_char(PG_FUNCTION_ARGS)
{ {

View File

@ -3,7 +3,7 @@
* client encoding and server internal encoding. * client encoding and server internal encoding.
* (currently mule internal code (mic) is used) * (currently mule internal code (mic) is used)
* Tatsuo Ishii * 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" #include "postgres.h"
@ -471,3 +471,10 @@ getdatabaseencoding(PG_FUNCTION_ARGS)
Assert(DatabaseEncoding); Assert(DatabaseEncoding);
return DirectFunctionCall1(namein, CStringGetDatum(DatabaseEncoding->name)); return DirectFunctionCall1(namein, CStringGetDatum(DatabaseEncoding->name));
} }
Datum
pg_client_encoding(PG_FUNCTION_ARGS)
{
Assert(ClientEncoding);
return DirectFunctionCall1(namein, CStringGetDatum(ClientEncoding->name));
}

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 * NOTES
* The script catalog/genbki.sh reads this file and generates .bki * The script catalog/genbki.sh reads this file and generates .bki
@ -2140,10 +2140,14 @@ DESCR("return portion of string");
/* for multi-byte support */ /* 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 - )); 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"); 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 - )); 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"); DESCR("convert string with specified destination encoding name");