Returns the status of the connection.
The status can be CONNECTION_OK or CONNECTION_BAD.
-ConnStatusType *PQstatus(PGconn *conn)
+ConnStatusType PQstatus(PGconn *conn)
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.2 1997/02/13 10:00:27 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.3 1999/05/10 15:27:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include
#include
+#include
#include "pgconnection.h"
extern "C" {
PQtrace(pgConn, debug);
#endif
- // Set Host Authentication service
- char errorMessage[ERROR_MSG_LENGTH];
- memset(errorMessage, 0, sizeof(errorMessage));
- fe_setauthsvc(pgEnv.Auth(), errorMessage);
-
// Connect to the database
- pgConn = PQsetdb(pgEnv.Host(), pgEnv.Port(), pgEnv.Option(), pgEnv.TTY(), dbName);
+ ostrstream conninfo;
+ conninfo << "dbname="<
+ conninfo << pgEnv;
+ pgConn=PQconnectdb(conninfo.str());
+ conninfo.freeze(0);
- // Return the connection status
- if (errorMessage) {
- SetErrorMessage( errorMessage );
- return CONNECTION_BAD;
+ if(ConnectionBad()) {
+ SetErrorMessage( PQerrorMessage(pgConn) );
}
- else
- return Status();
+
+ return Status();
}
// PgConnection::status -- return connection or result status
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgenv.cc,v 1.3 1997/02/13 10:00:33 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgenv.cc,v 1.4 1999/05/10 15:27:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
char* env = ::getenv(name);
return (env ? env : "");
}
+
+
+// Extract the PgEnv contents into a form suitable for PQconnectdb
+// which happens to be readable, hence choice of <<
+ostream& operator << (ostream &s, const PgEnv& a)
+{
+ s<<' '; // surround with whitespace, just in case
+ if(a.pgHost.length() !=0)s<<" host=" <
+ if(a.pgPort.length() !=0)s<<" port=" <
+ // deprecated: if(a.pgAuth.length()!=0)s<<" authtype="<
+ if(a.pgOption.length()!=0)s<<" options="<
+ if(a.pgTty.length() !=0)s<<" tty=" <
+ s<<' ';
+
+ return s;
+}
#define PGENV_H
#include
+#include
#ifdef __sun__
#ifndef __GNUC__
protected:
string getenv(const char*);
+ friend ostream& operator << (ostream &, const PgEnv&);
};
#endif // PGENV_H