*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.116 2000/01/26 05:58:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.117 2000/02/05 12:33:22 ishii Exp $
*
*-------------------------------------------------------------------------
*/
#endif
#ifdef MULTIBYTE
+#include "miscadmin.h"
#include "mb/pg_wchar.h"
#endif
}
int
-PQclientencoding(const PGconn *conn)
+PQclientEncoding(const PGconn *conn)
{
if (!conn || conn->status != CONNECTION_OK)
return -1;
return conn->client_encoding;
}
+#ifdef MULTIBYTE
+int
+PQsetClientEncoding(PGconn *conn, const char *encoding)
+{
+ char qbuf[128];
+ static char query[] = "set client_encoding to '%s'";
+ PGresult *res;
+ int status;
+
+ if (!conn || conn->status != CONNECTION_OK)
+ return -1;
+
+ /* check query buffer overflow */
+ if (sizeof(qbuf) < (sizeof(query) + strlen(encoding)))
+ return -1;
+
+ /* ok, now send a query */
+ sprintf(qbuf, query, encoding);
+ res = PQexec(conn, qbuf);
+
+ if (res == (PGresult *)NULL)
+ return -1;
+ if (res->resultStatus != PGRES_COMMAND_OK)
+ status = -1;
+ else
+ {
+ /* change libpq internal encoding */
+ conn->client_encoding = pg_char_to_encoding(encoding);
+ status = 0; /* everything is ok */
+ }
+ PQclear(res);
+ return(status);
+}
+#else
+int
+PQsetClientEncoding(PGconn *conn, const char *encoding)
+{
+ return -1;
+}
+#endif
+
void
PQtrace(PGconn *conn, FILE *debug_port)
{
* didn't really belong there.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.33 2000/01/29 16:58:51 petere Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.34 2000/02/05 12:33:22 ishii Exp $
*
*-------------------------------------------------------------------------
*/
char ch = '0';
#ifdef MULTIBYTE
- for (p = pval; *p; p += PQmblen(p, PQclientencoding(res->conn)))
+ for (p = pval; *p; p += PQmblen(p, PQclientEncoding(res->conn)))
#else
for (p = pval; *p; p++)
#endif
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-fe.h,v 1.58 2000/01/29 16:58:51 petere Exp $
+ * $Id: libpq-fe.h,v 1.59 2000/02/05 12:33:22 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);
+ extern int PQclientEncoding(const PGconn *conn);
+ extern int PQsetClientEncoding(PGconn *conn, const char *encoding);
/* Enable/disable tracing */
extern void PQtrace(PGconn *conn, FILE *debug_port);