1111 *
1212 *
1313 * 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 $
1515 *
1616 * HISTORY
1717 * AUTHORDATEMAJOR EVENT
5555#ifdef MULTIBYTE
5656#include " miscadmin.h"
5757#include " mb/pg_wchar.h"
58+ #else
59+ #define GetTemplateEncoding ()0 /* SQL_ASCII*/
60+ #define GetTemplateEncodingName ()" SQL_ASCII"
5861#endif
5962
6063extern List *parsetree;/* final parse result is delivered here*/
@@ -677,11 +680,7 @@ CreateSchemaStmt: CREATE SCHEMA UserId
677680CreatedbStmt *n = makeNode(CreatedbStmt);
678681n->dbname =$3 ;
679682n->dbpath =NULL ;
680- #ifdef MULTIBYTE
681683n->encoding = GetTemplateEncoding();
682- #else
683- n->encoding =0 ;
684- #endif
685684$$ = (Node *)n;
686685}
687686;
@@ -788,14 +787,10 @@ VariableSetStmt: SET ColId TO var_value
788787}
789788| SET NAMES opt_encoding
790789{
791- #ifdef MULTIBYTE
792790VariableSetStmt *n = makeNode(VariableSetStmt);
793791n->name =" client_encoding" ;
794792n->value =$3 ;
795793$$ = (Node *) n;
796- #else
797- elog (ERROR," SET NAMES is not supported" );
798- #endif
799794}
800795;
801796
@@ -813,47 +808,47 @@ var_value: opt_boolean{ $$ = $1; }
813808}
814809| ' -' ICONST
815810{
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+ }
820815| FCONST {$$ =$1 ; }
821816| ' -' FCONST
822817{
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+ }
828823| name_list
829824{
830- List *n;
831- int slen =0 ;
832- char *result;
825+ List *n;
826+ int slen =0 ;
827+ char *result;
833828
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" );
837832
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;
852851}
853- /* remove the trailing comma from the last element*/
854- *(result+strlen(result)-1 ) =' \0 ' ;
855- $$ = result;
856- }
857852| DEFAULT {$$ =NULL ; }
858853;
859854
@@ -2895,27 +2890,22 @@ LoadStmt: LOAD file_name
28952890
28962891CreatedbStmt :CREATE DATABASE database_name WITH createdb_opt_location createdb_opt_encoding
28972892{
2898- CreatedbStmt *n;
2893+ CreatedbStmt *n = makeNode(CreatedbStmt) ;
28992894
29002895if ($5 ==NULL &&$6 == -1 )
29012896elog (ERROR," CREATE DATABASE WITH requires at least one option" );
29022897
2903- n = makeNode(CreatedbStmt);
29042898n->dbname =$3 ;
29052899n->dbpath =$5 ;
2906- n->encoding =$6 ;
2900+ n->encoding =( $6 == - 1 ) ? GetTemplateEncoding() : $6 ;
29072901$$ = (Node *)n;
29082902}
29092903| CREATE DATABASE database_name
29102904{
29112905CreatedbStmt *n = makeNode(CreatedbStmt);
29122906n->dbname =$3 ;
29132907n->dbpath =NULL ;
2914- #ifdef MULTIBYTE
29152908n->encoding = GetTemplateEncoding();
2916- #else
2917- n->encoding =0 ;
2918- #endif
29192909$$ = (Node *)n;
29202910}
29212911;
@@ -2928,40 +2918,33 @@ createdb_opt_location: LOCATION '=' Sconst{ $$ = $3; }
29282918createdb_opt_encoding :ENCODING ' =' Sconst
29292919{
29302920#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 )
29342923elog (ERROR," %s is not a valid encoding name" , $3 );
2935- $$ = i;
29362924#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();
29382928#endif
29392929}
29402930| ENCODING ' =' Iconst
29412931{
29422932#ifdef MULTIBYTE
29432933if (!pg_get_encent_by_encoding($3 ))
29442934elog (ERROR," %d is not a valid encoding code" , $3 );
2945- $$ = $3 ;
29462935#else
2947- elog (ERROR," Multi-byte support is not enabled" );
2936+ if ($3 != GetTemplateEncoding())
2937+ elog (ERROR," Multi-byte support is not enabled" );
29482938#endif
2939+ $$ =$3 ;
29492940}
29502941| ENCODING ' =' DEFAULT
29512942{
2952- #ifdef MULTIBYTE
29532943$$ = GetTemplateEncoding();
2954- #else
2955- $$ =0 ;
2956- #endif
29572944}
29582945| /* EMPTY*/
29592946{
2960- #ifdef MULTIBYTE
2961- $$ = GetTemplateEncoding();
2962- #else
2963- $$=0 ;
2964- #endif
2947+ $$ = -1 ;
29652948}
29662949;
29672950