*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.109 2000/01/14 05:33:15 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.110 2000/01/15 05:37:21 ishii Exp $
*
*-------------------------------------------------------------------------
*/
these queries. */
conn->status = CONNECTION_OK;
- switch (PQsetenvPoll(conn->setenv_handle))
+ switch (PQsetenvPoll(conn))
{
case PGRES_POLLING_OK: /* Success */
conn->status = CONNECTION_OK;
* ----------------
*/
PostgresPollingStatusType
-PQsetenvPoll(PGsetenvHandle handle)
+PQsetenvPoll(PGconn *conn)
{
+ PGsetenvHandle handle = conn->setenv_handle;
#ifdef MULTIBYTE
static const char envname[] = "PGCLIENTENCODING";
#endif
encoding = PQgetvalue(handle->res, 0, 0);
if (!encoding) /* this should not happen */
- encoding = pg_encoding_to_char(MULTIBYTE);
+ encoding = SQL_ASCII;
if (encoding)
{
- /* set client encoding via environment variable */
- char *envbuf;
-
- envbuf = (char *) malloc(strlen(envname) + strlen(encoding) + 2);
- sprintf(envbuf, "%s=%s", envname, encoding);
- putenv(envbuf);
+ /* set client encoding to pg_conn struct */
+ conn->client_encoding = atoi(encoding);
}
PQclear(handle->res);
/* We have to keep going in order to clear up the query */
return 0;
for (;;) {
- flag = PQsetenvPoll(handle);
+ flag = PQsetenvPoll(conn);
switch (flag)
{
case PGRES_POLLING_ACTIVE:
return conn->be_pid;
}
+int
+PQclientencoding(const PGconn *conn)
+{
+ if (!conn || conn->status != CONNECTION_OK)
+ return -1;
+ return conn->client_encoding;
+}
+
void
PQtrace(PGconn *conn, FILE *debug_port)
{
* didn't really belong there.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.28 1999/11/11 00:10:14 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.29 2000/01/15 05:37:21 ishii Exp $
*
*-------------------------------------------------------------------------
*/
* the backend is assumed.
*/
int
-PQmblen(const unsigned char *s)
+PQmblen(const unsigned char *s, int encoding)
+{
+ return (pg_encoding_mblen(encoding, s));
+}
+
+/*
+ * Get encoding id from environment variable PGCLIENTENCODING.
+ */
+int
+PQenv2encoding(void)
{
char *str;
- int encoding = -1;
+ int encoding = SQL_ASCII;
str = getenv("PGCLIENTENCODING");
if (str && *str != '\0')
encoding = pg_char_to_encoding(str);
- if (encoding < 0)
- encoding = MULTIBYTE;
- return (pg_encoding_mblen(encoding, s));
+ return(encoding);
}
#else
/* Provide a default definition in case someone calls it anyway */
int
-PQmblen(const unsigned char *s)
+PQmblen(const unsigned char *s, int encoding)
{
return 1;
}
+int
+PQenv2encoding(void)
+{
+ return 0;
+}
#endif /* MULTIBYTE */
char ch = '0';
#ifdef MULTIBYTE
- for (p = pval; *p; p += PQmblen(p))
+ for (p = pval; *p; p += PQmblen(p, PQclientencoding(res->conn)))
#else
for (p = pval; *p; p++)
#endif
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-fe.h,v 1.54 2000/01/14 05:33:15 tgl Exp $
+ * $Id: libpq-fe.h,v 1.55 2000/01/15 05:37:21 ishii Exp $
*
*-------------------------------------------------------------------------
*/
extern const char *PQerrorMessage(const PGconn *conn);
extern int PQsocket(const PGconn *conn);
extern int PQbackendPID(const PGconn *conn);
+ extern int PQclientencoding(const PGconn *conn);
/* Enable/disable tracing */
extern void PQtrace(PGconn *conn, FILE *debug_port);
/* Passing of environment variables */
/* Asynchronous (non-blocking) */
extern PGsetenvHandle PQsetenvStart(PGconn *conn);
- extern PostgresPollingStatusType PQsetenvPoll(PGsetenvHandle handle);
+ extern PostgresPollingStatusType PQsetenvPoll(PGconn *conn);
extern void PQsetenvAbort(PGsetenvHandle handle);
/* Synchronous (blocking) */
* 0, use variable width */
/* Determine length of multibyte encoded char at *s */
- extern int PQmblen(const unsigned char *s);
+ extern int PQmblen(const unsigned char *s, int encoding);
+
+ /* Get encoding id from environment variable PGCLIENTENCODING */
+ int PQenv2encoding(void);
/* === in fe-lobj.c === */
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-int.h,v 1.15 2000/01/14 05:33:15 tgl Exp $
+ * $Id: libpq-int.h,v 1.16 2000/01/15 05:37:21 ishii Exp $
*
*-------------------------------------------------------------------------
*/
/* Buffer for receiving various parts of messages */
PQExpBufferData workBuffer; /* expansible string */
+
+ int client_encoding; /* encoding id */
};
/* ----------------