9
9
*
10
10
*
11
11
* 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 $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
16
16
17
+ #include "postgres.h"
18
+
17
19
#include <ctype.h>
18
20
#include <time.h>
19
21
20
- #include "postgres.h"
21
-
22
22
#include "access/xact.h"
23
23
#include "catalog/pg_shadow.h"
24
24
#include "commands/variable.h"
32
32
33
33
#ifdef MULTIBYTE
34
34
#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
35
39
#endif
36
40
37
41
38
-
39
42
static bool show_date (void );
40
43
static bool reset_date (void );
41
44
static bool parse_date (char * );
@@ -53,6 +56,13 @@ static bool parse_random_seed(char *);
53
56
static bool show_random_seed (void );
54
57
static bool reset_random_seed (void );
55
58
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
+
56
66
57
67
/*
58
68
* get_token
@@ -250,7 +260,7 @@ parse_date(char *value)
250
260
}
251
261
252
262
static bool
253
- show_date ()
263
+ show_date (void )
254
264
{
255
265
char buf [64 ];
256
266
@@ -280,7 +290,7 @@ show_date()
280
290
}
281
291
282
292
static bool
283
- reset_date ()
293
+ reset_date (void )
284
294
{
285
295
DateStyle = DefaultDateStyle ;
286
296
EuroDates = DefaultEuroDates ;
@@ -379,7 +389,7 @@ parse_timezone(char *value)
379
389
} /* parse_timezone() */
380
390
381
391
static bool
382
- show_timezone ()
392
+ show_timezone (void )
383
393
{
384
394
char * tz ;
385
395
@@ -401,7 +411,7 @@ show_timezone()
401
411
* - thomas 1998-01-26
402
412
*/
403
413
static bool
404
- reset_timezone ()
414
+ reset_timezone (void )
405
415
{
406
416
/* no time zone has been set in this session? */
407
417
if (defaultTZ == NULL )
@@ -470,7 +480,7 @@ parse_DefaultXactIsoLevel(char *value)
470
480
}
471
481
472
482
static bool
473
- show_DefaultXactIsoLevel ()
483
+ show_DefaultXactIsoLevel (void )
474
484
{
475
485
476
486
if (DefaultXactIsoLevel == XACT_SERIALIZABLE )
@@ -481,7 +491,7 @@ show_DefaultXactIsoLevel()
481
491
}
482
492
483
493
static bool
484
- reset_DefaultXactIsoLevel ()
494
+ reset_DefaultXactIsoLevel (void )
485
495
{
486
496
#if 0
487
497
TransactionState s = CurrentTransactionState ;
@@ -527,7 +537,7 @@ parse_XactIsoLevel(char *value)
527
537
}
528
538
529
539
static bool
530
- show_XactIsoLevel ()
540
+ show_XactIsoLevel (void )
531
541
{
532
542
533
543
if (XactIsoLevel == XACT_SERIALIZABLE )
@@ -538,7 +548,7 @@ show_XactIsoLevel()
538
548
}
539
549
540
550
static bool
541
- reset_XactIsoLevel ()
551
+ reset_XactIsoLevel (void )
542
552
{
543
553
544
554
if (SerializableSnapshot != NULL )
@@ -588,6 +598,96 @@ reset_random_seed(void)
588
598
}
589
599
590
600
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
+
591
691
592
692
void
593
693
SetPGVariable (const char * name , const char * value )
@@ -606,12 +706,10 @@ SetPGVariable(const char *name, const char *value)
606
706
parse_DefaultXactIsoLevel (mvalue );
607
707
else if (strcasecmp (name , "XactIsoLevel" )== 0 )
608
708
parse_XactIsoLevel (mvalue );
609
- #ifdef MULTIBYTE
610
709
else if (strcasecmp (name , "client_encoding" )== 0 )
611
710
parse_client_encoding (mvalue );
612
711
else if (strcasecmp (name , "server_encoding" )== 0 )
613
712
parse_server_encoding (mvalue );
614
- #endif
615
713
else if (strcasecmp (name , "random_seed" )== 0 )
616
714
parse_random_seed (mvalue );
617
715
else
@@ -633,12 +731,10 @@ GetPGVariable(const char *name)
633
731
show_DefaultXactIsoLevel ();
634
732
else if (strcasecmp (name , "XactIsoLevel" )== 0 )
635
733
show_XactIsoLevel ();
636
- #ifdef MULTIBYTE
637
734
else if (strcasecmp (name , "client_encoding" )== 0 )
638
735
show_client_encoding ();
639
736
else if (strcasecmp (name , "server_encoding" )== 0 )
640
737
show_server_encoding ();
641
- #endif
642
738
else if (strcasecmp (name , "random_seed" )== 0 )
643
739
show_random_seed ();
644
740
else
@@ -659,12 +755,10 @@ ResetPGVariable(const char *name)
659
755
reset_DefaultXactIsoLevel ();
660
756
else if (strcasecmp (name , "XactIsoLevel" )== 0 )
661
757
reset_XactIsoLevel ();
662
- #ifdef MULTIBYTE
663
758
else if (strcasecmp (name , "client_encoding" )== 0 )
664
759
reset_client_encoding ();
665
760
else if (strcasecmp (name , "server_encoding" )== 0 )
666
761
reset_server_encoding ();
667
- #endif
668
762
else if (strcasecmp (name , "random_seed" )== 0 )
669
763
reset_random_seed ();
670
764
else
0 commit comments