11
11
*
12
12
*
13
13
* IDENTIFICATION
14
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.197 2000/10/22 23:32:48 tgl Exp $
14
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.198 2000/10/25 18:56:16 tgl Exp $
15
15
*
16
16
* HISTORY
17
17
* AUTHOR DATE MAJOR EVENT
55
55
#ifdef MULTIBYTE
56
56
#include " miscadmin.h"
57
57
#include " mb/pg_wchar.h"
58
+ #else
59
+ #define GetTemplateEncoding () 0 /* SQL_ASCII */
60
+ #define GetTemplateEncodingName () " SQL_ASCII"
58
61
#endif
59
62
60
63
extern List *parsetree; /* final parse result is delivered here */
@@ -677,11 +680,7 @@ CreateSchemaStmt: CREATE SCHEMA UserId
677
680
CreatedbStmt *n = makeNode(CreatedbStmt);
678
681
n->dbname = $3 ;
679
682
n->dbpath = NULL ;
680
- #ifdef MULTIBYTE
681
683
n->encoding = GetTemplateEncoding();
682
- #else
683
- n->encoding = 0 ;
684
- #endif
685
684
$$ = (Node *)n;
686
685
}
687
686
;
@@ -788,14 +787,10 @@ VariableSetStmt: SET ColId TO var_value
788
787
}
789
788
| SET NAMES opt_encoding
790
789
{
791
- #ifdef MULTIBYTE
792
790
VariableSetStmt *n = makeNode(VariableSetStmt);
793
791
n->name = " client_encoding" ;
794
792
n->value = $3 ;
795
793
$$ = (Node *) n;
796
- #else
797
- elog (ERROR, " SET NAMES is not supported" );
798
- #endif
799
794
}
800
795
;
801
796
@@ -813,47 +808,47 @@ var_value: opt_boolean { $$ = $1; }
813
808
}
814
809
| ' -' ICONST
815
810
{
816
- char buf[64 ];
817
- sprintf (buf, " %d" , -($2 ));
818
- $$ = pstrdup(buf);
819
- }
811
+ char buf[64 ];
812
+ sprintf (buf, " %d" , -($2 ));
813
+ $$ = pstrdup(buf);
814
+ }
820
815
| FCONST { $$ = $1 ; }
821
816
| ' -' FCONST
822
817
{
823
- char * s = palloc(strlen($2 )+2 );
824
- s[0 ] = ' -' ;
825
- strcpy (s + 1 , $2 );
826
- $$ = s;
827
- }
818
+ char * s = palloc(strlen($2 )+2 );
819
+ s[0 ] = ' -' ;
820
+ strcpy (s + 1 , $2 );
821
+ $$ = s;
822
+ }
828
823
| name_list
829
824
{
830
- List *n;
831
- int slen = 0 ;
832
- char *result;
825
+ List *n;
826
+ int slen = 0 ;
827
+ char *result;
833
828
834
- /* List of words? Then concatenate together */
835
- if ($1 == NIL)
836
- elog (ERROR, " SET must have at least one argument" );
829
+ /* List of words? Then concatenate together */
830
+ if ($1 == NIL)
831
+ elog (ERROR, " SET must have at least one argument" );
837
832
838
- foreach (n, $1 )
839
- {
840
- Value *p = (Value *) lfirst (n);
841
- Assert (IsA (p, String));
842
- /* keep track of room for string and trailing comma */
843
- slen += (strlen (p->val .str ) + 1 );
844
- }
845
- result = palloc(slen + 1 );
846
- *result = ' \0 ' ;
847
- foreach (n, $1 )
848
- {
849
- Value *p = (Value *) lfirst (n);
850
- strcat (result, p->val .str );
851
- strcat (result, " ," );
833
+ foreach (n, $1 )
834
+ {
835
+ Value *p = (Value *) lfirst (n);
836
+ Assert (IsA (p, String));
837
+ /* keep track of room for string and trailing comma */
838
+ slen += (strlen (p->val .str ) + 1 );
839
+ }
840
+ result = palloc(slen + 1 );
841
+ *result = ' \0 ' ;
842
+ foreach (n, $1 )
843
+ {
844
+ Value *p = (Value *) lfirst (n);
845
+ strcat (result, p->val .str );
846
+ strcat (result, " ," );
847
+ }
848
+ /* remove the trailing comma from the last element */
849
+ *(result+strlen(result)-1 ) = ' \0 ' ;
850
+ $$ = result;
852
851
}
853
- /* remove the trailing comma from the last element */
854
- *(result+strlen(result)-1 ) = ' \0 ' ;
855
- $$ = result;
856
- }
857
852
| DEFAULT { $$ = NULL ; }
858
853
;
859
854
@@ -2895,27 +2890,22 @@ LoadStmt: LOAD file_name
2895
2890
2896
2891
CreatedbStmt : CREATE DATABASE database_name WITH createdb_opt_location createdb_opt_encoding
2897
2892
{
2898
- CreatedbStmt *n;
2893
+ CreatedbStmt *n = makeNode(CreatedbStmt) ;
2899
2894
2900
2895
if ($5 == NULL && $6 == -1 )
2901
2896
elog (ERROR, " CREATE DATABASE WITH requires at least one option" );
2902
2897
2903
- n = makeNode(CreatedbStmt);
2904
2898
n->dbname = $3 ;
2905
2899
n->dbpath = $5 ;
2906
- n->encoding = $6 ;
2900
+ n->encoding = ( $6 == - 1 ) ? GetTemplateEncoding() : $6 ;
2907
2901
$$ = (Node *)n;
2908
2902
}
2909
2903
| CREATE DATABASE database_name
2910
2904
{
2911
2905
CreatedbStmt *n = makeNode(CreatedbStmt);
2912
2906
n->dbname = $3 ;
2913
2907
n->dbpath = NULL ;
2914
- #ifdef MULTIBYTE
2915
2908
n->encoding = GetTemplateEncoding();
2916
- #else
2917
- n->encoding = 0 ;
2918
- #endif
2919
2909
$$ = (Node *)n;
2920
2910
}
2921
2911
;
@@ -2928,40 +2918,33 @@ createdb_opt_location: LOCATION '=' Sconst { $$ = $3; }
2928
2918
createdb_opt_encoding : ENCODING ' =' Sconst
2929
2919
{
2930
2920
#ifdef MULTIBYTE
2931
- int i;
2932
- i = pg_char_to_encoding($3 );
2933
- if (i == -1 )
2921
+ $$ = pg_char_to_encoding($3 );
2922
+ if ($$ == -1 )
2934
2923
elog (ERROR, " %s is not a valid encoding name" , $3 );
2935
- $$ = i;
2936
2924
#else
2937
- elog (ERROR, " Multi-byte support is not enabled" );
2925
+ if (strcasecmp($3 , GetTemplateEncodingName()) != 0 )
2926
+ elog (ERROR, " Multi-byte support is not enabled" );
2927
+ $$ = GetTemplateEncoding();
2938
2928
#endif
2939
2929
}
2940
2930
| ENCODING ' =' Iconst
2941
2931
{
2942
2932
#ifdef MULTIBYTE
2943
2933
if (!pg_get_encent_by_encoding($3 ))
2944
2934
elog (ERROR, " %d is not a valid encoding code" , $3 );
2945
- $$ = $3 ;
2946
2935
#else
2947
- elog (ERROR, " Multi-byte support is not enabled" );
2936
+ if ($3 != GetTemplateEncoding())
2937
+ elog (ERROR, " Multi-byte support is not enabled" );
2948
2938
#endif
2939
+ $$ = $3 ;
2949
2940
}
2950
2941
| ENCODING ' =' DEFAULT
2951
2942
{
2952
- #ifdef MULTIBYTE
2953
2943
$$ = GetTemplateEncoding();
2954
- #else
2955
- $$ = 0 ;
2956
- #endif
2957
2944
}
2958
2945
| /* EMPTY*/
2959
2946
{
2960
- #ifdef MULTIBYTE
2961
- $$ = GetTemplateEncoding();
2962
- #else
2963
- $$= 0 ;
2964
- #endif
2947
+ $$ = -1 ;
2965
2948
}
2966
2949
;
2967
2950
0 commit comments