mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Change function name PQclientencoding to PQclientEncoding since
it seems more suitable for the naming convention in libpq. New function PQsetClientEncoding added. It makes possible to change the client encoding on the fly without setting PGCLIENTENCODING.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* 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 $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -41,6 +41,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef MULTIBYTE
|
||||
#include "miscadmin.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
#endif
|
||||
|
||||
@ -2381,13 +2382,54 @@ PQbackendPID(const PGconn *conn)
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user