From c2d4526495a149d215a9c2a6e0f7c165e78e6b66 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 23 Sep 2008 10:58:03 +0000 Subject: Tighten the check in initdb and CREATE DATABASE that the chosen encoding matches the encoding of the locale. LC_COLLATE is now checked in addition to LC_CTYPE. --- src/backend/commands/dbcommands.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/backend/commands/dbcommands.c') diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index ce3754f5928..29dc0733a73 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.211 2008/09/23 09:20:35 heikki Exp $ + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.212 2008/09/23 10:58:03 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -118,6 +118,7 @@ createdb(const CreatedbStmt *stmt) int encoding = -1; int dbconnlimit = -1; int ctype_encoding; + int collate_encoding; int notherbackends; int npreparedxacts; createdb_failure_params fparms; @@ -334,6 +335,7 @@ createdb(const CreatedbStmt *stmt) * Note: if you change this policy, fix initdb to match. */ ctype_encoding = pg_get_encoding_from_locale(dbctype); + collate_encoding = pg_get_encoding_from_locale(dbcollate); if (!(ctype_encoding == encoding || ctype_encoding == PG_SQL_ASCII || @@ -345,9 +347,22 @@ createdb(const CreatedbStmt *stmt) (errmsg("encoding %s does not match locale %s", pg_encoding_to_char(encoding), dbctype), - errdetail("The chosen LC_CTYPE setting requires encoding %s.", + errdetail("The chosen CTYPE setting requires encoding %s.", pg_encoding_to_char(ctype_encoding)))); + if (!(collate_encoding == encoding || + collate_encoding == PG_SQL_ASCII || +#ifdef WIN32 + encoding == PG_UTF8 || +#endif + (encoding == PG_SQL_ASCII && superuser()))) + ereport(ERROR, + (errmsg("encoding %s does not match locale %s", + pg_encoding_to_char(encoding), + dbcollate), + errdetail("The chosen COLLATE setting requires encoding %s.", + pg_encoding_to_char(collate_encoding)))); + /* * Check that the new locale is compatible with the source database. * -- cgit v1.2.3