Skip to content

Commit 86dacdb

Browse files
committed
libpq++ uses fe_setauthsvc which is deprecated and results in an error
on connection. This patch changes it to use PQconnectdb rather than {fe_setauthsvc,PQsetdb}. This still isn't the complete solution, as there is no provision for user,password in class PgEnv, but it does get rid of the error message. Tested with gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release) under NetBSD-1.3K/i386. Cheers, Patrick Welche
1 parent d6e33c8 commit 86dacdb

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ char *PQoptions(PGconn *conn)
316316
Returns the status of the connection.
317317
The status can be CONNECTION_OK or CONNECTION_BAD.
318318
<synopsis>
319-
ConnStatusType *PQstatus(PGconn *conn)
319+
ConnStatusType PQstatus(PGconn *conn)
320320
</synopsis>
321321
</Para>
322322

src/interfaces/libpq++/pgconnection.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
* Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.2 1997/02/13 10:00:27 scrappy Exp $
13+
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.3 1999/05/10 15:27:18 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
1717

1818
#include <stdlib.h>
1919
#include <string.h>
20+
#include <strstream>
2021
#include "pgconnection.h"
2122

2223
extern "C" {
@@ -88,21 +89,18 @@ ConnStatusType PgConnection::Connect(const char* dbName)
8889
PQtrace(pgConn, debug);
8990
#endif
9091

91-
// Set Host Authentication service
92-
char errorMessage[ERROR_MSG_LENGTH];
93-
memset(errorMessage, 0, sizeof(errorMessage));
94-
fe_setauthsvc(pgEnv.Auth(), errorMessage);
95-
9692
// Connect to the database
97-
pgConn = PQsetdb(pgEnv.Host(), pgEnv.Port(), pgEnv.Option(), pgEnv.TTY(), dbName);
93+
ostrstream conninfo;
94+
conninfo << "dbname="<<dbName;
95+
conninfo << pgEnv;
96+
pgConn=PQconnectdb(conninfo.str());
97+
conninfo.freeze(0);
9898

99-
// Return the connection status
100-
if (errorMessage) {
101-
SetErrorMessage( errorMessage );
102-
return CONNECTION_BAD;
99+
if(ConnectionBad()) {
100+
SetErrorMessage( PQerrorMessage(pgConn) );
103101
}
104-
else
105-
return Status();
102+
103+
return Status();
106104
}
107105

108106
// PgConnection::status -- return connection or result status

src/interfaces/libpq++/pgenv.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1994, Regents of the University of California
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgenv.cc,v 1.3 1997/02/13 10:00:33 scrappy Exp $
17+
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgenv.cc,v 1.4 1999/05/10 15:27:19 momjian Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -66,3 +66,19 @@ string PgEnv::getenv(const char* name)
6666
char* env = ::getenv(name);
6767
return (env ? env : "");
6868
}
69+
70+
71+
// Extract the PgEnv contents into a form suitable for PQconnectdb
72+
// which happens to be readable, hence choice of <<
73+
ostream& operator << (ostream &s, const PgEnv& a)
74+
{
75+
s<<' '; // surround with whitespace, just in case
76+
if(a.pgHost.length() !=0)s<<" host=" <<a.pgHost;
77+
if(a.pgPort.length() !=0)s<<" port=" <<a.pgPort;
78+
// deprecated: if(a.pgAuth.length()!=0)s<<" authtype="<<a.pgAuth;
79+
if(a.pgOption.length()!=0)s<<" options="<<a.pgOption;
80+
if(a.pgTty.length() !=0)s<<" tty=" <<a.pgTty;
81+
s<<' ';
82+
83+
return s;
84+
}

src/interfaces/libpq++/pgenv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define PGENV_H
2020

2121
#include <string>
22+
#include <iostream>
2223

2324
#ifdef __sun__
2425
#ifndef __GNUC__
@@ -79,6 +80,7 @@ class PgEnv {
7980

8081
protected:
8182
string getenv(const char*);
83+
friend ostream& operator << (ostream &, const PgEnv&);
8284
};
8385

8486
#endif // PGENV_H

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy