1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-01 21:31:19 +03:00

Here it is. Remove or rename the current interfaces/libpq++ and untar

this file in interfaces/

It will all need to be checked in.  I used the char *rcsid[] method for
cvs ids so it can be strings | grep'd to find version numbers.  The new
version for the library is 3.0.

Run configure from src/ to create the Makefile and it should be good to
go.

I did minimal documentation references in the README, I'll see if I can
get something to Tom Lockhart rather quickly.

Vince.
This commit is contained in:
Bruce Momjian
1999-05-23 01:04:07 +00:00
parent 795f6ca66a
commit b14c99d8d6
28 changed files with 556 additions and 588 deletions

View File

@@ -9,21 +9,19 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.4 1999/05/16 14:34:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdlib.h>
#include <string.h>
#include <strstream.h>
#include "pgconnection.h"
extern "C" {
#include "fe-auth.h"
}
static char rcsid[] = "$Id: pgconnection.cc,v 1.5 1999/05/23 01:04:00 momjian Exp $";
// ****************************************************************
//
@@ -35,32 +33,17 @@ PgConnection::PgConnection()
: pgConn(NULL), pgResult(NULL), pgCloseConnection(0)
{}
// copy constructor -- copy the pointers; no deep copy required
PgConnection::PgConnection(const PgConnection& conn)
: pgEnv(conn.pgEnv), pgConn(conn.pgConn), pgResult(conn.pgResult),
pgCloseConnection(conn.pgCloseConnection)
{}
// constructor -- checks environment variable for database name
PgConnection::PgConnection(const char* dbName)
// Now uses PQconnectdb
PgConnection::PgConnection(const char* conninfo)
: pgConn(NULL), pgResult(NULL), pgCloseConnection(1)
{
// Get a default database name to connect to
char* defDB = (char*)dbName;
if ( !dbName )
if ( !(defDB = getenv(ENV_DEFAULT_DBASE)) )
return;
// Connect to the database
Connect( defDB );
Connect( conninfo );
}
// constructor -- for given environment and database name
PgConnection::PgConnection(const PgEnv& env, const char* dbName)
: pgEnv(env), pgConn(NULL), pgResult(NULL), pgCloseConnection(1)
{
Connect( dbName );
}
// destructor - closes down the connection and cleanup
PgConnection::~PgConnection()
@@ -74,39 +57,37 @@ PgConnection::~PgConnection()
// This feature will most probably be used by the derived classes that
// need not close the connection after they are destructed.
if ( pgCloseConnection ) {
if (pgResult) PQclear(pgResult);
if (pgConn) PQfinish(pgConn);
if(pgResult) PQclear(pgResult);
if(pgConn) PQfinish(pgConn);
}
}
// PgConnection::connect
// establish a connection to a backend
ConnStatusType PgConnection::Connect(const char* dbName)
ConnStatusType PgConnection::Connect(const char* conninfo)
{
// Turn the trace on
#if defined(DEBUG)
FILE *debug = fopen("/tmp/trace.out","w");
PQtrace(pgConn, debug);
#endif
ConnStatusType cst;
// Turn the trace on
#if defined(DEBUG)
FILE *debug = fopen("/tmp/trace.out","w");
PQtrace(pgConn, debug);
#endif
// Connect to the database
pgConn = PQconnectdb(conninfo);
// Status will return either CONNECTION_OK or CONNECTION_BAD
cst = Status();
if(CONNECTION_OK == cst) pgCloseConnection = (ConnStatusType)1;
else pgCloseConnection = (ConnStatusType)0;
// Connect to the database
ostrstream conninfo;
conninfo << "dbname="<<dbName;
conninfo << pgEnv;
pgConn=PQconnectdb(conninfo.str());
conninfo.freeze(0);
if(ConnectionBad()) {
SetErrorMessage( PQerrorMessage(pgConn) );
}
return Status();
return cst;
}
// PgConnection::status -- return connection or result status
ConnStatusType PgConnection::Status()
{
return PQstatus(pgConn);
return PQstatus(pgConn);
}
// PgConnection::exec -- send a query to the backend
@@ -121,11 +102,9 @@ ExecStatusType PgConnection::Exec(const char* query)
// Return the status
if (pgResult)
return PQresultStatus(pgResult);
else {
SetErrorMessage( PQerrorMessage(pgConn) );
return PGRES_FATAL_ERROR;
}
return PQresultStatus(pgResult);
else
return PGRES_FATAL_ERROR;
}
// Return true if the Postgres command was executed OK
@@ -140,6 +119,9 @@ int PgConnection::ExecTuplesOk(const char* query)
} // End ExecTuplesOk()
// Don't know why these next two need to be part of Connection
// PgConnection::notifies() -- returns a notification from a list of unhandled notifications
PGnotify* PgConnection::Notifies()
{
@@ -147,15 +129,6 @@ PGnotify* PgConnection::Notifies()
return PQnotifies(pgConn);
}
// PgConnection::SetErrorMessage
// sets error message to the given string
void PgConnection::SetErrorMessage(const string& msg, int append)
{
if ( append )
pgErrorMessage += msg;
else
pgErrorMessage = msg;
}
// From Integer To String Conversion Function
string PgConnection::IntToString(int n)
@@ -165,3 +138,24 @@ string PgConnection::IntToString(int n)
sprintf(buffer, "%d", n);
return buffer;
}
int PgConnection::ConnectionBad()
{
return Status() == CONNECTION_BAD;
}
const char* PgConnection::ErrorMessage()
{
return (const char *)PQerrorMessage(pgConn);
}
const char* PgConnection::DBName()
{
return (const char *)PQdb(pgConn);
}