99 *
1010 *
1111 * IDENTIFICATION
12- * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.41 2000/09/22 15:34:31 tgl Exp $
12+ * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.42 2000/10/25 19:44:44 tgl Exp $
1313 *
1414 *-------------------------------------------------------------------------
1515 */
1616
17+ #include "postgres.h"
18+
1719#include <ctype.h>
1820#include <time.h>
1921
20- #include "postgres.h"
21-
2222#include "access/xact.h"
2323#include "catalog/pg_shadow.h"
2424#include "commands/variable.h"
3232
3333#ifdef MULTIBYTE
3434#include "mb/pg_wchar.h"
35+ #else
36+ /* Grand unified hard-coded badness */
37+ #define pg_encoding_to_char (x ) "SQL_ASCII"
38+ #define pg_get_client_encoding () 0
3539#endif
3640
3741
38-
3942static bool show_date (void );
4043static bool reset_date (void );
4144static bool parse_date (char * );
@@ -53,6 +56,13 @@ static bool parse_random_seed(char *);
5356static bool show_random_seed (void );
5457static bool reset_random_seed (void );
5558
59+ static bool show_client_encoding (void );
60+ static bool reset_client_encoding (void );
61+ static bool parse_client_encoding (char * );
62+ static bool show_server_encoding (void );
63+ static bool reset_server_encoding (void );
64+ static bool parse_server_encoding (char * );
65+
5666
5767/*
5868 * get_token
@@ -250,7 +260,7 @@ parse_date(char *value)
250260}
251261
252262static bool
253- show_date ()
263+ show_date (void )
254264{
255265char buf [64 ];
256266
@@ -280,7 +290,7 @@ show_date()
280290}
281291
282292static bool
283- reset_date ()
293+ reset_date (void )
284294{
285295DateStyle = DefaultDateStyle ;
286296EuroDates = DefaultEuroDates ;
@@ -379,7 +389,7 @@ parse_timezone(char *value)
379389}/* parse_timezone() */
380390
381391static bool
382- show_timezone ()
392+ show_timezone (void )
383393{
384394char * tz ;
385395
@@ -401,7 +411,7 @@ show_timezone()
401411 * - thomas 1998-01-26
402412 */
403413static bool
404- reset_timezone ()
414+ reset_timezone (void )
405415{
406416/* no time zone has been set in this session? */
407417if (defaultTZ == NULL )
@@ -470,7 +480,7 @@ parse_DefaultXactIsoLevel(char *value)
470480}
471481
472482static bool
473- show_DefaultXactIsoLevel ()
483+ show_DefaultXactIsoLevel (void )
474484{
475485
476486if (DefaultXactIsoLevel == XACT_SERIALIZABLE )
@@ -481,7 +491,7 @@ show_DefaultXactIsoLevel()
481491}
482492
483493static bool
484- reset_DefaultXactIsoLevel ()
494+ reset_DefaultXactIsoLevel (void )
485495{
486496#if 0
487497TransactionState s = CurrentTransactionState ;
@@ -527,7 +537,7 @@ parse_XactIsoLevel(char *value)
527537}
528538
529539static bool
530- show_XactIsoLevel ()
540+ show_XactIsoLevel (void )
531541{
532542
533543if (XactIsoLevel == XACT_SERIALIZABLE )
@@ -538,7 +548,7 @@ show_XactIsoLevel()
538548}
539549
540550static bool
541- reset_XactIsoLevel ()
551+ reset_XactIsoLevel (void )
542552{
543553
544554if (SerializableSnapshot != NULL )
@@ -588,6 +598,96 @@ reset_random_seed(void)
588598}
589599
590600
601+ /*
602+ * MULTIBYTE-related functions
603+ *
604+ * If MULTIBYTE support was not compiled, we still allow these variables
605+ * to exist, but you can't set them to anything but "SQL_ASCII". This
606+ * minimizes interoperability problems between non-MB servers and MB-enabled
607+ * clients.
608+ */
609+
610+ static bool
611+ parse_client_encoding (char * value )
612+ {
613+ #ifdef MULTIBYTE
614+ int encoding ;
615+
616+ encoding = pg_valid_client_encoding (value );
617+ if (encoding < 0 )
618+ {
619+ if (value )
620+ elog (ERROR ,"Client encoding %s is not supported" ,value );
621+ else
622+ elog (ERROR ,"No client encoding is specified" );
623+ }
624+ else
625+ {
626+ if (pg_set_client_encoding (encoding ))
627+ {
628+ elog (ERROR ,"Conversion between %s and %s is not supported" ,
629+ value ,pg_encoding_to_char (GetDatabaseEncoding ()));
630+ }
631+ }
632+ #else
633+ if (value &&
634+ strcasecmp (value ,pg_encoding_to_char (pg_get_client_encoding ()))!= 0 )
635+ elog (ERROR ,"Client encoding %s is not supported" ,value );
636+ #endif
637+ return TRUE;
638+ }
639+
640+ static bool
641+ show_client_encoding (void )
642+ {
643+ elog (NOTICE ,"Current client encoding is %s" ,
644+ pg_encoding_to_char (pg_get_client_encoding ()));
645+ return TRUE;
646+ }
647+
648+ static bool
649+ reset_client_encoding (void )
650+ {
651+ #ifdef MULTIBYTE
652+ int encoding ;
653+ char * env = getenv ("PGCLIENTENCODING" );
654+
655+ if (env )
656+ {
657+ encoding = pg_char_to_encoding (env );
658+ if (encoding < 0 )
659+ encoding = GetDatabaseEncoding ();
660+ }
661+ else
662+ encoding = GetDatabaseEncoding ();
663+ pg_set_client_encoding (encoding );
664+ #endif
665+ return TRUE;
666+ }
667+
668+ static bool
669+ parse_server_encoding (char * value )
670+ {
671+ elog (NOTICE ,"SET SERVER_ENCODING is not supported" );
672+ return TRUE;
673+ }
674+
675+ static bool
676+ show_server_encoding (void )
677+ {
678+ elog (NOTICE ,"Current server encoding is %s" ,
679+ pg_encoding_to_char (GetDatabaseEncoding ()));
680+ return TRUE;
681+ }
682+
683+ static bool
684+ reset_server_encoding (void )
685+ {
686+ elog (NOTICE ,"RESET SERVER_ENCODING is not supported" );
687+ return TRUE;
688+ }
689+
690+
591691
592692void
593693SetPGVariable (const char * name ,const char * value )
@@ -606,12 +706,10 @@ SetPGVariable(const char *name, const char *value)
606706parse_DefaultXactIsoLevel (mvalue );
607707else if (strcasecmp (name ,"XactIsoLevel" )== 0 )
608708parse_XactIsoLevel (mvalue );
609- #ifdef MULTIBYTE
610709else if (strcasecmp (name ,"client_encoding" )== 0 )
611710parse_client_encoding (mvalue );
612711else if (strcasecmp (name ,"server_encoding" )== 0 )
613712parse_server_encoding (mvalue );
614- #endif
615713else if (strcasecmp (name ,"random_seed" )== 0 )
616714parse_random_seed (mvalue );
617715else
@@ -633,12 +731,10 @@ GetPGVariable(const char *name)
633731show_DefaultXactIsoLevel ();
634732else if (strcasecmp (name ,"XactIsoLevel" )== 0 )
635733show_XactIsoLevel ();
636- #ifdef MULTIBYTE
637734else if (strcasecmp (name ,"client_encoding" )== 0 )
638735show_client_encoding ();
639736else if (strcasecmp (name ,"server_encoding" )== 0 )
640737show_server_encoding ();
641- #endif
642738else if (strcasecmp (name ,"random_seed" )== 0 )
643739show_random_seed ();
644740else
@@ -659,12 +755,10 @@ ResetPGVariable(const char *name)
659755reset_DefaultXactIsoLevel ();
660756else if (strcasecmp (name ,"XactIsoLevel" )== 0 )
661757reset_XactIsoLevel ();
662- #ifdef MULTIBYTE
663758else if (strcasecmp (name ,"client_encoding" )== 0 )
664759reset_client_encoding ();
665760else if (strcasecmp (name ,"server_encoding" )== 0 )
666761reset_server_encoding ();
667- #endif
668762else if (strcasecmp (name ,"random_seed" )== 0 )
669763reset_random_seed ();
670764else