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

Commit44611f6

Browse files
committed
libpq's query to get the OIDs of large-object support functions was not
schema-safe. Make it so, and improve the internal support for knowledgeof server version.
1 parentd91acf8 commit44611f6

File tree

4 files changed

+58
-21
lines changed

4 files changed

+58
-21
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.156 2003/12/28 17:29:41 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.157 2004/03/05 01:53:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -609,12 +609,28 @@ pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
609609

610610
/*
611611
* Special hacks: remember client_encoding as a numeric value, and
612-
*remember at least the first few bytes of server version.
612+
*convert server version to a numeric form as well.
613613
*/
614614
if (strcmp(name,"client_encoding")==0)
615615
conn->client_encoding=pg_char_to_encoding(value);
616-
if (strcmp(name,"server_version")==0)
617-
StrNCpy(conn->sversion,value,sizeof(conn->sversion));
616+
elseif (strcmp(name,"server_version")==0)
617+
{
618+
intcnt;
619+
intvmaj,
620+
vmin,
621+
vrev;
622+
623+
cnt=sscanf(value,"%d.%d.%d",&vmaj,&vmin,&vrev);
624+
625+
if (cnt<2)
626+
conn->sversion=0;/* unknown */
627+
else
628+
{
629+
if (cnt==2)
630+
vrev=0;
631+
conn->sversion= (100*vmaj+vmin)*100+vrev;
632+
}
633+
}
618634
}
619635

620636

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.47 2004/01/26 22:35:32 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.48 2004/03/05 01:53:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -534,6 +534,7 @@ lo_initialize(PGconn *conn)
534534
PGresult*res;
535535
PGlobjfuncs*lobjfuncs;
536536
intn;
537+
constchar*query;
537538
constchar*fname;
538539
Oidfoid;
539540

@@ -550,17 +551,34 @@ lo_initialize(PGconn *conn)
550551
MemSet((char*)lobjfuncs,0,sizeof(PGlobjfuncs));
551552

552553
/*
553-
* Execute the query to get all the functions at once
554+
* Execute the query to get all the functions at once. In 7.3 and later
555+
* we need to be schema-safe.
554556
*/
555-
res=PQexec(conn,"select proname, oid from pg_proc\
556-
where proname = 'lo_open'\
557-
or proname = 'lo_close'\
558-
or proname = 'lo_creat'\
559-
or proname = 'lo_unlink'\
560-
or proname = 'lo_lseek'\
561-
or proname = 'lo_tell'\
562-
or proname = 'loread'\
563-
or proname = 'lowrite'");
557+
if (conn->sversion >=70300)
558+
query="select proname, oid from pg_catalog.pg_proc "
559+
"where proname in ("
560+
"'lo_open', "
561+
"'lo_close', "
562+
"'lo_creat', "
563+
"'lo_unlink', "
564+
"'lo_lseek', "
565+
"'lo_tell', "
566+
"'loread', "
567+
"'lowrite') "
568+
"and pronamespace = (select oid from pg_catalog.pg_namespace "
569+
"where nspname = 'pg_catalog')";
570+
else
571+
query="select proname, oid from pg_proc "
572+
"where proname = 'lo_open' "
573+
"or proname = 'lo_close' "
574+
"or proname = 'lo_creat' "
575+
"or proname = 'lo_unlink' "
576+
"or proname = 'lo_lseek' "
577+
"or proname = 'lo_tell' "
578+
"or proname = 'loread' "
579+
"or proname = 'lowrite'";
580+
581+
res=PQexec(conn,query);
564582
if (res==NULL)
565583
{
566584
free(lobjfuncs);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.9 2003/11/29 19:52:12 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.10 2004/03/05 01:53:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -178,7 +178,9 @@ pqSetenvPoll(PGconn *conn)
178178
* default in a 7.3 server.
179179
*
180180
* Note: version() exists in all
181-
* protocol-2.0-supporting backends.
181+
* protocol-2.0-supporting backends. In 7.3 it would
182+
* be safer to write pg_catalog.version(), but we can't
183+
* do that without causing problems on older versions.
182184
*/
183185
if (!PQsendQuery(conn,"begin; select version(); end"))
184186
gotoerror_return;
@@ -258,8 +260,9 @@ pqSetenvPoll(PGconn *conn)
258260
* in 7.3 servers where we need to prevent
259261
* autocommit-off from starting a transaction anyway.
260262
*/
261-
if (strncmp(conn->sversion,"7.3",3)==0)
262-
query="begin; select pg_client_encoding(); end";
263+
if (conn->sversion >=70300&&
264+
conn->sversion<70400)
265+
query="begin; select pg_catalog.pg_client_encoding(); end";
263266
else
264267
query="select pg_client_encoding()";
265268
if (!PQsendQuery(conn,query))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.84 2004/01/09 02:02:43 momjian Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.85 2004/03/05 01:53:59 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -280,7 +280,7 @@ struct pg_conn
280280
SockAddrladdr;/* Local address */
281281
SockAddrraddr;/* Remote address */
282282
ProtocolVersionpversion;/* FE/BE protocol version in use */
283-
charsversion[8];/*The first few bytes of server version */
283+
intsversion;/*server version, e.g. 70401 for 7.4.1 */
284284

285285
/* Transient state needed while establishing connection */
286286
structaddrinfo*addrlist;/* list of possible backend addresses */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp