From b14c99d8d6bdb3155fe54e6f24e8aac32a09ed81 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sun, 23 May 1999 01:04:07 +0000 Subject: [PATCH] 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. --- src/interfaces/libpq++/CHANGES | 33 ++++ src/interfaces/libpq++/Makefile.in | 20 +-- src/interfaces/libpq++/README | 33 ++-- src/interfaces/libpq++/TODO | 6 + src/interfaces/libpq++/dependencies | 7 +- src/interfaces/libpq++/examples/Makefile | 26 +-- src/interfaces/libpq++/examples/testlibpq0.cc | 6 +- src/interfaces/libpq++/examples/testlibpq1.cc | 4 +- src/interfaces/libpq++/examples/testlibpq2.cc | 4 +- src/interfaces/libpq++/examples/testlibpq3.cc | 4 +- src/interfaces/libpq++/examples/testlibpq4.cc | 4 +- src/interfaces/libpq++/examples/testlibpq5.cc | 4 +- src/interfaces/libpq++/examples/testlibpq6.cc | 4 +- src/interfaces/libpq++/examples/testlo.cc | 4 +- src/interfaces/libpq++/libpq++.H | 233 +++++++++++++------------- src/interfaces/libpq++/libpq++.h | 33 ---- src/interfaces/libpq++/pgconnection.cc | 106 ++++++------ src/interfaces/libpq++/pgconnection.h | 22 +-- src/interfaces/libpq++/pgcursordb.cc | 15 +- src/interfaces/libpq++/pgcursordb.h | 9 +- src/interfaces/libpq++/pgdatabase.cc | 152 +++++++++++++++++ src/interfaces/libpq++/pgdatabase.h | 67 +++----- src/interfaces/libpq++/pgenv.cc | 84 ---------- src/interfaces/libpq++/pgenv.h | 86 ---------- src/interfaces/libpq++/pglobject.cc | 97 +++++++---- src/interfaces/libpq++/pglobject.h | 34 ++-- src/interfaces/libpq++/pgtransdb.cc | 24 +-- src/interfaces/libpq++/pgtransdb.h | 9 +- 28 files changed, 549 insertions(+), 581 deletions(-) create mode 100644 src/interfaces/libpq++/CHANGES create mode 100644 src/interfaces/libpq++/TODO delete mode 100644 src/interfaces/libpq++/libpq++.h create mode 100644 src/interfaces/libpq++/pgdatabase.cc delete mode 100644 src/interfaces/libpq++/pgenv.cc delete mode 100644 src/interfaces/libpq++/pgenv.h diff --git a/src/interfaces/libpq++/CHANGES b/src/interfaces/libpq++/CHANGES new file mode 100644 index 0000000000..da473a61f5 --- /dev/null +++ b/src/interfaces/libpq++/CHANGES @@ -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 + + + + + + diff --git a/src/interfaces/libpq++/Makefile.in b/src/interfaces/libpq++/Makefile.in index 8c3ba2f004..09528e3937 100644 --- a/src/interfaces/libpq++/Makefile.in +++ b/src/interfaces/libpq++/Makefile.in @@ -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 diff --git a/src/interfaces/libpq++/README b/src/interfaces/libpq++/README index 1332b9633d..975bd54e79 100644 --- a/src/interfaces/libpq++/README +++ b/src/interfaces/libpq++/README @@ -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 diff --git a/src/interfaces/libpq++/TODO b/src/interfaces/libpq++/TODO new file mode 100644 index 0000000000..7ec2486647 --- /dev/null +++ b/src/interfaces/libpq++/TODO @@ -0,0 +1,6 @@ + +* Implement exceptions +* Binary Large Objects segfaulting +* Many other things I have yet to discover + + diff --git a/src/interfaces/libpq++/dependencies b/src/interfaces/libpq++/dependencies index 89633e1e87..426c34493e 100644 --- a/src/interfaces/libpq++/dependencies +++ b/src/interfaces/libpq++/dependencies @@ -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 diff --git a/src/interfaces/libpq++/examples/Makefile b/src/interfaces/libpq++/examples/Makefile index aff2fdd9bc..0e0c07cf5f 100644 --- a/src/interfaces/libpq++/examples/Makefile +++ b/src/interfaces/libpq++/examples/Makefile @@ -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) diff --git a/src/interfaces/libpq++/examples/testlibpq0.cc b/src/interfaces/libpq++/examples/testlibpq0.cc index 43f8e93d15..d432aab52f 100644 --- a/src/interfaces/libpq++/examples/testlibpq0.cc +++ b/src/interfaces/libpq++/examples/testlibpq0.cc @@ -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 -#include +#include 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; diff --git a/src/interfaces/libpq++/examples/testlibpq1.cc b/src/interfaces/libpq++/examples/testlibpq1.cc index ef63cf7077..53012f0cee 100644 --- a/src/interfaces/libpq++/examples/testlibpq1.cc +++ b/src/interfaces/libpq++/examples/testlibpq1.cc @@ -8,7 +8,7 @@ #include #include -#include +#include 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 diff --git a/src/interfaces/libpq++/examples/testlibpq2.cc b/src/interfaces/libpq++/examples/testlibpq2.cc index c6f6215bbc..4e0657f387 100644 --- a/src/interfaces/libpq++/examples/testlibpq2.cc +++ b/src/interfaces/libpq++/examples/testlibpq2.cc @@ -8,7 +8,7 @@ #include #include -#include +#include 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 diff --git a/src/interfaces/libpq++/examples/testlibpq3.cc b/src/interfaces/libpq++/examples/testlibpq3.cc index 3c4e6ec429..924c0c565c 100644 --- a/src/interfaces/libpq++/examples/testlibpq3.cc +++ b/src/interfaces/libpq++/examples/testlibpq3.cc @@ -9,7 +9,7 @@ #include #include -#include +#include 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 diff --git a/src/interfaces/libpq++/examples/testlibpq4.cc b/src/interfaces/libpq++/examples/testlibpq4.cc index a1b21d33a9..7803f338c9 100644 --- a/src/interfaces/libpq++/examples/testlibpq4.cc +++ b/src/interfaces/libpq++/examples/testlibpq4.cc @@ -19,7 +19,7 @@ INSERT INTO TBL1 values (10); * */ #include -#include +#include #include 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 diff --git a/src/interfaces/libpq++/examples/testlibpq5.cc b/src/interfaces/libpq++/examples/testlibpq5.cc index 878499baf4..52aa37cec4 100644 --- a/src/interfaces/libpq++/examples/testlibpq5.cc +++ b/src/interfaces/libpq++/examples/testlibpq5.cc @@ -27,7 +27,7 @@ tuple 1: got * */ #include -#include +#include #include 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 diff --git a/src/interfaces/libpq++/examples/testlibpq6.cc b/src/interfaces/libpq++/examples/testlibpq6.cc index 57be9c3fb0..1df83c9bf6 100644 --- a/src/interfaces/libpq++/examples/testlibpq6.cc +++ b/src/interfaces/libpq++/examples/testlibpq6.cc @@ -5,7 +5,7 @@ * */ #include -#include +#include #include 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 diff --git a/src/interfaces/libpq++/examples/testlo.cc b/src/interfaces/libpq++/examples/testlo.cc index df1dc6c360..dbd3fc1393 100644 --- a/src/interfaces/libpq++/examples/testlo.cc +++ b/src/interfaces/libpq++/examples/testlo.cc @@ -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 -#include +#include #include int main(int argc, char **argv) diff --git a/src/interfaces/libpq++/libpq++.H b/src/interfaces/libpq++/libpq++.H index 98581e7709..898a146aa3 100644 --- a/src/interfaces/libpq++/libpq++.H +++ b/src/interfaces/libpq++/libpq++.H @@ -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 #include +#include extern "C" { #include "config.h" #include "postgres.h" #include "libpq-fe.h" -#include "fe-auth.h" } +static char rcsid[] = "$Id: libpq++.H,v 1.4 1999/05/23 01:03:58 momjian Exp $"; + + // **************************************************************** // -// PGenv - the environment for setting up a connection to postgres +// PgConnection - a connection made to a postgres backend // // **************************************************************** -class PGenv { - friend class PGconnection; - char* pgauth; - char* pghost; - char* pgport; - char* pgoption; - char* pgtty; +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: - 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(); + 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(); }; // **************************************************************** // -// PGconnection - a connection made to a postgres backend +// PgDatabase - a class for accessing databases // // **************************************************************** -class PGconnection { - friend class PGdatabase; - friend class PGlobj; - PGenv* env; - PGconn* conn; - PGresult* result; - - char errorMessage[ERROR_MSG_LENGTH]; +class PgDatabase : public PgConnection { +protected: + PgDatabase() : PgConnection() {} // Do not connect + 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;}; - - // returns the database name of the connection - char* dbName() {return PQdb(conn);}; + // connect to the database with conninfo + PgDatabase(const char *conninfo) : PgConnection(conninfo) {}; + ~PgDatabase() {}; // close connection and clean up + // query result access + 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) ; - ExecStatusType exec(char* query); // send a query to the backend - PGnotify* notifies() {exec(" "); return PQnotifies(conn);}; - ~PGconnection(); // close connection and clean up -protected: - ConnStatusType connect(PGenv* env, char* dbName); + // copy command related access + int GetLine(char* string, int length); + void PutLine(const char* string); + const char *OidStatus(); + int EndCopy(); }; + + // **************************************************************** // -// PGdatabase - a class for accessing databases +// PGLargeObject - a class for accessing Large Object in a database // // **************************************************************** -class PGdatabase : public PGconnection { +class PgLargeObject : public PgConnection { public: - PGdatabase() : PGconnection() {}; // use reasonable defaults - // connect to the database with - PGdatabase(PGenv* env, char* dbName) : PGconnection(env, dbName) {}; - // 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);}; - // 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 + 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(); }; + // **************************************************************** // -// PGlobj - a class for accessing Large Object in a database +// PgTransaction - a class for running transactions against databases // // **************************************************************** -class PGlobj : public PGconnection { - int fd; - Oid object; +class PgTransaction : public PgDatabase { +protected: + ExecStatusType BeginTransaction(); + ExecStatusType EndTransaction(); + PgTransaction() : PgDatabase() {} // Do not connect + 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 + 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 + }; + +// **************************************************************** // -// these are the environment variables used for getting defaults +// 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); +}; + -#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 */ + + diff --git a/src/interfaces/libpq++/libpq++.h b/src/interfaces/libpq++/libpq++.h deleted file mode 100644 index ee257bf6f7..0000000000 --- a/src/interfaces/libpq++/libpq++.h +++ /dev/null @@ -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 - diff --git a/src/interfaces/libpq++/pgconnection.cc b/src/interfaces/libpq++/pgconnection.cc index 73b198adf3..838b410941 100644 --- a/src/interfaces/libpq++/pgconnection.cc +++ b/src/interfaces/libpq++/pgconnection.cc @@ -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 #include -#include #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 - - // Connect to the database - ostrstream conninfo; - conninfo << "dbname="< -#include "pgenv.h" +#include 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 diff --git a/src/interfaces/libpq++/pgcursordb.cc b/src/interfaces/libpq++/pgcursordb.cc index 0589996940..50585f88dc 100644 --- a/src/interfaces/libpq++/pgcursordb.cc +++ b/src/interfaces/libpq++/pgcursordb.cc @@ -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 diff --git a/src/interfaces/libpq++/pgcursordb.h b/src/interfaces/libpq++/pgcursordb.h index de1adafb2f..1d8bad7f81 100644 --- a/src/interfaces/libpq++/pgcursordb.h +++ b/src/interfaces/libpq++/pgcursordb.h @@ -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 diff --git a/src/interfaces/libpq++/pgdatabase.cc b/src/interfaces/libpq++/pgdatabase.cc new file mode 100644 index 0000000000..10fcdd0e92 --- /dev/null +++ b/src/interfaces/libpq++/pgdatabase.cc @@ -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); +} + + diff --git a/src/interfaces/libpq++/pgdatabase.h b/src/interfaces/libpq++/pgdatabase.h index c3c904234c..d529f5bae2 100644 --- a/src/interfaces/libpq++/pgdatabase.h +++ b/src/interfaces/libpq++/pgdatabase.h @@ -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 diff --git a/src/interfaces/libpq++/pgenv.cc b/src/interfaces/libpq++/pgenv.cc deleted file mode 100644 index b7edbd12fe..0000000000 --- a/src/interfaces/libpq++/pgenv.cc +++ /dev/null @@ -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 -#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=" <= 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; +} + diff --git a/src/interfaces/libpq++/pglobject.h b/src/interfaces/libpq++/pglobject.h index 9fcd3449a2..7d7c160583 100644 --- a/src/interfaces/libpq++/pglobject.h +++ b/src/interfaces/libpq++/pglobject.h @@ -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. diff --git a/src/interfaces/libpq++/pgtransdb.cc b/src/interfaces/libpq++/pgtransdb.cc index cef16a2004..6ad2cf3cc1 100644 --- a/src/interfaces/libpq++/pgtransdb.cc +++ b/src/interfaces/libpq++/pgtransdb.cc @@ -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(); } diff --git a/src/interfaces/libpq++/pgtransdb.h b/src/interfaces/libpq++/pgtransdb.h index 4bce4b1e7b..80f17617e5 100644 --- a/src/interfaces/libpq++/pgtransdb.h +++ b/src/interfaces/libpq++/pgtransdb.h @@ -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(); -- 2.11.0