Commit f9453f46 authored by Tom Lane's avatar Tom Lane

Accept CREATE DATABASE WITH ENCODING 'SQL_ASCII' even when MULTIBYTE

support is not present.  This allows a non-MB server to load a pg_dumpall
script produced by an MB-enabled server, so long as only ASCII encoding
was used.
parent 53f300d4
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.197 2000/10/22 23:32:48 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.198 2000/10/25 18:56:16 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -55,6 +55,9 @@ ...@@ -55,6 +55,9 @@
#ifdef MULTIBYTE #ifdef MULTIBYTE
#include "miscadmin.h" #include "miscadmin.h"
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
#else
#define GetTemplateEncoding() 0 /* SQL_ASCII */
#define GetTemplateEncodingName() "SQL_ASCII"
#endif #endif
extern List *parsetree; /* final parse result is delivered here */ extern List *parsetree; /* final parse result is delivered here */
...@@ -677,11 +680,7 @@ CreateSchemaStmt: CREATE SCHEMA UserId ...@@ -677,11 +680,7 @@ CreateSchemaStmt: CREATE SCHEMA UserId
CreatedbStmt *n = makeNode(CreatedbStmt); CreatedbStmt *n = makeNode(CreatedbStmt);
n->dbname = $3; n->dbname = $3;
n->dbpath = NULL; n->dbpath = NULL;
#ifdef MULTIBYTE
n->encoding = GetTemplateEncoding(); n->encoding = GetTemplateEncoding();
#else
n->encoding = 0;
#endif
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
...@@ -788,14 +787,10 @@ VariableSetStmt: SET ColId TO var_value ...@@ -788,14 +787,10 @@ VariableSetStmt: SET ColId TO var_value
} }
| SET NAMES opt_encoding | SET NAMES opt_encoding
{ {
#ifdef MULTIBYTE
VariableSetStmt *n = makeNode(VariableSetStmt); VariableSetStmt *n = makeNode(VariableSetStmt);
n->name = "client_encoding"; n->name = "client_encoding";
n->value = $3; n->value = $3;
$$ = (Node *) n; $$ = (Node *) n;
#else
elog(ERROR, "SET NAMES is not supported");
#endif
} }
; ;
...@@ -813,47 +808,47 @@ var_value: opt_boolean { $$ = $1; } ...@@ -813,47 +808,47 @@ var_value: opt_boolean { $$ = $1; }
} }
| '-' ICONST | '-' ICONST
{ {
char buf[64]; char buf[64];
sprintf(buf, "%d", -($2)); sprintf(buf, "%d", -($2));
$$ = pstrdup(buf); $$ = pstrdup(buf);
} }
| FCONST { $$ = $1; } | FCONST { $$ = $1; }
| '-' FCONST | '-' FCONST
{ {
char * s = palloc(strlen($2)+2); char * s = palloc(strlen($2)+2);
s[0] = '-'; s[0] = '-';
strcpy(s + 1, $2); strcpy(s + 1, $2);
$$ = s; $$ = s;
} }
| name_list | name_list
{ {
List *n; List *n;
int slen = 0; int slen = 0;
char *result; char *result;
/* List of words? Then concatenate together */ /* List of words? Then concatenate together */
if ($1 == NIL) if ($1 == NIL)
elog(ERROR, "SET must have at least one argument"); elog(ERROR, "SET must have at least one argument");
foreach (n, $1) foreach (n, $1)
{ {
Value *p = (Value *) lfirst(n); Value *p = (Value *) lfirst(n);
Assert(IsA(p, String)); Assert(IsA(p, String));
/* keep track of room for string and trailing comma */ /* keep track of room for string and trailing comma */
slen += (strlen(p->val.str) + 1); slen += (strlen(p->val.str) + 1);
} }
result = palloc(slen + 1); result = palloc(slen + 1);
*result = '\0'; *result = '\0';
foreach (n, $1) foreach (n, $1)
{ {
Value *p = (Value *) lfirst(n); Value *p = (Value *) lfirst(n);
strcat(result, p->val.str); strcat(result, p->val.str);
strcat(result, ","); strcat(result, ",");
}
/* remove the trailing comma from the last element */
*(result+strlen(result)-1) = '\0';
$$ = result;
} }
/* remove the trailing comma from the last element */
*(result+strlen(result)-1) = '\0';
$$ = result;
}
| DEFAULT { $$ = NULL; } | DEFAULT { $$ = NULL; }
; ;
...@@ -2895,15 +2890,14 @@ LoadStmt: LOAD file_name ...@@ -2895,15 +2890,14 @@ LoadStmt: LOAD file_name
CreatedbStmt: CREATE DATABASE database_name WITH createdb_opt_location createdb_opt_encoding CreatedbStmt: CREATE DATABASE database_name WITH createdb_opt_location createdb_opt_encoding
{ {
CreatedbStmt *n; CreatedbStmt *n = makeNode(CreatedbStmt);
if ($5 == NULL && $6 == -1) if ($5 == NULL && $6 == -1)
elog(ERROR, "CREATE DATABASE WITH requires at least one option"); elog(ERROR, "CREATE DATABASE WITH requires at least one option");
n = makeNode(CreatedbStmt);
n->dbname = $3; n->dbname = $3;
n->dbpath = $5; n->dbpath = $5;
n->encoding = $6; n->encoding = ($6 == -1) ? GetTemplateEncoding() : $6;
$$ = (Node *)n; $$ = (Node *)n;
} }
| CREATE DATABASE database_name | CREATE DATABASE database_name
...@@ -2911,11 +2905,7 @@ CreatedbStmt: CREATE DATABASE database_name WITH createdb_opt_location createdb ...@@ -2911,11 +2905,7 @@ CreatedbStmt: CREATE DATABASE database_name WITH createdb_opt_location createdb
CreatedbStmt *n = makeNode(CreatedbStmt); CreatedbStmt *n = makeNode(CreatedbStmt);
n->dbname = $3; n->dbname = $3;
n->dbpath = NULL; n->dbpath = NULL;
#ifdef MULTIBYTE
n->encoding = GetTemplateEncoding(); n->encoding = GetTemplateEncoding();
#else
n->encoding = 0;
#endif
$$ = (Node *)n; $$ = (Node *)n;
} }
; ;
...@@ -2928,13 +2918,13 @@ createdb_opt_location: LOCATION '=' Sconst { $$ = $3; } ...@@ -2928,13 +2918,13 @@ createdb_opt_location: LOCATION '=' Sconst { $$ = $3; }
createdb_opt_encoding: ENCODING '=' Sconst createdb_opt_encoding: ENCODING '=' Sconst
{ {
#ifdef MULTIBYTE #ifdef MULTIBYTE
int i; $$ = pg_char_to_encoding($3);
i = pg_char_to_encoding($3); if ($$ == -1)
if (i == -1)
elog(ERROR, "%s is not a valid encoding name", $3); elog(ERROR, "%s is not a valid encoding name", $3);
$$ = i;
#else #else
elog(ERROR, "Multi-byte support is not enabled"); if (strcasecmp($3, GetTemplateEncodingName()) != 0)
elog(ERROR, "Multi-byte support is not enabled");
$$ = GetTemplateEncoding();
#endif #endif
} }
| ENCODING '=' Iconst | ENCODING '=' Iconst
...@@ -2942,26 +2932,19 @@ createdb_opt_encoding: ENCODING '=' Sconst ...@@ -2942,26 +2932,19 @@ createdb_opt_encoding: ENCODING '=' Sconst
#ifdef MULTIBYTE #ifdef MULTIBYTE
if (!pg_get_encent_by_encoding($3)) if (!pg_get_encent_by_encoding($3))
elog(ERROR, "%d is not a valid encoding code", $3); elog(ERROR, "%d is not a valid encoding code", $3);
$$ = $3;
#else #else
elog(ERROR, "Multi-byte support is not enabled"); if ($3 != GetTemplateEncoding())
elog(ERROR, "Multi-byte support is not enabled");
#endif #endif
$$ = $3;
} }
| ENCODING '=' DEFAULT | ENCODING '=' DEFAULT
{ {
#ifdef MULTIBYTE
$$ = GetTemplateEncoding(); $$ = GetTemplateEncoding();
#else
$$ = 0;
#endif
} }
| /*EMPTY*/ | /*EMPTY*/
{ {
#ifdef MULTIBYTE $$ = -1;
$$ = GetTemplateEncoding();
#else
$$= 0;
#endif
} }
; ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment