Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4e62e5

Browse files
committed
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 changethe client encoding on the fly without setting PGCLIENTENCODING.
1 parentb304b4a commitd4e62e5

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 44 additions & 2 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.116 2000/01/26 05:58:45 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.117 2000/02/05 12:33:22 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -41,6 +41,7 @@
4141
#endif
4242

4343
#ifdefMULTIBYTE
44+
#include"miscadmin.h"
4445
#include"mb/pg_wchar.h"
4546
#endif
4647

@@ -2381,13 +2382,54 @@ PQbackendPID(const PGconn *conn)
23812382
}
23822383

23832384
int
2384-
PQclientencoding(constPGconn*conn)
2385+
PQclientEncoding(constPGconn*conn)
23852386
{
23862387
if (!conn||conn->status!=CONNECTION_OK)
23872388
return-1;
23882389
returnconn->client_encoding;
23892390
}
23902391

2392+
#ifdefMULTIBYTE
2393+
int
2394+
PQsetClientEncoding(PGconn*conn,constchar*encoding)
2395+
{
2396+
charqbuf[128];
2397+
staticcharquery[]="set client_encoding to '%s'";
2398+
PGresult*res;
2399+
intstatus;
2400+
2401+
if (!conn||conn->status!=CONNECTION_OK)
2402+
return-1;
2403+
2404+
/* check query buffer overflow */
2405+
if (sizeof(qbuf)< (sizeof(query)+strlen(encoding)))
2406+
return-1;
2407+
2408+
/* ok, now send a query */
2409+
sprintf(qbuf,query,encoding);
2410+
res=PQexec(conn,qbuf);
2411+
2412+
if (res== (PGresult*)NULL)
2413+
return-1;
2414+
if (res->resultStatus!=PGRES_COMMAND_OK)
2415+
status=-1;
2416+
else
2417+
{
2418+
/* change libpq internal encoding */
2419+
conn->client_encoding=pg_char_to_encoding(encoding);
2420+
status=0;/* everything is ok */
2421+
}
2422+
PQclear(res);
2423+
return(status);
2424+
}
2425+
#else
2426+
int
2427+
PQsetClientEncoding(PGconn*conn,constchar*encoding)
2428+
{
2429+
return-1;
2430+
}
2431+
#endif
2432+
23912433
void
23922434
PQtrace(PGconn*conn,FILE*debug_port)
23932435
{

‎src/interfaces/libpq/fe-print.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* didn't really belong there.
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.33 2000/01/29 16:58:51 petere Exp $
13+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.34 2000/02/05 12:33:22 ishii Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -347,7 +347,7 @@ do_field(const PQprintOpt *po, const PGresult *res,
347347
charch='0';
348348

349349
#ifdefMULTIBYTE
350-
for (p=pval;*p;p+=PQmblen(p,PQclientencoding(res->conn)))
350+
for (p=pval;*p;p+=PQmblen(p,PQclientEncoding(res->conn)))
351351
#else
352352
for (p=pval;*p;p++)
353353
#endif

‎src/interfaces/libpq/libpq-fe.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: libpq-fe.h,v 1.58 2000/01/29 16:58:51 petere Exp $
10+
* $Id: libpq-fe.h,v 1.59 2000/02/05 12:33:22 ishii Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -218,7 +218,8 @@ extern"C"
218218
externconstchar*PQerrorMessage(constPGconn*conn);
219219
externintPQsocket(constPGconn*conn);
220220
externintPQbackendPID(constPGconn*conn);
221-
externintPQclientencoding(constPGconn*conn);
221+
externintPQclientEncoding(constPGconn*conn);
222+
externintPQsetClientEncoding(PGconn*conn,constchar*encoding);
222223

223224
/* Enable/disable tracing */
224225
externvoidPQtrace(PGconn*conn,FILE*debug_port);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp