# 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 $
#
#-------------------------------------------------------------------------
-I$(SRCHEADERDIR) \
-I$(LIBPQDIR)
-#CXXFLAGS+= -DDEBUGFILE
-
ifdef KRBVERS
CXXFLAGS+= $(KRBFLAGS)
endif
* 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 $
*
*-------------------------------------------------------------------------
*/
#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 */
/*-------------------------------------------------------------------------
*
* FILE
- * pgconnection.cpp
+ * pgconnection.cc
*
* DESCRIPTION
* implementation of the PgConnection class.
* 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"
-}
// ****************************************************************
//
// 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 ) {
// 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);
+
+ // Now we have a connection we must close (even if it's bad!)
+ pgCloseConnection = 1;
// Status will return either CONNECTION_OK or CONNECTION_BAD
- cst = Status();
- if(CONNECTION_OK == cst) pgCloseConnection = (ConnStatusType)1;
- else pgCloseConnection = (ConnStatusType)0;
-
-return cst;
+ return Status();
}
// PgConnection::status -- return connection or result status
* 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"
// 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();
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
* 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
// ****************************************************************
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
* 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 $
*
*-------------------------------------------------------------------------
*/
#ifndef PGDATABASE_H
#define PGDATABASE_H
+#ifndef PGCONNECTION_H
#include "pgconnection.h"
-
+#endif
// ****************************************************************
//
// 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();
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
* 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
: PgConnection(conninfo)
{
Init();
- Create();
- Open();
+ if (! ConnectionBad()) {
+ Create();
+ Open();
+ }
}
// constructor
PgLargeObject::PgLargeObject(Oid lobjId, const char* conninfo)
: PgConnection(conninfo)
{
-
Init(lobjId);
- if ( !pgObject ) {
- Create();
+ if (! ConnectionBad()) {
+ if ( !pgObject )
+ Create();
+ Open();
}
- Open();
}
// destructor -- closes large object
// 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);
void PgLargeObject::Close()
{
- if (pgFd >= 0) lo_close(pgConn, pgFd);
+ if (pgFd >= 0) lo_close(pgConn, pgFd);
+ pgFd = -1;
}
{
return loStatus;
}
-
* 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
// ****************************************************************
Oid Import(const char* filename);
int Export(const char* filename);
string Status();
-};
-#endif // PGLOBJ_H
+private:
+// We don't support copying of PgLargeObject objects,
+// so make copy constructor and assignment op private.
+ PgLargeObject(const PgLargeObject&);
+ PgLargeObject& operator= (const PgLargeObject&);
+};
-// sig 11's if the filename points to a binary file.
+#endif // PGLOBJECT_H
* 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 $
*
*-------------------------------------------------------------------------
*/
#ifndef PGTRANSDB_H
#define PGTRANSDB_H
+#ifndef PGDATABASE_H
#include "pgdatabase.h"
+#endif
// ****************************************************************
//
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