Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4fec86f

Browse files
committed
Fix nasty bug in setting client_encoding
1 parent eb089e7 commit 4fec86f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.119 2000/02/15 20:49:28 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.120 2000/02/19 05:04:54 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1461,15 +1461,15 @@ PQsetenvPoll(PGconn *conn)
14611461

14621462
case SETENV_STATE_ENCODINGS_WAIT:
14631463
{
1464-
const char *encoding = 0;
1465-
14661464
if (PQisBusy(handle->conn))
14671465
return PGRES_POLLING_READING;
14681466

14691467
handle->res = PQgetResult(handle->conn);
14701468

14711469
if (handle->res)
14721470
{
1471+
char *encoding;
1472+
14731473
if (PQresultStatus(handle->res) != PGRES_TUPLES_OK)
14741474
{
14751475
PQclear(handle->res);
@@ -1478,13 +1478,10 @@ PQsetenvPoll(PGconn *conn)
14781478

14791479
encoding = PQgetvalue(handle->res, 0, 0);
14801480
if (!encoding) /* this should not happen */
1481-
encoding = SQL_ASCII;
1482-
1483-
if (encoding)
1484-
{
1481+
conn->client_encoding = SQL_ASCII;
1482+
else
14851483
/* set client encoding to pg_conn struct */
1486-
conn->client_encoding = atoi(encoding);
1487-
}
1484+
conn->client_encoding = pg_char_to_encoding(encoding);
14881485
PQclear(handle->res);
14891486
/* We have to keep going in order to clear up the query */
14901487
goto keep_going;
@@ -2395,6 +2392,9 @@ PQsetClientEncoding(PGconn *conn, const char *encoding)
23952392
if (!conn || conn->status != CONNECTION_OK)
23962393
return -1;
23972394

2395+
if (!encoding)
2396+
return -1;
2397+
23982398
/* check query buffer overflow */
23992399
if (sizeof(qbuf) < (sizeof(query) + strlen(encoding)))
24002400
return -1;

0 commit comments

Comments
 (0)