*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.200 2007/10/12 18:55:12 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.201 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
else if (IsA(dencoding->arg, String))
{
encoding_name = strVal(dencoding->arg);
- if (pg_valid_server_encoding(encoding_name) < 0)
+ encoding = pg_valid_server_encoding(encoding_name);
+ if (encoding < 0)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("%s is not a valid encoding name",
encoding_name)));
- encoding = pg_char_to_encoding(encoding_name);
}
else
elog(ERROR, "unrecognized node type: %d",
* Portions Copyright (c) 1999-2007, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ascii.c,v 1.30 2007/01/05 22:19:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ascii.c,v 1.31 2007/10/13 20:18:41 tgl Exp $
*
*-----------------------------------------------------------------------
*/
to_ascii_encname(PG_FUNCTION_ARGS)
{
text *data = PG_GETARG_TEXT_P_COPY(0);
- int enc = pg_char_to_encoding(NameStr(*PG_GETARG_NAME(1)));
+ char *encname = NameStr(*PG_GETARG_NAME(1));
+ int enc = pg_char_to_encoding(encname);
+
+ if (enc < 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("%s is not a valid encoding name", encname)));
PG_RETURN_TEXT_P(encode_to_ascii(data, enc));
}
text *data = PG_GETARG_TEXT_P_COPY(0);
int enc = PG_GETARG_INT32(1);
+ if (!PG_VALID_ENCODING(enc))
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("%d is not a valid encoding code", enc)));
+
PG_RETURN_TEXT_P(encode_to_ascii(data, enc));
}
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.47 2007/09/23 21:36:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.48 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#define NAMESPACE_SQLXML "http://standards.iso.org/iso/9075/2003/sqlxml"
+#ifdef USE_LIBXML
+
+static int
+xmlChar_to_encoding(xmlChar *encoding_name)
+{
+ int encoding = pg_char_to_encoding((char *) encoding_name);
+
+ if (encoding < 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid encoding name \"%s\"",
+ (char *) encoding_name)));
+ return encoding;
+}
+
+#endif
+
+
Datum
xml_in(PG_FUNCTION_ARGS)
{
/* Now that we know what we're dealing with, convert to server encoding */
newstr = (char *) pg_do_encoding_conversion((unsigned char *) str,
nbytes,
- encoding ? pg_char_to_encoding((char *) encoding) : PG_UTF8,
+ encoding ?
+ xmlChar_to_encoding(encoding) :
+ PG_UTF8,
GetDatabaseEncoding());
if (newstr != str)
utf8string = pg_do_encoding_conversion(string,
len,
- encoding
- ? pg_char_to_encoding((char *) encoding)
- : GetDatabaseEncoding(),
+ encoding ?
+ xmlChar_to_encoding(encoding) :
+ GetDatabaseEncoding(),
PG_UTF8);
xml_init();
* Encoding names and routines for work with it. All
* in this file is shared bedween FE and BE.
*
- * $PostgreSQL: pgsql/src/backend/utils/mb/encnames.c,v 1.34 2007/04/16 18:50:49 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/encnames.c,v 1.35 2007/10/13 20:18:41 tgl Exp $
*/
#ifdef FRONTEND
#include "postgres_fe.h"
#include "utils/builtins.h"
#endif
+#include <ctype.h>
#include <unistd.h>
#include "mb/pg_wchar.h"
-#include <ctype.h>
+
/* ----------
* All encoding names, sorted: *** A L P H A B E T I C ***
"EUC_TW", PG_EUC_TW
},
{
+ "EUC_JIS_2004", PG_EUC_JIS_2004
+ },
+ {
"UTF8", PG_UTF8
},
{
"WIN1257", PG_WIN1257
},
{
- "EUC_JIS_2004", PG_EUC_JIS_2004
- },
- {
"SJIS", PG_SJIS
},
{
"UHC", PG_UHC
},
{
- "JOHAB", PG_JOHAB
+ "GB18030", PG_GB18030
},
{
- "GB18030", PG_GB18030
+ "JOHAB", PG_JOHAB
},
{
"SHIFT_JIS_2004", PG_SHIFT_JIS_2004
return enc;
}
+int
+pg_valid_server_encoding_id(int encoding)
+{
+ return PG_VALID_BE_ENCODING(encoding);
+}
+
/* ----------
* Remove irrelevant chars from encoding name
* ----------
* Returns encoding or -1 for error
*/
int
-pg_char_to_encoding(const char *s)
+pg_char_to_encoding(const char *name)
{
- pg_encname *p = NULL;
+ pg_encname *p;
- if (!s)
+ if (!name)
return -1;
- p = pg_char_to_encname_struct(s);
+ p = pg_char_to_encname_struct(name);
return p ? p->encoding : -1;
}
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
*
- * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.66 2007/09/24 16:38:24 adunstan Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.67 2007/10/13 20:18:41 tgl Exp $
*/
#include "postgres.h"
int len = VARSIZE(string) - VARHDRSZ;
int retval;
+ if (src_encoding < 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("invalid encoding name \"%s\"",
+ src_encoding_name)));
+
retval = pg_verify_mbstr_len(src_encoding, VARDATA(string), len, false);
PG_RETURN_INT32(retval);
# Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
-# $PostgreSQL: pgsql/src/bin/initdb/Makefile,v 1.53 2007/09/27 19:53:43 tgl Exp $
+# $PostgreSQL: pgsql/src/bin/initdb/Makefile,v 1.54 2007/10/13 20:18:41 tgl Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
-override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
+override CPPFLAGS := -DFRONTEND -I$(libpq_srcdir) $(CPPFLAGS)
-OBJS= initdb.o $(WIN32RES)
+OBJS= initdb.o encnames.o pqsignal.o $(WIN32RES)
-all: submake-libpq submake-libpgport initdb
+all: submake-libpgport initdb
-initdb: $(OBJS) $(libpq_builddir)/libpq.a
- $(CC) $(CFLAGS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
+initdb: $(OBJS)
+ $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LIBS) -o $@$(X)
+
+# We used to pull in all of libpq to get encnames and pqsignal, but that
+# exposes us to risks of version skew if we link to a shared library.
+# Do it the hard way, instead, so that we're statically linked.
+
+encnames.c: % : $(top_srcdir)/src/backend/utils/mb/%
+ rm -f $@ && $(LN_S) $< .
+
+pqsignal.c: % : $(libpq_srcdir)/%
+ rm -f $@ && $(LN_S) $< .
install: all installdirs
$(INSTALL_PROGRAM) initdb$(X) '$(DESTDIR)$(bindir)/initdb$(X)'
rm -f '$(DESTDIR)$(bindir)/initdb$(X)'
clean distclean maintainer-clean:
- rm -f initdb$(X) $(OBJS)
+ rm -f initdb$(X) $(OBJS) encnames.c pqsignal.c
# ensure that changes in datadir propagate into object file
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.144 2007/09/29 00:14:40 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.145 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
progname);
exit(1);
}
- else if (!PG_VALID_BE_ENCODING(ctype_enc))
+ else if (!pg_valid_server_encoding_id(ctype_enc))
{
/* We recognized it, but it's not a legal server encoding */
fprintf(stderr,
{
char *linkloc;
- linkloc = (char *) palloc(strlen(pg_data) + 8 + 2);
+ linkloc = (char *) pg_malloc(strlen(pg_data) + 8 + 2);
sprintf(linkloc, "%s/pg_xlog", pg_data);
/* check if the specified xlog directory is empty */
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.146 2007/08/21 01:11:20 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.147 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#endif
#include "libpq/libpq-fs.h"
-#include "mb/pg_wchar.h"
const char *progname;
AH->vrev = K_VERS_REV;
/* initialize for backwards compatible string processing */
- AH->public.encoding = PG_SQL_ASCII;
+ AH->public.encoding = 0; /* PG_SQL_ASCII */
AH->public.std_strings = false;
/* sql error handling */
* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.472 2007/09/03 00:39:19 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.473 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "catalog/pg_type.h"
#include "commands/sequence.h"
#include "libpq/libpq-fs.h"
-#include "mb/pg_wchar.h"
#include "pg_backup_archiver.h"
#include "dumputils.h"
* Portions Copyright (c) 1994, Regents of the University of California
*
*
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.92 2007/07/08 19:07:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.93 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#endif
#include "dumputils.h"
-#include "mb/pg_wchar.h"
/* version string we expect back from pg_dump */
*
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.181 2007/08/21 01:11:22 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.182 2007/10/13 20:18:41 tgl Exp $
*/
#include "postgres_fe.h"
#include "command.h"
#include "psqlscan.h"
#include "settings.h"
#include "variables.h"
-#include "mb/pg_wchar.h"
/* functions for use in this file */
}
if (pset.dirname)
- pfree(pset.dirname);
+ free(pset.dirname);
pset.dirname = pg_strdup(dir);
canonicalize_path(pset.dirname);
*
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.135 2007/06/22 01:09:28 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.136 2007/10/13 20:18:41 tgl Exp $
*/
#include "postgres_fe.h"
#include "common.h"
#include "settings.h"
#include "command.h"
#include "copy.h"
-#include "mb/pg_wchar.h"
#include "mbprint.h"
*
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.25 2007/01/05 22:19:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.26 2007/10/13 20:18:41 tgl Exp $
+ *
+ * XXX this file does not really belong in psql/. Perhaps move to libpq?
+ * It also seems that the mbvalidate function is redundant with existing
+ * functionality.
*/
#include "postgres_fe.h"
+#include "mbprint.h"
+#include "libpq-fe.h"
#ifndef PGSCRIPTS
#include "settings.h"
#endif
-#include "mbprint.h"
-#include "mb/pg_wchar.h"
+
+/*
+ * To avoid version-skew problems, this file must not use declarations
+ * from pg_wchar.h: the encoding IDs we are dealing with are determined
+ * by the libpq.so we are linked with, and that might not match the
+ * numbers we see at compile time. (If this file were inside libpq,
+ * the problem would go away...)
+ *
+ * Hence, we have our own definition of pg_wchar, and we get the values
+ * of any needed encoding IDs on-the-fly.
+ */
+
+typedef unsigned int pg_wchar;
+
+static int
+get_utf8_id(void)
+{
+ static int utf8_id = -1;
+
+ if (utf8_id < 0)
+ utf8_id = pg_char_to_encoding("utf8");
+ return utf8_id;
+}
+
+#define PG_UTF8 get_utf8_id()
+
static pg_wchar
utf2ucs(const unsigned char *c)
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.21 2007/01/05 22:19:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.22 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include <ctype.h>
-#include "mb/pg_wchar.h"
-
#include "common.h"
#include "settings.h"
#include "variables.h"
/* Do we need to hack the character set encoding? */
state->encoding = pset.encoding;
- state->safe_encoding = PG_VALID_BE_ENCODING(state->encoding);
+ state->safe_encoding = pg_valid_server_encoding_id(state->encoding);
/* needed for prepare_buffer */
cur_state = state;
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.23 2007/06/04 10:02:40 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/createdb.c,v 1.24 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
-
#include "postgres_fe.h"
+
#include "common.h"
#include "dumputils.h"
-#include "mb/pg_wchar.h"
-
static void help(const char *progname);
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.430 2007/09/30 19:54:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.431 2007/10/13 20:18:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200709301
+#define CATALOG_VERSION_NO 200710131
#endif
-/* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.73 2007/09/18 17:41:17 adunstan Exp $ */
-
+/*-------------------------------------------------------------------------
+ *
+ * pg_wchar.h
+ * multibyte-character support
+ *
+ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.74 2007/10/13 20:18:41 tgl Exp $
+ *
+ * NOTES
+ * This is used both by the backend and by libpq, but should not be
+ * included by libpq client programs. In particular, a libpq client
+ * should not assume that the encoding IDs used by the version of libpq
+ * it's linked to match up with the IDs declared here.
+ *
+ *-------------------------------------------------------------------------
+ */
#ifndef PG_WCHAR_H
#define PG_WCHAR_H
#include <sys/types.h>
-#ifdef FRONTEND
-#undef palloc
-#define palloc malloc
-#undef pfree
-#define pfree free
-#endif
-
/*
- * The pg_wchar
+ * The pg_wchar type
*/
typedef unsigned int pg_wchar;
* If you add some encoding don't forget to check
* PG_ENCODING_BE_LAST macro.
*
- * The PG_SQL_ASCII is default encoding and must be = 0.
+ * PG_SQL_ASCII is default encoding and must be = 0.
+ *
+ * XXX We must avoid renumbering any backend encoding until libpq's major
+ * version number is increased beyond 5; it turns out that the backend
+ * encoding IDs are effectively part of libpq's ABI as far as 8.2 initdb and
+ * psql are concerned.
*/
typedef enum pg_enc
{
PG_EUC_CN, /* EUC for Chinese */
PG_EUC_KR, /* EUC for Korean */
PG_EUC_TW, /* EUC for Taiwan */
+ PG_EUC_JIS_2004, /* EUC-JIS-2004 */
PG_UTF8, /* Unicode UTF8 */
PG_MULE_INTERNAL, /* Mule internal code */
PG_LATIN1, /* ISO-8859-1 Latin 1 */
PG_WIN1254, /* windows-1254 */
PG_WIN1255, /* windows-1255 */
PG_WIN1257, /* windows-1257 */
- PG_EUC_JIS_2004, /* EUC-JIS-2004 */
/* PG_ENCODING_BE_LAST points to the above entry */
/* followings are for client encoding only */
PG_BIG5, /* Big5 (Windows-950) */
PG_GBK, /* GBK (Windows-936) */
PG_UHC, /* UHC (Windows-949) */
- PG_JOHAB, /* EUC for Korean JOHAB */
PG_GB18030, /* GB18030 */
+ PG_JOHAB, /* EUC for Korean JOHAB */
PG_SHIFT_JIS_2004, /* Shift-JIS-2004 */
_PG_LAST_ENCODING_ /* mark only */
} pg_enc;
-#define PG_ENCODING_BE_LAST PG_EUC_JIS_2004
+#define PG_ENCODING_BE_LAST PG_WIN1257
/*
* Please use these tests before access to pg_encconv_tbl[]
extern pg_enc2name pg_enc2name_tbl[];
-extern pg_encname *pg_char_to_encname_struct(const char *name);
-
-extern int pg_char_to_encoding(const char *s);
-extern const char *pg_encoding_to_char(int encoding);
-
/*
* pg_wchar stuff
*/
uint32 utf2; /* UTF-8 code 2 */
} pg_local_to_utf_combined;
+
+/*
+ * These functions are considered part of libpq's exported API and
+ * are also declared in libpq-fe.h.
+ */
+extern int pg_char_to_encoding(const char *name);
+extern const char *pg_encoding_to_char(int encoding);
+extern int pg_valid_server_encoding_id(int encoding);
+
+/*
+ * Remaining functions are not considered part of libpq's API, though many
+ * of them do exist inside libpq.
+ */
+extern pg_encname *pg_char_to_encname_struct(const char *name);
+
extern int pg_mb2wchar(const char *from, pg_wchar *to);
extern int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len);
extern int pg_encoding_mb2wchar_with_len(int encoding,
-# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.16 2007/07/08 17:11:51 joe Exp $
+# $PostgreSQL: pgsql/src/interfaces/libpq/exports.txt,v 1.17 2007/10/13 20:18:41 tgl Exp $
# Functions to be exported by libpq DLLs
PQconnectdb 1
PQsetdbLogin 2
PQsendDescribePortal 136
lo_truncate 137
PQconnectionUsedPassword 138
+pg_valid_server_encoding_id 139
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.192 2007/01/05 22:20:01 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.193 2007/10/13 20:18:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* standard_conforming_strings, and convert server version to a numeric
* form. We keep the first two of these in static variables as well, so
* that PQescapeString and PQescapeBytea can behave somewhat sanely (at
- * least in single- connection-using programs).
+ * least in single-connection-using programs).
*/
if (strcmp(name, "client_encoding") == 0)
{
conn->client_encoding = pg_char_to_encoding(value);
+ /* if we don't recognize the encoding name, fall back to SQL_ASCII */
+ if (conn->client_encoding < 0)
+ conn->client_encoding = PG_SQL_ASCII;
static_client_encoding = conn->client_encoding;
}
else if (strcmp(name, "standard_conforming_strings") == 0)
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.131 2007/01/05 22:20:01 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.132 2007/10/13 20:18:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
str = getenv("PGCLIENTENCODING");
if (str && *str != '\0')
+ {
encoding = pg_char_to_encoding(str);
+ if (encoding < 0)
+ encoding = PG_SQL_ASCII;
+ }
return encoding;
}
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.138 2007/07/08 18:28:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.139 2007/10/13 20:18:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern char *PQencryptPassword(const char *passwd, const char *user);
+/* === in encnames.c === */
+
+extern int pg_char_to_encoding(const char *name);
+extern const char *pg_encoding_to_char(int encoding);
+extern int pg_valid_server_encoding_id(int encoding);
+
#ifdef __cplusplus
}
#endif