mirror of https://github.com/postgres/postgres
Remove broken tracing code (which would be dangerous if it did work...)
libpq++.h contained copies of the class declarations in the other libpq++ include files, which was bogus enough, but the declarations were not completely in step with the real declarations. Remove these in favor of including the headers with #include. Make PgConnection destructor virtual (not absolutely necessary, but seems like a real good idea considering the number of subclasses derived from it). Give all classes declared private copy constructors and assignment operators, to prevent compiler from thinking it can copy these objects safely.
This commit is contained in:
parent
51c92941c6
commit
290978fff0
|
@ -6,7 +6,7 @@
|
|||
# Copyright (c) 1994, Regents of the University of California
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/Makefile.in,v 1.23 2000/03/31 05:00:36 tgl Exp $
|
||||
# $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/Makefile.in,v 1.24 2000/04/22 22:39:15 tgl Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
|
@ -27,8 +27,6 @@ CXXFLAGS+= -I$(SRCDIR)/backend \
|
|||
-I$(SRCHEADERDIR) \
|
||||
-I$(LIBPQDIR)
|
||||
|
||||
#CXXFLAGS+= -DDEBUGFILE
|
||||
|
||||
ifdef KRBVERS
|
||||
CXXFLAGS+= $(KRBFLAGS)
|
||||
endif
|
||||
|
|
|
@ -8,12 +8,15 @@
|
|||
* used for building front-end applications
|
||||
*
|
||||
* NOTES
|
||||
* Currently under construction.
|
||||
* This is intended to be included by client applications.
|
||||
* It will not work as an inclusion in the libpq++ sources, since
|
||||
* in the build environment the individual include files are not
|
||||
* yet installed in a subdirectory.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpq++.h,v 1.8 2000/04/14 01:00:16 tgl Exp $
|
||||
* $Id: libpq++.h,v 1.9 2000/04/22 22:39:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -21,188 +24,10 @@
|
|||
#ifndef LIBPQXX_H
|
||||
#define LIBPQXX_H
|
||||
|
||||
extern "C" {
|
||||
#include "config.h"
|
||||
}
|
||||
|
||||
/* We assume that the C++ compiler will have these keywords, even though
|
||||
* config.h may have #define'd them to empty because C compiler doesn't.
|
||||
*/
|
||||
#undef const
|
||||
#undef inline
|
||||
#undef signed
|
||||
#undef volatile
|
||||
|
||||
#ifdef HAVE_CXX_STRING_HEADER
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include "postgres.h"
|
||||
#include "libpq-fe.h"
|
||||
}
|
||||
|
||||
#ifdef HAVE_NAMESPACE_STD
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
// PgConnection - a connection made to a postgres backend
|
||||
//
|
||||
// ****************************************************************
|
||||
class PgConnection {
|
||||
protected:
|
||||
PGconn* pgConn; // Connection Structures
|
||||
PGresult* pgResult; // Query Result
|
||||
int pgCloseConnection; // Flag indicating whether the connection should be closed
|
||||
ConnStatusType Connect(const char* conninfo);
|
||||
string IntToString(int);
|
||||
PgConnection();
|
||||
|
||||
public:
|
||||
PgConnection(const char* conninfo); // use reasonable and environment defaults
|
||||
~PgConnection(); // close connection and clean up
|
||||
|
||||
ConnStatusType Status();
|
||||
int ConnectionBad();
|
||||
const char* ErrorMessage();
|
||||
|
||||
// returns the database name of the connection
|
||||
const char* DBName();
|
||||
|
||||
ExecStatusType Exec(const char* query); // send a query to the backend
|
||||
int ExecCommandOk(const char* query); // send a command and check if it's
|
||||
int ExecTuplesOk(const char* query); // send a command and check if tuple
|
||||
PGnotify* Notifies();
|
||||
};
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
// PgDatabase - a class for accessing databases
|
||||
//
|
||||
// ****************************************************************
|
||||
class PgDatabase : public PgConnection {
|
||||
protected:
|
||||
PgDatabase() : PgConnection() {} // Do not connect
|
||||
|
||||
public:
|
||||
// connect to the database with conninfo
|
||||
PgDatabase(const char *conninfo) : PgConnection(conninfo) {};
|
||||
~PgDatabase() {}; // close connection and clean up
|
||||
// query result access
|
||||
int Tuples();
|
||||
int CmdTuples();
|
||||
int Fields();
|
||||
const char* FieldName(int field_num);
|
||||
int FieldNum(const char *field_name);
|
||||
Oid FieldType(int field_num);
|
||||
Oid FieldType(const char *field_name);
|
||||
short FieldSize(int field_num);
|
||||
short FieldSize(const char *field_name);
|
||||
const char* GetValue(int tup_num, int field_num);
|
||||
const char* GetValue(int tup_num, const char *field_name);
|
||||
int GetIsNull(int tup_num, int field_num);
|
||||
int GetIsNull(int tup_num, const char* field_name);
|
||||
int GetLength(int tup_num, int field_num);
|
||||
int GetLength(int tup_num, const char* field_name);
|
||||
void DisplayTuples(FILE *out = 0, int fillAlign = 1,
|
||||
const char* fieldSep = "|",int printHeader = 1, int quiet = 0) ;
|
||||
void PrintTuples(FILE *out = 0, int printAttName = 1,
|
||||
int terseOutput = 0, int width = 0) ;
|
||||
|
||||
// copy command related access
|
||||
int GetLine(char* string, int length);
|
||||
void PutLine(const char* string);
|
||||
const char *OidStatus();
|
||||
int EndCopy();
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
// PGLargeObject - a class for accessing Large Object in a database
|
||||
//
|
||||
// ****************************************************************
|
||||
class PgLargeObject : public PgConnection {
|
||||
private:
|
||||
int pgFd;
|
||||
Oid pgObject;
|
||||
string loStatus;
|
||||
|
||||
public:
|
||||
PgLargeObject(const char* conninfo = 0); // use reasonable defaults and create large object
|
||||
PgLargeObject(Oid lobjId, const char* conninfo = 0); // use reasonable defaults and open large object
|
||||
~PgLargeObject(); // close connection and clean up
|
||||
|
||||
void Create();
|
||||
void Open();
|
||||
void Close();
|
||||
int Read(char* buf, int len);
|
||||
int Write(const char* buf, int len);
|
||||
int LSeek(int offset, int whence);
|
||||
int Tell();
|
||||
int Unlink();
|
||||
Oid LOid();
|
||||
Oid Import(const char* filename);
|
||||
int Export(const char* filename);
|
||||
string Status();
|
||||
};
|
||||
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
// PgTransaction - a class for running transactions against databases
|
||||
//
|
||||
// ****************************************************************
|
||||
class PgTransaction : public PgDatabase {
|
||||
protected:
|
||||
ExecStatusType BeginTransaction();
|
||||
ExecStatusType EndTransaction();
|
||||
PgTransaction() : PgDatabase() {} // Do not connect
|
||||
|
||||
public:
|
||||
PgTransaction(const char* conninfo); // use reasonable & environment defaults
|
||||
// connect to the database with given environment and database name
|
||||
PgTransaction(const PgConnection&);
|
||||
virtual ~PgTransaction(); // close connection and clean up
|
||||
|
||||
};
|
||||
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
// PgCursor - a class for querying databases using a cursor
|
||||
//
|
||||
// ****************************************************************
|
||||
class PgCursor : public PgTransaction {
|
||||
protected:
|
||||
int Fetch(const string& num, const string& dir);
|
||||
string pgCursor;
|
||||
PgCursor() : PgTransaction() {} // Do not connect
|
||||
|
||||
public:
|
||||
PgCursor(const char* dbName, const char* cursor); // use reasonable & environment defaults
|
||||
// connect to the database with given environment and database name
|
||||
PgCursor(const PgConnection&, const char* cursor);
|
||||
virtual ~PgCursor(); // close connection and clean up
|
||||
|
||||
// Commands associated with cursor interface
|
||||
int Declare(const string& query, int binary = 0); // Declare a cursor with given name
|
||||
int Fetch(const char* dir = "FORWARD"); // Fetch ALL tuples in given direction
|
||||
int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples
|
||||
int Close(); // Close the cursor
|
||||
|
||||
// Accessors to the cursor name
|
||||
const char* Cursor();
|
||||
void Cursor(const string& cursor);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// buffer size
|
||||
#define BUFSIZE 1024
|
||||
#include "libpq++/pgconnection.h"
|
||||
#include "libpq++/pgdatabase.h"
|
||||
#include "libpq++/pglobject.h"
|
||||
#include "libpq++/pgtransdb.h"
|
||||
#include "libpq++/pgcursordb.h"
|
||||
|
||||
#endif /* LIBPQXX_H */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* FILE
|
||||
* pgconnection.cpp
|
||||
* pgconnection.cc
|
||||
*
|
||||
* DESCRIPTION
|
||||
* implementation of the PgConnection class.
|
||||
|
@ -10,16 +10,13 @@
|
|||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.8 2000/03/30 05:30:42 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.9 2000/04/22 22:39:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "pgconnection.h"
|
||||
|
||||
extern "C" {
|
||||
#include "fe-auth.h"
|
||||
}
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
|
@ -46,12 +43,7 @@ PgConnection::PgConnection(const char* conninfo)
|
|||
// destructor - closes down the connection and cleanup
|
||||
PgConnection::~PgConnection()
|
||||
{
|
||||
// Terminate the debugging output if it was turned on
|
||||
#if defined(DEBUGFILE)
|
||||
PQuntrace(pgConn);
|
||||
#endif
|
||||
|
||||
// Close the conneciton only if needed
|
||||
// Close the connection only if needed
|
||||
// This feature will most probably be used by the derived classes that
|
||||
// need not close the connection after they are destructed.
|
||||
if ( pgCloseConnection ) {
|
||||
|
@ -64,22 +56,14 @@ PgConnection::~PgConnection()
|
|||
// establish a connection to a backend
|
||||
ConnStatusType PgConnection::Connect(const char* conninfo)
|
||||
{
|
||||
ConnStatusType cst;
|
||||
// Turn the trace on
|
||||
#if defined(DEBUGFILE)
|
||||
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;
|
||||
// Now we have a connection we must close (even if it's bad!)
|
||||
pgCloseConnection = 1;
|
||||
|
||||
return cst;
|
||||
// Status will return either CONNECTION_OK or CONNECTION_BAD
|
||||
return Status();
|
||||
}
|
||||
|
||||
// PgConnection::status -- return connection or result status
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pgconnection.h,v 1.6 2000/04/14 01:00:16 tgl Exp $
|
||||
* $Id: pgconnection.h,v 1.7 2000/04/22 22:39:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PGCONN_H
|
||||
#define PGCONN_H
|
||||
#ifndef PGCONNECTION_H
|
||||
#define PGCONNECTION_H
|
||||
|
||||
extern "C" {
|
||||
#include "config.h"
|
||||
|
@ -57,13 +57,13 @@ using namespace std;
|
|||
// derived from this class to obtain the connection interface.
|
||||
class PgConnection {
|
||||
protected:
|
||||
PGconn* pgConn; // Connection Structures
|
||||
PGresult* pgResult; // Query Result
|
||||
int pgCloseConnection; // Flag indicating whether the connection should be closed or not
|
||||
PGconn* pgConn; // Connection Structure
|
||||
PGresult* pgResult; // Current Query Result
|
||||
int pgCloseConnection; // TRUE if connection should be closed by destructor
|
||||
|
||||
public:
|
||||
PgConnection(const char* conninfo); // use reasonable & environment defaults
|
||||
~PgConnection(); // close connection and clean up
|
||||
virtual ~PgConnection(); // close connection and clean up
|
||||
|
||||
// Connection status and error messages
|
||||
ConnStatusType Status();
|
||||
|
@ -82,9 +82,14 @@ public:
|
|||
protected:
|
||||
ConnStatusType Connect(const char* conninfo);
|
||||
string IntToString(int);
|
||||
|
||||
protected:
|
||||
// Default constructor is only available to subclasses
|
||||
PgConnection();
|
||||
|
||||
private:
|
||||
// We don't support copying of PgConnection objects,
|
||||
// so make copy constructor and assignment op private.
|
||||
PgConnection(const PgConnection&);
|
||||
PgConnection& operator= (const PgConnection&);
|
||||
};
|
||||
|
||||
#endif // PGCONN_H
|
||||
#endif // PGCONNECTION_H
|
||||
|
|
|
@ -14,16 +14,17 @@
|
|||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* $Id: pgcursordb.h,v 1.4 2000/01/26 05:58:48 momjian Exp $
|
||||
* $Id: pgcursordb.h,v 1.5 2000/04/22 22:39:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PGCURSOR_H
|
||||
#define PGCURSOR_H
|
||||
#ifndef PGCURSORDB_H
|
||||
#define PGCURSORDB_H
|
||||
|
||||
#ifndef PGTRANSDB_H
|
||||
#include "pgtransdb.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// ****************************************************************
|
||||
|
@ -60,6 +61,12 @@ protected:
|
|||
|
||||
protected:
|
||||
PgCursor() : PgTransaction() {} // Do not connect
|
||||
|
||||
private:
|
||||
// We don't support copying of PgCursor objects,
|
||||
// so make copy constructor and assignment op private.
|
||||
PgCursor(const PgCursor&);
|
||||
PgCursor& operator= (const PgCursor&);
|
||||
}; // End PgCursor Class Declaration
|
||||
|
||||
#endif // PGCURSOR_H
|
||||
#endif // PGCURSORDB_H
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* $Id: pgdatabase.h,v 1.7 2000/03/30 05:30:42 tgl Exp $
|
||||
* $Id: pgdatabase.h,v 1.8 2000/04/22 22:39:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -22,8 +22,9 @@
|
|||
#ifndef PGDATABASE_H
|
||||
#define PGDATABASE_H
|
||||
|
||||
#ifndef PGCONNECTION_H
|
||||
#include "pgconnection.h"
|
||||
|
||||
#endif
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
|
@ -35,8 +36,10 @@
|
|||
// results are being received.
|
||||
class PgDatabase : public PgConnection {
|
||||
public:
|
||||
PgDatabase(const char* conninfo) : PgConnection(conninfo) {} // use reasonable defaults
|
||||
~PgDatabase() {} ; // close connection and clean up
|
||||
// connect to the database with conninfo
|
||||
PgDatabase(const char* conninfo) : PgConnection(conninfo) {}
|
||||
|
||||
~PgDatabase() {} // close connection and clean up
|
||||
|
||||
// query result access
|
||||
int Tuples();
|
||||
|
@ -67,6 +70,12 @@ public:
|
|||
|
||||
protected:
|
||||
PgDatabase() : PgConnection() {} // Do not connect
|
||||
|
||||
private:
|
||||
// We don't support copying of PgDatabase objects,
|
||||
// so make copy constructor and assignment op private.
|
||||
PgDatabase(const PgDatabase&);
|
||||
PgDatabase& operator= (const PgDatabase&);
|
||||
};
|
||||
|
||||
#endif // PGDATABASE_H
|
||||
|
|
|
@ -10,17 +10,17 @@
|
|||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.5 1999/05/30 15:17:58 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.6 2000/04/22 22:39:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "pglobject.h"
|
||||
|
||||
extern "C" {
|
||||
#include "libpq/libpq-fs.h"
|
||||
}
|
||||
|
||||
#include "pglobject.h"
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
// PgLargeObject Implementation
|
||||
|
@ -33,8 +33,10 @@ PgLargeObject::PgLargeObject(const char* conninfo)
|
|||
: PgConnection(conninfo)
|
||||
{
|
||||
Init();
|
||||
if (! ConnectionBad()) {
|
||||
Create();
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
// constructor
|
||||
|
@ -43,12 +45,12 @@ PgLargeObject::PgLargeObject(const char* conninfo)
|
|||
PgLargeObject::PgLargeObject(Oid lobjId, const char* conninfo)
|
||||
: PgConnection(conninfo)
|
||||
{
|
||||
|
||||
Init(lobjId);
|
||||
if ( !pgObject ) {
|
||||
if (! ConnectionBad()) {
|
||||
if ( !pgObject )
|
||||
Create();
|
||||
}
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
// destructor -- closes large object
|
||||
|
@ -83,6 +85,8 @@ void PgLargeObject::Create()
|
|||
// open large object and check for errors
|
||||
void PgLargeObject::Open()
|
||||
{
|
||||
// Close any prior object
|
||||
Close();
|
||||
// Open the object
|
||||
pgFd = lo_open(pgConn, pgObject, INV_READ|INV_WRITE);
|
||||
|
||||
|
@ -116,6 +120,7 @@ int PgLargeObject::Unlink()
|
|||
void PgLargeObject::Close()
|
||||
{
|
||||
if (pgFd >= 0) lo_close(pgConn, pgFd);
|
||||
pgFd = -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,4 +164,3 @@ string PgLargeObject::Status()
|
|||
{
|
||||
return loStatus;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,18 +11,17 @@
|
|||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* $Id: pglobject.h,v 1.4 2000/01/26 05:58:48 momjian Exp $
|
||||
* $Id: pglobject.h,v 1.5 2000/04/22 22:39:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef PGLOBJ_H
|
||||
#define PGLOBJ_H
|
||||
#ifndef PGLOBJECT_H
|
||||
#define PGLOBJECT_H
|
||||
|
||||
#ifndef PGCONNECTION_H
|
||||
#include "pgconnection.h"
|
||||
|
||||
// buffer size
|
||||
#define BUFSIZE 1024
|
||||
#endif
|
||||
|
||||
|
||||
// ****************************************************************
|
||||
|
@ -54,8 +53,12 @@ public:
|
|||
Oid Import(const char* filename);
|
||||
int Export(const char* filename);
|
||||
string Status();
|
||||
|
||||
private:
|
||||
// We don't support copying of PgLargeObject objects,
|
||||
// so make copy constructor and assignment op private.
|
||||
PgLargeObject(const PgLargeObject&);
|
||||
PgLargeObject& operator= (const PgLargeObject&);
|
||||
};
|
||||
|
||||
#endif // PGLOBJ_H
|
||||
|
||||
// sig 11's if the filename points to a binary file.
|
||||
#endif // PGLOBJECT_H
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* $Id: pgtransdb.h,v 1.4 2000/01/26 05:58:48 momjian Exp $
|
||||
* $Id: pgtransdb.h,v 1.5 2000/04/22 22:39:15 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
@ -22,7 +22,9 @@
|
|||
#ifndef PGTRANSDB_H
|
||||
#define PGTRANSDB_H
|
||||
|
||||
#ifndef PGDATABASE_H
|
||||
#include "pgdatabase.h"
|
||||
#endif
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
|
@ -45,6 +47,12 @@ protected:
|
|||
|
||||
protected:
|
||||
PgTransaction() : PgDatabase() {} // Do not connect
|
||||
|
||||
private:
|
||||
// We don't support copying of PgTransaction objects,
|
||||
// so make copy constructor and assignment op private.
|
||||
PgTransaction(const PgTransaction&);
|
||||
PgTransaction& operator= (const PgTransaction&);
|
||||
}; // End PgTransaction Class Declaration
|
||||
|
||||
#endif // PGTRANSDB_H
|
||||
|
|
Loading…
Reference in New Issue