*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.119 2000/02/15 20:49:28 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.120 2000/02/19 05:04:54 ishii Exp $
*
*-------------------------------------------------------------------------
*/
case SETENV_STATE_ENCODINGS_WAIT:
{
- const char *encoding = 0;
-
if (PQisBusy(handle->conn))
return PGRES_POLLING_READING;
if (handle->res)
{
+ char *encoding;
+
if (PQresultStatus(handle->res) != PGRES_TUPLES_OK)
{
PQclear(handle->res);
encoding = PQgetvalue(handle->res, 0, 0);
if (!encoding) /* this should not happen */
- encoding = SQL_ASCII;
-
- if (encoding)
- {
+ conn->client_encoding = SQL_ASCII;
+ else
/* set client encoding to pg_conn struct */
- conn->client_encoding = atoi(encoding);
- }
+ conn->client_encoding = pg_char_to_encoding(encoding);
PQclear(handle->res);
/* We have to keep going in order to clear up the query */
goto keep_going;
if (!conn || conn->status != CONNECTION_OK)
return -1;
+ if (!encoding)
+ return -1;
+
/* check query buffer overflow */
if (sizeof(qbuf) < (sizeof(query) + strlen(encoding)))
return -1;