aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/dbcommands.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-11-02 18:41:22 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-11-02 18:41:22 +0000
commit5123139210a6767e99f3e420038d64926beb7d78 (patch)
treee4eadcde9f1d7d76c9f9de43f3ef39e99101f7a1 /src/backend/commands/dbcommands.c
parentf6e0130b5bee398b68ed64144cd0a467e8b8713a (diff)
downloadpostgresql-5123139210a6767e99f3e420038d64926beb7d78.tar.gz
postgresql-5123139210a6767e99f3e420038d64926beb7d78.zip
Remove encoding lookups from grammar stage, push them back to places
where it's safe to do database access. Along the way, fix core dump for 'DEFAULT' parameters to CREATE DATABASE. initdb forced due to change in pg_proc entry.
Diffstat (limited to 'src/backend/commands/dbcommands.c')
-rw-r--r--src/backend/commands/dbcommands.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 327aac29593..291770f98cc 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.106 2002/10/21 22:06:19 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.107 2002/11/02 18:41:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -122,14 +122,34 @@ createdb(const CreatedbStmt *stmt)
defel->defname);
}
- if (downer)
+ if (downer && downer->arg)
dbowner = strVal(downer->arg);
- if (dpath)
+ if (dpath && dpath->arg)
dbpath = strVal(dpath->arg);
- if (dtemplate)
+ if (dtemplate && dtemplate->arg)
dbtemplate = strVal(dtemplate->arg);
- if (dencoding)
- encoding = intVal(dencoding->arg);
+ if (dencoding && dencoding->arg)
+ {
+ const char *encoding_name;
+
+ if (IsA(dencoding->arg, Integer))
+ {
+ encoding = intVal(dencoding->arg);
+ encoding_name = pg_encoding_to_char(encoding);
+ if (strcmp(encoding_name, "") == 0 ||
+ pg_valid_server_encoding(encoding_name) < 0)
+ elog(ERROR, "%d is not a valid encoding code", encoding);
+ }
+ else if (IsA(dencoding->arg, String))
+ {
+ encoding_name = strVal(dencoding->arg);
+ if (pg_valid_server_encoding(encoding_name) < 0)
+ elog(ERROR, "%s is not a valid encoding name", encoding_name);
+ encoding = pg_char_to_encoding(encoding_name);
+ }
+ else
+ elog(ERROR, "CREATE DATABASE: bogus encoding parameter");
+ }
/* obtain sysid of proposed owner */
if (dbowner)