Commit 44611f6e authored by Tom Lane's avatar Tom Lane

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 knowledge
of server version.
parent d91acf84
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.156 2003/12/28 17:29:41 tgl Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.157 2004/03/05 01:53:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -609,12 +609,28 @@ pqSaveParameterStatus(PGconn *conn, const char *name, const char *value) ...@@ -609,12 +609,28 @@ pqSaveParameterStatus(PGconn *conn, const char *name, const char *value)
/* /*
* Special hacks: remember client_encoding as a numeric value, and * Special hacks: remember client_encoding as a numeric value, and
* remember at least the first few bytes of server version. * convert server version to a numeric form as well.
*/ */
if (strcmp(name, "client_encoding") == 0) if (strcmp(name, "client_encoding") == 0)
conn->client_encoding = pg_char_to_encoding(value); conn->client_encoding = pg_char_to_encoding(value);
if (strcmp(name, "server_version") == 0) else if (strcmp(name, "server_version") == 0)
StrNCpy(conn->sversion, value, sizeof(conn->sversion)); {
int cnt;
int vmaj,
vmin,
vrev;
cnt = sscanf(value, "%d.%d.%d", &vmaj, &vmin, &vrev);
if (cnt < 2)
conn->sversion = 0; /* unknown */
else
{
if (cnt == 2)
vrev = 0;
conn->sversion = (100 * vmaj + vmin) * 100 + vrev;
}
}
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.47 2004/01/26 22:35:32 tgl Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-lobj.c,v 1.48 2004/03/05 01:53:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -534,6 +534,7 @@ lo_initialize(PGconn *conn) ...@@ -534,6 +534,7 @@ lo_initialize(PGconn *conn)
PGresult *res; PGresult *res;
PGlobjfuncs *lobjfuncs; PGlobjfuncs *lobjfuncs;
int n; int n;
const char *query;
const char *fname; const char *fname;
Oid foid; Oid foid;
...@@ -550,17 +551,34 @@ lo_initialize(PGconn *conn) ...@@ -550,17 +551,34 @@ lo_initialize(PGconn *conn)
MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs)); MemSet((char *) lobjfuncs, 0, sizeof(PGlobjfuncs));
/* /*
* Execute the query to get all the functions at once * Execute the query to get all the functions at once. In 7.3 and later
* we need to be schema-safe.
*/ */
res = PQexec(conn, "select proname, oid from pg_proc \ if (conn->sversion >= 70300)
where proname = 'lo_open' \ query = "select proname, oid from pg_catalog.pg_proc "
or proname = 'lo_close' \ "where proname in ("
or proname = 'lo_creat' \ "'lo_open', "
or proname = 'lo_unlink' \ "'lo_close', "
or proname = 'lo_lseek' \ "'lo_creat', "
or proname = 'lo_tell' \ "'lo_unlink', "
or proname = 'loread' \ "'lo_lseek', "
or proname = 'lowrite'"); "'lo_tell', "
"'loread', "
"'lowrite') "
"and pronamespace = (select oid from pg_catalog.pg_namespace "
"where nspname = 'pg_catalog')";
else
query = "select proname, oid from pg_proc "
"where proname = 'lo_open' "
"or proname = 'lo_close' "
"or proname = 'lo_creat' "
"or proname = 'lo_unlink' "
"or proname = 'lo_lseek' "
"or proname = 'lo_tell' "
"or proname = 'loread' "
"or proname = 'lowrite'";
res = PQexec(conn, query);
if (res == NULL) if (res == NULL)
{ {
free(lobjfuncs); free(lobjfuncs);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.9 2003/11/29 19:52:12 pgsql Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.10 2004/03/05 01:53:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -178,7 +178,9 @@ pqSetenvPoll(PGconn *conn) ...@@ -178,7 +178,9 @@ pqSetenvPoll(PGconn *conn)
* default in a 7.3 server. * default in a 7.3 server.
* *
* Note: version() exists in all * Note: version() exists in all
* protocol-2.0-supporting backends. * protocol-2.0-supporting backends. In 7.3 it would
* be safer to write pg_catalog.version(), but we can't
* do that without causing problems on older versions.
*/ */
if (!PQsendQuery(conn, "begin; select version(); end")) if (!PQsendQuery(conn, "begin; select version(); end"))
goto error_return; goto error_return;
...@@ -258,8 +260,9 @@ pqSetenvPoll(PGconn *conn) ...@@ -258,8 +260,9 @@ pqSetenvPoll(PGconn *conn)
* in 7.3 servers where we need to prevent * in 7.3 servers where we need to prevent
* autocommit-off from starting a transaction anyway. * autocommit-off from starting a transaction anyway.
*/ */
if (strncmp(conn->sversion, "7.3", 3) == 0) if (conn->sversion >= 70300 &&
query = "begin; select pg_client_encoding(); end"; conn->sversion < 70400)
query = "begin; select pg_catalog.pg_client_encoding(); end";
else else
query = "select pg_client_encoding()"; query = "select pg_client_encoding()";
if (!PQsendQuery(conn, query)) if (!PQsendQuery(conn, query))
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.84 2004/01/09 02:02:43 momjian Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-int.h,v 1.85 2004/03/05 01:53:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -280,7 +280,7 @@ struct pg_conn ...@@ -280,7 +280,7 @@ struct pg_conn
SockAddr laddr; /* Local address */ SockAddr laddr; /* Local address */
SockAddr raddr; /* Remote address */ SockAddr raddr; /* Remote address */
ProtocolVersion pversion; /* FE/BE protocol version in use */ ProtocolVersion pversion; /* FE/BE protocol version in use */
char sversion[8]; /* The first few bytes of server version */ int sversion; /* server version, e.g. 70401 for 7.4.1 */
/* Transient state needed while establishing connection */ /* Transient state needed while establishing connection */
struct addrinfo *addrlist; /* list of possible backend addresses */ struct addrinfo *addrlist; /* list of possible backend addresses */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment