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

@ -0,0 +1,33 @@
5/18/1999 - vv
---------
* Rewrote libpq++.H
* Added CVS IDs
* Incremented shared library version to 3.0
* Cleaned up makefiles
* Made examples use the installed versions of the library and header
4/26/1999 - vv
---------
* Changed PrintTuples and DisplayTuples in PgDatabase to use PQprint()
4/14/1999 - vv
---------
* Changed connection routines to use PQconnectdb()
* Connect now returns CONNECTION_OK or CONNECTION_BAD
* Eliminated pgEnv
* Changed error handler to return proper messages
* New function LOid() returns Large Object ID
* New function Status() returns Large Object Status

View File

@ -6,12 +6,12 @@
# Copyright (c) 1994, Regents of the University of California
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/Makefile.in,v 1.11 1999/01/17 06:19:39 momjian Exp $
# $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/Makefile.in,v 1.12 1999/05/23 01:03:57 momjian Exp $
#
#-------------------------------------------------------------------------
NAME= pq++
SO_MAJOR_VERSION= 2
SO_MAJOR_VERSION= 3
SO_MINOR_VERSION= 0
SRCDIR= @top_srcdir@
@ -42,20 +42,16 @@ ifdef KRBVERS
CXXFLAGS+= $(KRBFLAGS)
endif
OBJS = pgenv.o pgconnection.o pgtransdb.o pgcursordb.o pglobject.o
OBJS = pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o
ifeq ($(PORTNAME), win)
SHLIB_LINK+= -L../libpq -lpq -lstdc++
else
SHLIB_LINK= -L../libpq -lpq
endif
# Shared library stuff, also default 'all' target
include $(SRCDIR)/Makefile.shlib
# Pull shared-lib CFLAGS into CXXFLAGS
CXXFLAGS+= $(CFLAGS)
CXXFLAGS+= $(CFLAGS) -Wno-unused
.PHONY: examples
@ -68,9 +64,8 @@ install: install-headers install-lib $(install-shlib-dep)
LIBPGXXDIR = libpq++
LIBPGXXHEADERDIR = $(HEADERDIR)/$(LIBPGXXDIR)
MAINHEADER = libpq++.h
LIBPGXXHEADERS = pgenv.h \
pgconnection.h \
MAINHEADER = libpq++.H
LIBPGXXHEADERS = pgconnection.h \
pgdatabase.h \
pgtransdb.h \
pgcursordb.h \
@ -91,9 +86,6 @@ beforeinstall-headers:
clean:
rm -f libpq++.a $(shlib) $(OBJS)
$(MAKE) -C examples clean
ifeq ($(PORTNAME), win)
rm -f pq++.def
endif
dep depend:
$(CXX) -MM $(CXXFLAGS) *.cc >depend

View File

@ -1,22 +1,25 @@
This directory contains libpq++, the C++ language interface to POSTGRESQL.
libpq++ is implemented on of the libpq library. Users would benefit
from reading the chapter on libpq in the PostgreSQL users manual
before using libpq++.
The initial version of this implementation was done by William Wanders
(wwanders@sci.kun.nl)
Based on the original work by William Wanders (wwanders@sci.kun.nl)
and Jolly Chen (jolly@cs.berkeley.edu), this is the first set of
changes to libpq++ since ~1997. Pgenv has been removed, deprecated
functions removed and/or updated and error handling rewritten,
however for the most part it remains as a wrapper around libpq.
The documentation on libpq is recommended reading to understand
the function of libpq++.
This is only a preliminary attempt at providing something useful for
people who would like to use C++ to build frontend applications to
PostgreSQL. The API provided herein is subject to change in later
versions of PostgreSQL.
The API provided herein is subject to change in later versions of
PostgreSQL.
For details on how to to use libpq++, see the man page in the man/
subdirectory and the test programs in the examples/ subdirectory.
subdirectory and the test programs in the examples/ subdirectory.
libpq++ has been tested with g++, version 2.7.0
** PgConnection has been changed to accept either the environment
variables or conninfo style strings. See the PQconnectdb in the
documentation on libpq for details.
libpq++ has only been tested with g++, version 2.7.2.1
Vince Vielhaber (vev@michvhf.com)
Tue May 18 08:30:00 EDT 1999
- Jolly Chen
jolly@cs.berkeley.edu
Tue Sep 5 11:09:51 PDT 1995

View File

@ -0,0 +1,6 @@
* Implement exceptions
* Binary Large Objects segfaulting
* Many other things I have yet to discover

View File

@ -2,13 +2,11 @@
# Dependencies for libpq++ C++ library for Postgres SQL
#
# Author: Leo Shuster (lsh@lubrizol.com)
# Updated 18 May 1999 by Vince Vielhaber (vev@michvhf.com)
###########################################################################
pgenv.o :: pgenv.cc \
pgenv.h
pgconnection.o :: pgconnection.cc \
pgconnection.h \
pgenv.h \
$(LIBPQDIR)/libpq-fe.h \
$(LIBPQDIR)/fe-auth.h
@ -16,7 +14,6 @@ pgtransdb.o :: pgtransdb.cc \
pgtransdb.h \
pgdatabase.h \
pgconnection.h \
pgenv.h \
$(LIBPQDIR)/libpq-fe.h \
$(LIBPQDIR)/fe-auth.h
@ -24,13 +21,11 @@ pgcursordb.o :: pgcursordb.cc \
pgcursordb.h \
pgdatabase.h \
pgconnection.h \
pgenv.h \
$(LIBPQDIR)/libpq-fe.h \
$(LIBPQDIR)/fe-auth.h
pglobject.o :: pglobject.cc \
pglobject.h \
pgconnection.h \
pgenv.h \
$(LIBPQDIR)/libpq-fe.h \
$(LIBPQHEADERDIR)/libpq-fs.h

View File

@ -2,26 +2,23 @@
# Makefile for example programs
#
SRCDIR= ../../..
include ../../../Makefile.global
LIBNAME= libpq++
HEADERDIR= /usr/local/pgsql/include
LIBPQDIR= /usr/local/pgsql/lib
# We have to override -Werror, which makes warnings, fatal, because we
# inevitably get the warning, "abstract declarator used as declaration"
# because of our inclusion of c.h and we don't know how to stop that.
CXXFLAGS= $(CFLAGS) -Wno-error
CXXFLAGS= $(CFLAGS) -Wno-error -Wno-unused -Wl,-Bdynamic
INCLUDE_OPT= -I$(HEADERDIR)
INCLUDE_OPT= \
-I.. \
-I../../../backend \
-I../../../include \
-I$(LIBPQDIR) \
-I$(HEADERDIR)
CXXFLAGS+= $(INCLUDE_OPT)
LDFLAGS+= -L.. -lpq++ -L$(LIBPQDIR) -lpq
LDFLAGS+= -L$(LIBPQDIR) -lpq++
#
# And where libpq goes, so goes the authentication stuff...
@ -34,17 +31,12 @@ endif
PROGS= testlibpq0 testlibpq1 testlibpq2 testlibpq3 \
testlibpq4 testlibpq5 testlibpq6 testlo
all: submake $(PROGS)
all: $(PROGS)
$(PROGS): % : %.cc ../$(LIBNAME).a
$(PROGS): % : %.cc
$(CXX) $(CXXFLAGS) -o $@ $@.cc $(LDFLAGS)
.PHONY: submake
submake:
$(MAKE) -C.. $(LIBNAME).a
../$(LIBNAME).a:
$(MAKE) -C.. $(LIBNAME).a
clean:
rm -f $(PROGS)

View File

@ -9,18 +9,18 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.3 1997/02/13 10:00:42 scrappy Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.4 1999/05/23 01:04:05 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <iostream.h>
#include <libpq++.h>
#include <libpq++.H>
int main()
{
// Open the connection to the database and make sure it's OK
PgDatabase data("template1");
PgDatabase data("dbname=template1");
if ( data.ConnectionBad() ) {
cout << "Connection was unsuccessful..." << endl
<< "Error message returned: " << data.ErrorMessage() << endl;

View File

@ -8,7 +8,7 @@
#include <iostream.h>
#include <iomanip.h>
#include <libpq++.h>
#include <libpq++.H>
int main()
{
@ -16,7 +16,7 @@ int main()
// When no parameters are given then the system will
// try to use reasonable defaults by looking up environment variables
// or, failing that, using hardwired constants
const char* dbName = "template1";
const char* dbName = "dbname=template1";
PgDatabase data(dbName);
// check to see that the backend connection was successfully made

View File

@ -8,7 +8,7 @@
#include <iostream.h>
#include <iomanip.h>
#include <libpq++.h>
#include <libpq++.H>
int main()
{
@ -16,7 +16,7 @@ int main()
// When no parameters are given then the system will
// try to use reasonable defaults by looking up environment variables
// or, failing that, using hardwired constants
const char* dbName = "template1";
const char* dbName = "dbname=template1";
PgTransaction data(dbName);
// check to see that the backend connection was successfully made

View File

@ -9,7 +9,7 @@
#include <iostream.h>
#include <iomanip.h>
#include <libpq++.h>
#include <libpq++.H>
int main()
{
@ -19,7 +19,7 @@ int main()
// or, failing that, using hardwired constants.
// Create a cursor database query object.
// All queries using cursor will be performed through this object.
const char* dbName = "template1";
const char* dbName = "dbname=template1";
PgCursor cData(dbName, "myportal");
// check to see that the backend connection was successfully made

View File

@ -19,7 +19,7 @@ INSERT INTO TBL1 values (10);
*
*/
#include <iostream.h>
#include <libpq++.h>
#include <libpq++.H>
#include <stdlib.h>
main()
@ -27,7 +27,7 @@ main()
// Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation
// of this test program.
char* dbName = getenv("USER"); // change this to the name of your test database
char* dbName = "dbname=template1";
PgDatabase data(dbName);
// Check to see that the backend connection was successfully made

View File

@ -27,7 +27,7 @@ tuple 1: got
*
*/
#include <iostream.h>
#include <libpq++.h>
#include <libpq++.H>
#include <stdlib.h>
extern "C" {
#include "postgres.h" // for Postgres types
@ -39,7 +39,7 @@ main()
// Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation
// of this test program. Connect using cursor interface.
char* dbName = getenv("USER"); // change this to the name of your test database
char* dbName = "dbname=template1"; // change this to the name of your test database
PgCursor data(dbName, "mycursor");
// check to see that the backend connection was successfully made

View File

@ -5,7 +5,7 @@
*
*/
#include <iostream.h>
#include <libpq++.h>
#include <libpq++.H>
#include <stdlib.h>
main()
@ -13,7 +13,7 @@ main()
// Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation
// of this test program. Connect using transaction interface.
char* dbName = getenv("USER"); // change this to the name of your test database
char* dbName = "dbname=template1";
PgTransaction data(dbName);
// check to see that the backend connection was successfully made

View File

@ -7,12 +7,12 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlo.cc,v 1.3 1997/02/13 10:01:05 scrappy Exp $
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlo.cc,v 1.4 1999/05/23 01:04:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <iostream.h>
#include <libpq++.h>
#include <libpq++.H>
#include <stdlib.h>
int main(int argc, char **argv)

View File

@ -1,3 +1,4 @@
/*-------------------------------------------------------------------------
*
* libpq++.H
@ -12,9 +13,6 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
*
* $Id: libpq++.H,v 1.3 1996/11/12 11:42:27 bryanh Exp $
*
*-------------------------------------------------------------------------
*/
@ -24,156 +22,167 @@
#include <stdio.h>
#include <strings.h>
#include <string>
extern "C" {
#include "config.h"
#include "postgres.h"
#include "libpq-fe.h"
#include "fe-auth.h"
}
// ****************************************************************
//
// PGenv - the environment for setting up a connection to postgres
//
// ****************************************************************
class PGenv {
friend class PGconnection;
char* pgauth;
char* pghost;
char* pgport;
char* pgoption;
char* pgtty;
public:
PGenv(); // default ctor will use reasonable defaults
// will use environment variables PGHOST, PGPORT,
// PGOPTION, PGTTY
PGenv(char* auth, char* host, char* port, char* option, char* tty);
void setValues(char* auth, char* host, char* port, char* option, char* tty);
~PGenv();
};
static char rcsid[] = "$Id: libpq++.H,v 1.4 1999/05/23 01:03:58 momjian Exp $";
// ****************************************************************
//
// PGconnection - a connection made to a postgres backend
// PgConnection - a connection made to a postgres backend
//
// ****************************************************************
class PGconnection {
friend class PGdatabase;
friend class PGlobj;
PGenv* env;
PGconn* conn;
PGresult* result;
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();
char errorMessage[ERROR_MSG_LENGTH];
public:
PGconnection(); // use reasonable defaults
PGconnection(PGenv* env, char* dbName); // connect to the database with
// given environment and database name
ConnStatusType status();
char* errormessage() {return errorMessage;};
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
char* dbName() {return PQdb(conn);};
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();
};
ExecStatusType exec(char* query); // send a query to the backend
PGnotify* notifies() {exec(" "); return PQnotifies(conn);};
~PGconnection(); // close connection and clean up
// ****************************************************************
//
// PgDatabase - a class for accessing databases
//
// ****************************************************************
class PgDatabase : public PgConnection {
protected:
ConnStatusType connect(PGenv* env, char* dbName);
};
PgDatabase() : PgConnection() {} // Do not connect
// ****************************************************************
//
// PGdatabase - a class for accessing databases
//
// ****************************************************************
class PGdatabase : public PGconnection {
public:
PGdatabase() : PGconnection() {}; // use reasonable defaults
// connect to the database with
PGdatabase(PGenv* env, char* dbName) : PGconnection(env, dbName) {};
// connect to the database with conninfo
PgDatabase(const char *conninfo) : PgConnection(conninfo) {};
~PgDatabase() {}; // close connection and clean up
// query result access
int ntuples()
{return PQntuples(result);};
int nfields()
{return PQnfields(result);};
char* fieldname(int field_num)
{return PQfname(result, field_num);};
int fieldnum(char* field_name)
{return PQfnumber(result, field_name);};
Oid fieldtype(int field_num)
{return PQftype(result, field_num);};
Oid fieldtype(char* field_name)
{return PQftype(result, fieldnum(field_name));};
int2 fieldsize(int field_num)
{return PQfsize(result, field_num);};
int2 fieldsize(char* field_name)
{return PQfsize(result, fieldnum(field_name));};
char* getvalue(int tup_num, int field_num)
{return PQgetvalue(result, tup_num, field_num);};
char* getvalue(int tup_num, char* field_name)
{return PQgetvalue(result, tup_num, fieldnum(field_name));};
int getlength(int tup_num, int field_num)
{return PQgetlength(result, tup_num, field_num);};
int getlength(int tup_num, char* field_name)
{return PQgetlength(result, tup_num, fieldnum(field_name));};
void printtuples(FILE *out, int fillAlign, char *fieldSep,
int printHeader, int quiet)
{PQdisplayTuples(result, out, fillAlign, fieldSep, printHeader, quiet);};
int Tuples();
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 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)
{return PQgetline(conn, string, length);};
void putline(char* string)
{PQputline(conn, string);};
const char *OidStatus()
{
return PQoidStatus(result);
}
int endcopy()
{return PQendcopy(conn);};
~PGdatabase() {}; // close connection and clean up
int GetLine(char* string, int length);
void PutLine(const char* string);
const char *OidStatus();
int EndCopy();
};
// ****************************************************************
//
// PGlobj - a class for accessing Large Object in a database
// PGLargeObject - a class for accessing Large Object in a database
//
// ****************************************************************
class PGlobj : public PGconnection {
int fd;
Oid object;
class PgLargeObject : public PgConnection {
public:
PGlobj(); // use reasonable defaults and create large object
PGlobj(Oid lobjId); // use reasonable defaults and open large object
PGlobj(PGenv* env, char* dbName); // create large object
PGlobj(PGenv* env, char* dbName, Oid lobjId); // open large object
int read(char* buf, int len)
{return lo_read(conn, fd, buf, len);};
int write(char* buf, int len)
{return lo_write(conn, fd, buf, len);};
int lseek(int offset, int whence)
{return lo_lseek(conn, fd, offset, whence);};
int tell()
{return lo_tell(conn, fd);};
int unlink();
int import(char* filename);
int export(char* filename);
~PGlobj(); // close connection and clean up
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);
};
//
// these are the environment variables used for getting defaults
//
#define ENV_DEFAULT_AUTH "PGAUTH"
#define ENV_DEFAULT_DBASE "PGDATABASE"
#define ENV_DEFAULT_HOST "PGHOST"
#define ENV_DEFAULT_OPTION "PGOPTION"
#define ENV_DEFAULT_PORT "PGPORT"
#define ENV_DEFAULT_TTY "PGTTY"
// buffer size
#define BUFSIZE 1024
#endif /* LIBPQXX_H */

View File

@ -1,33 +0,0 @@
/*-------------------------------------------------------------------------
*
* libpq++.H
*
*
* DESCRIPTION
* C++ client interface to Postgres
* used for building front-end applications
*
* NOTES
* Currently under construction.
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
*
* $Id: libpq++.h,v 1.1 1997/02/13 10:00:25 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef LIBPQXX_H
#define LIBPQXX_H
#include "libpq++/pgenv.h"
#include "libpq++/pgconnection.h"
#include "libpq++/pgdatabase.h"
#include "libpq++/pgtransdb.h"
#include "libpq++/pgcursordb.h"
#include "libpq++/pglobject.h"
#endif // LIBPQXX_H

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);
}

View File

@ -11,6 +11,8 @@
* Currently under construction.
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pgconnection.h,v 1.2 1999/05/23 01:04:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -19,7 +21,7 @@
#define PGCONN_H
#include <stdio.h>
#include "pgenv.h"
#include <string>
extern "C" {
#include "libpq-fe.h"
@ -36,25 +38,21 @@ extern "C" {
// derived from this class to obtain the connection interface.
class PgConnection {
protected:
PgEnv pgEnv; // Current connection environment
PGconn* pgConn; // Connection Structures
PGresult* pgResult; // Query Result
string pgErrorMessage; // Error messages container
int pgCloseConnection; // Flag indicating whether the connection should be closed or not
public:
PgConnection(const char* dbName); // use reasonable defaults
PgConnection(const PgEnv& env, const char* dbName); // connect to the database with
// given environment and database name
virtual ~PgConnection(); // close connection and clean up
PgConnection(const char* conninfo); // use reasonable & environment defaults
~PgConnection(); // close connection and clean up
// Connection status and error messages
ConnStatusType Status();
int ConnectionBad() { return Status() == CONNECTION_BAD; }
const char* ErrorMessage() const { return pgErrorMessage.c_str(); }
int ConnectionBad();
const char* ErrorMessage();
// returns the database name of the connection
const char* DBName() const { return PQdb(pgConn); }
const char* DBName();
// Query Execution interface
ExecStatusType Exec(const char* query); // send a query to the backend
@ -63,13 +61,11 @@ public:
PGnotify* Notifies();
protected:
ConnStatusType Connect(const char* dbName);
void SetErrorMessage(const string&, int append = 0);
ConnStatusType Connect(const char* conninfo);
string IntToString(int);
protected:
PgConnection();
PgConnection(const PgConnection&);
};
#endif // PGCONN_H

View File

@ -9,13 +9,14 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.1 1997/02/13 10:00:30 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgcursordb.h"
static char rcsid[] = "$Id: pgcursordb.cc,v 1.2 1999/05/23 01:04:01 momjian Exp $";
// ****************************************************************
@ -24,13 +25,9 @@
//
// ****************************************************************
// Make a connection to the specified database with default environment
PgCursor::PgCursor(const char* dbName, const char* cursor)
: PgTransaction(dbName), pgCursor(cursor)
{}
// Make a connection to the specified database with the given environment
PgCursor::PgCursor(const PgEnv& env, const char* dbName, const char* cursor)
: PgTransaction(env, dbName), pgCursor(cursor)
// See PQconnectdb() for conninfo usage
PgCursor::PgCursor(const char* conninfo, const char* cursor)
: PgTransaction(conninfo), pgCursor(cursor)
{}
// Do not make a connection to the backend -- just query

View File

@ -12,6 +12,9 @@
*
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgcursordb.h,v 1.2 1999/05/23 01:04:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -21,6 +24,7 @@
#include "pgtransdb.h"
// ****************************************************************
//
// PgCursor - a class for querying databases using a cursor
@ -32,11 +36,10 @@
// operations, like fetch, forward, etc.
class PgCursor : public PgTransaction {
public:
PgCursor(const char* dbName, const char* cursor); // use reasonable defaults
PgCursor(const char* conninfo, const char* cursor); // use reasonable & environment defaults
// connect to the database with given environment and database name
PgCursor(const PgEnv& env, const char* dbName, const char* cursor);
PgCursor(const PgConnection&, const char* cursor);
virtual ~PgCursor(); // close connection and clean up
~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

View File

@ -0,0 +1,152 @@
/*-------------------------------------------------------------------------
*
* FILE
* pgdatabase.cpp
*
* DESCRIPTION
* implementation of the PgDatabase class.
* PgDatabase encapsulates some utility routines
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
*
*-------------------------------------------------------------------------
*/
#include "pgdatabase.h"
static char rcsid[] = "$Id: pgdatabase.cc,v 1.1 1999/05/23 01:04:01 momjian Exp $";
void PgDatabase::DisplayTuples(FILE *out = 0, int fillAlign = 1,
const char* fieldSep = "|",int printHeader = 1, int quiet = 0)
{
PQprintOpt po;
memset(&po,0,sizeof(po));
po.align = (pqbool)fillAlign;
po.fieldSep = (char *)fieldSep;
po.header = (pqbool)printHeader;
PQprint(out,pgResult,&po);
}
void PgDatabase::PrintTuples(FILE *out = 0, int printAttName = 1, int terseOutput = 0, int width = 0)
{
PQprintOpt po;
memset(&po,0,sizeof(po));
po.align = (pqbool)width;
if(terseOutput) po.fieldSep = strdup("|");
else po.fieldSep = "";
po.header = (pqbool)printAttName;
PQprint(out,pgResult,&po);
}
int PgDatabase::Tuples()
{
return PQntuples(pgResult);
}
int PgDatabase::Fields()
{
return PQnfields(pgResult);
}
const char* PgDatabase::FieldName(int field_num)
{
return PQfname(pgResult, field_num);
}
int PgDatabase::FieldNum(const char* field_name)
{
return PQfnumber(pgResult, field_name);
}
Oid PgDatabase::FieldType(int field_num)
{
return PQftype(pgResult, field_num);
}
Oid PgDatabase::FieldType(const char* field_name)
{
return PQftype(pgResult, FieldNum(field_name));
}
short PgDatabase::FieldSize(int field_num)
{
return PQfsize(pgResult, field_num);
}
short PgDatabase::FieldSize(const char* field_name)
{
return PQfsize(pgResult, FieldNum(field_name));
}
const char* PgDatabase::GetValue(int tup_num, int field_num)
{
return PQgetvalue(pgResult, tup_num, field_num);
}
const char* PgDatabase::GetValue(int tup_num, const char* field_name)
{
return PQgetvalue(pgResult, tup_num, FieldNum(field_name));
}
int PgDatabase::GetLength(int tup_num, int field_num)
{
return PQgetlength(pgResult, tup_num, field_num);
}
int PgDatabase::GetLength(int tup_num, const char* field_name)
{
return PQgetlength(pgResult, tup_num, FieldNum(field_name));
}
int PgDatabase::GetLine(char* string, int length)
{
return PQgetline(pgConn, string, length);
}
void PgDatabase::PutLine(const char* string)
{
PQputline(pgConn, string);
}
const char* PgDatabase::OidStatus()
{
return PQoidStatus(pgResult);
}
int PgDatabase::EndCopy()
{
return PQendcopy(pgConn);
}

View File

@ -12,6 +12,9 @@
*
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgdatabase.h,v 1.2 1999/05/23 01:04:01 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -31,52 +34,32 @@
// results are being received.
class PgDatabase : public PgConnection {
public:
PgDatabase(const char* dbName) : PgConnection(dbName) {} // use reasonable defaults
// connect to the database with given environment and database name
PgDatabase(const PgEnv& env, const char* dbName) : PgConnection(env, dbName) {}
PgDatabase(const PgConnection& conn) : PgConnection(conn) {pgCloseConnection = 0;}
~PgDatabase() {} // close connection and clean up
PgDatabase(const char* conninfo) : PgConnection(conninfo) {} // use reasonable defaults
~PgDatabase() {} ; // close connection and clean up
// query result access
int Tuples()
{ return PQntuples(pgResult); }
int Fields()
{ return PQnfields(pgResult); }
const char* FieldName(int field_num)
{ return PQfname(pgResult, field_num); }
int FieldNum(const char* field_name)
{ return PQfnumber(pgResult, field_name); }
Oid FieldType(int field_num)
{ return PQftype(pgResult, field_num); }
Oid FieldType(const char* field_name)
{ return PQftype(pgResult, FieldNum(field_name)); }
short FieldSize(int field_num)
{ return PQfsize(pgResult, field_num); }
short FieldSize(const char* field_name)
{ return PQfsize(pgResult, FieldNum(field_name)); }
const char* GetValue(int tup_num, int field_num)
{ return PQgetvalue(pgResult, tup_num, field_num); }
const char* GetValue(int tup_num, const char* field_name)
{ return PQgetvalue(pgResult, tup_num, FieldNum(field_name)); }
int GetLength(int tup_num, int field_num)
{ return PQgetlength(pgResult, tup_num, field_num); }
int GetLength(int tup_num, const char* field_name)
{ return PQgetlength(pgResult, tup_num, FieldNum(field_name)); }
void DisplayTuples(FILE *out = 0, int fillAlign = 1, const char* fieldSep = "|",
int printHeader = 1, int quiet = 0)
{ PQdisplayTuples(pgResult, (out ? out : stdout), fillAlign, fieldSep, printHeader, quiet); }
void PrintTuples(FILE *out = 0, int printAttName = 1, int terseOutput = 0, int width = 0)
{ PQprintTuples(pgResult, (out ? out : stdout), printAttName, terseOutput, width); }
int Tuples();
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 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)
{ return PQgetline(pgConn, string, length); }
void PutLine(const char* string)
{ PQputline(pgConn, string); }
const char* OidStatus()
{ return PQoidStatus(pgResult); }
int EndCopy()
{ return PQendcopy(pgConn); }
int GetLine(char* string, int length);
void PutLine(const char* string);
const char* OidStatus();
int EndCopy();
protected:
PgDatabase() : PgConnection() {} // Do not connect

View File

@ -1,84 +0,0 @@
/*-------------------------------------------------------------------------
*
* FILE
* PgEnv.cc
*
* DESCRIPTION
* PgEnv is the environment for setting up a connection to a
* postgres backend, captures the host, port, tty, options and
* authentication type.
*
* NOTES
* Currently under construction.
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgenv.cc,v 1.4 1999/05/10 15:27:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdlib.h>
#include "pgenv.h"
#define DefaultAuth DEFAULT_CLIENT_AUTHSVC
#define DefaultPort POSTPORT
// ****************************************************************
//
// PgEnv Implementation
//
// ****************************************************************
// Default constructor for PgEnv
// checks the environment variables
PgEnv::PgEnv()
{
SetValues(getenv(ENV_DEFAULT_AUTH), getenv(ENV_DEFAULT_HOST),
getenv(ENV_DEFAULT_PORT), getenv(ENV_DEFAULT_OPTION),
getenv(ENV_DEFAULT_TTY));
}
// constructor for given environment
PgEnv::PgEnv(const string& auth, const string& host, const string& port,
const string& option, const string& tty)
{
SetValues(auth, host, port, option, tty);
}
// allocate memory and set internal structures to match
// required environment
void PgEnv::SetValues(const string& auth, const string& host, const string& port,
const string& option, const string& tty)
{
Auth( auth );
Host( host );
Port( port );
Option( option );
TTY( tty );
}
// read a string from the environment and convert it to string
string PgEnv::getenv(const char* name)
{
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=" <<a.pgHost;
if(a.pgPort.length() !=0)s<<" port=" <<a.pgPort;
// deprecated: if(a.pgAuth.length()!=0)s<<" authtype="<<a.pgAuth;
if(a.pgOption.length()!=0)s<<" options="<<a.pgOption;
if(a.pgTty.length() !=0)s<<" tty=" <<a.pgTty;
s<<' ';
return s;
}

View File

@ -1,86 +0,0 @@
/*-------------------------------------------------------------------------
*
* pgenv.h
*
*
* DESCRIPTION
* Postgres Environment Class: manages and stores all the required
* connection variables.
*
* NOTES
* Currently under construction.
*
* Copyright (c) 1994, Regents of the University of California
*
*-------------------------------------------------------------------------
*/
#ifndef PGENV_H
#define PGENV_H
#include <string>
#include <iostream.h>
#ifdef __sun__
#ifndef __GNUC__
using namespace std;
#endif
#endif
//
// these are the environment variables used for getting defaults
//
#define ENV_DEFAULT_AUTH "PGAUTH"
#define ENV_DEFAULT_DBASE "PGDATABASE"
#define ENV_DEFAULT_HOST "PGHOST"
#define ENV_DEFAULT_OPTION "PGOPTION"
#define ENV_DEFAULT_PORT "PGPORT"
#define ENV_DEFAULT_TTY "PGTTY"
// ****************************************************************
//
// PgEnv - the environment for setting up a connection to postgres
//
// ****************************************************************
class PgEnv {
private:
string pgAuth;
string pgHost;
string pgPort;
string pgOption;
string pgTty;
public:
PgEnv(); // default ctor will use reasonable defaults
// will use environment variables PGHOST, PGPORT,
// PGOPTION, PGTTY
PgEnv(const string& auth, const string& host, const string& port,
const string& option, const string& tty);
// Access methods to all the environment variables
const char* Auth() { return pgAuth.c_str(); }
void Auth(const string& auth) { pgAuth = auth; }
const char* Host() { return pgHost.c_str(); }
void Host(const string& host) { pgHost = host; }
const char* Port() { return pgPort.c_str(); }
void Port(const string& port) { pgPort = port; }
const char* Option() { return pgOption.c_str(); }
void Option(const string& option) { pgOption = option; }
const char* TTY() { return pgTty.c_str(); }
void TTY(const string& tty) { pgTty = tty; }
void SetValues(const string& auth, const string& host, const string& port,
const string& option, const string& tty);
protected:
string getenv(const char*);
friend ostream& operator << (ostream &, const PgEnv&);
};
#endif // PGENV_H

View File

@ -9,8 +9,6 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.3 1997/02/13 10:00:34 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@ -21,7 +19,7 @@ extern "C" {
#include "pglobject.h"
static char rcsid[] = "$Id: pglobject.cc,v 1.4 1999/05/23 01:04:03 momjian Exp $";
// ****************************************************************
//
@ -30,8 +28,9 @@ extern "C" {
// ****************************************************************
// default constructor
// creates a large object in the default database
PgLargeObject::PgLargeObject(const char* dbName)
: PgConnection(dbName)
// See PQconnectdb() for conninfo usage
PgLargeObject::PgLargeObject(const char* conninfo)
: PgConnection(conninfo)
{
Init();
Create();
@ -40,33 +39,15 @@ PgLargeObject::PgLargeObject(const char* dbName)
// constructor
// open an existing large object in the default database
PgLargeObject::PgLargeObject(Oid lobjId, const char* dbName)
: PgConnection(dbName)
// See PQconnectdb() for conninfo usage
PgLargeObject::PgLargeObject(Oid lobjId, const char* conninfo)
: PgConnection(conninfo)
{
Init(lobjId);
if ( !pgObject )
Create();
Open();
}
// constructor
// create a large object in the given database
PgLargeObject::PgLargeObject(const PgEnv& env, const char* dbName)
: PgConnection(env, dbName)
{
Init();
Create();
Open();
}
// constructor
// open an existing large object in the given database
PgLargeObject::PgLargeObject(const PgEnv& env, const char* dbName, Oid lobjId)
: PgConnection(env, dbName)
{
Init(lobjId);
if ( !pgObject )
Create();
if ( !pgObject ) {
Create();
}
Open();
}
@ -93,7 +74,9 @@ void PgLargeObject::Create()
// Check for possible errors
if (!pgObject)
SetErrorMessage( "PgLargeObject: can't create large object" );
loStatus = "PgLargeObject: can't create large object" ;
else
loStatus = "PgLargeObject: created large object" ;
}
// PgLargeObject::open
@ -106,9 +89,9 @@ void PgLargeObject::Open()
// Check for possible errors
string objStr( IntToString(pgObject) );
if (pgFd < 0)
SetErrorMessage( "PgLargeObject: can't open large object " + objStr );
loStatus = "PgLargeObject: can't open large object " + objStr ;
else
SetErrorMessage( "PgLargeObject: created and opened large object " + objStr );
loStatus = "PgLargeObject: created and opened large object " + objStr ;
}
// PgLargeObject::unlink
@ -127,3 +110,53 @@ int PgLargeObject::Unlink()
// Return the status
return temp;
}
void PgLargeObject::Close()
{
if (pgFd >= 0) lo_close(pgConn, pgFd);
}
int PgLargeObject::Read(char* buf, int len)
{
return lo_read(pgConn, pgFd, buf, len);
}
int PgLargeObject::Write(const char* buf, int len)
{
return lo_write(pgConn, pgFd, (char*)buf, len);
}
int PgLargeObject::LSeek(int offset, int whence)
{
return lo_lseek(pgConn, pgFd, offset, whence);
}
int PgLargeObject::Tell()
{
return lo_tell(pgConn, pgFd);
}
Oid PgLargeObject::Import(const char* filename)
{
return pgObject = lo_import(pgConn, (char*)filename);
}
int PgLargeObject::Export(const char* filename)
{
return lo_export(pgConn, pgObject, (char*)filename);
}
string PgLargeObject::Status()
{
return loStatus;
}

View File

@ -9,8 +9,8 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.h,v 1.1 1997/02/13 10:00:35 scrappy Exp $
*
* $Id: pglobject.h,v 1.2 1999/05/23 01:04:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -33,32 +33,30 @@ class PgLargeObject : public PgConnection {
private:
int pgFd;
Oid pgObject;
string loStatus;
public:
PgLargeObject(const char* dbName = 0); // use reasonable defaults and create large object
PgLargeObject(Oid lobjId, const char* dbName = 0); // use reasonable defaults and open large object
PgLargeObject(const PgEnv& env, const char* dbName); // create large object
PgLargeObject(const PgEnv& env, const char* dbName, Oid lobjId); // open large object
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()
{ if (pgFd >= 0) lo_close(pgConn, pgFd); }
int Read(char* buf, int len)
{ return lo_read(pgConn, pgFd, buf, len); }
int Write(const char* buf, int len)
{ return lo_write(pgConn, pgFd, (char*)buf, len); }
int LSeek(int offset, int whence)
{ return lo_lseek(pgConn, pgFd, offset, whence); }
int Tell()
{ return lo_tell(pgConn, pgFd); }
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 Import(const char* filename) { return pgObject = lo_import(pgConn, (char*)filename); }
int Export(const char* filename) { return lo_export(pgConn, pgObject, (char*)filename); }
Oid LOid();
Oid Import(const char* filename);
int Export(const char* filename);
string Status();
private:
void Init(Oid lobjId = 0);
};
#endif // PGLOBJ_H
// sig 11's if the filename points to a binary file.

View File

@ -9,14 +9,13 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgtransdb.cc,v 1.1 1997/02/13 10:00:36 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgtransdb.h"
static char rcsid[] = "$Id: pgtransdb.cc,v 1.2 1999/05/23 01:04:03 momjian Exp $";
// ****************************************************************
//
@ -24,24 +23,9 @@
//
// ****************************************************************
// Make a connection to the specified database with default environment
PgTransaction::PgTransaction(const char* dbName)
: PgDatabase(dbName)
{
BeginTransaction();
}
// Make a connection to the specified database with the given environment
PgTransaction::PgTransaction(const PgEnv& env, const char* dbName)
: PgDatabase(env, dbName)
{
BeginTransaction();
}
// Do not make a connection to the backend -- just query
// Connection should not be closed after the object destructs since some
// other object is using the connection
PgTransaction::PgTransaction(const PgConnection& conn)
: PgDatabase(conn)
// See PQconnectdb() for conninfo usage.
PgTransaction::PgTransaction(const char* conninfo)
: PgDatabase(conninfo)
{
BeginTransaction();
}

View File

@ -12,6 +12,9 @@
*
* Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgtransdb.h,v 1.2 1999/05/23 01:04:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -20,7 +23,6 @@
#include "pgdatabase.h"
// ****************************************************************
//
// PgTransaction - a class for running transactions against databases
@ -31,11 +33,10 @@
// the object is destroyed.
class PgTransaction : public PgDatabase {
public:
PgTransaction(const char* dbName); // use reasonable defaults
PgTransaction(const char* conninfo); // use reasonable & environment defaults
// connect to the database with given environment and database name
PgTransaction(const PgEnv& env, const char* dbName);
PgTransaction(const PgConnection&);
virtual ~PgTransaction(); // close connection and clean up
~PgTransaction(); // close connection and clean up
protected:
ExecStatusType BeginTransaction();