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:
parent
795f6ca66a
commit
b14c99d8d6
33
src/interfaces/libpq++/CHANGES
Normal file
33
src/interfaces/libpq++/CHANGES
Normal 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
|||||||
# Copyright (c) 1994, Regents of the University of California
|
# Copyright (c) 1994, Regents of the University of California
|
||||||
#
|
#
|
||||||
# IDENTIFICATION
|
# 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++
|
NAME= pq++
|
||||||
SO_MAJOR_VERSION= 2
|
SO_MAJOR_VERSION= 3
|
||||||
SO_MINOR_VERSION= 0
|
SO_MINOR_VERSION= 0
|
||||||
|
|
||||||
SRCDIR= @top_srcdir@
|
SRCDIR= @top_srcdir@
|
||||||
@ -42,20 +42,16 @@ ifdef KRBVERS
|
|||||||
CXXFLAGS+= $(KRBFLAGS)
|
CXXFLAGS+= $(KRBFLAGS)
|
||||||
endif
|
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
|
SHLIB_LINK= -L../libpq -lpq
|
||||||
endif
|
|
||||||
|
|
||||||
# Shared library stuff, also default 'all' target
|
# Shared library stuff, also default 'all' target
|
||||||
include $(SRCDIR)/Makefile.shlib
|
include $(SRCDIR)/Makefile.shlib
|
||||||
|
|
||||||
|
|
||||||
# Pull shared-lib CFLAGS into CXXFLAGS
|
# Pull shared-lib CFLAGS into CXXFLAGS
|
||||||
CXXFLAGS+= $(CFLAGS)
|
CXXFLAGS+= $(CFLAGS) -Wno-unused
|
||||||
|
|
||||||
|
|
||||||
.PHONY: examples
|
.PHONY: examples
|
||||||
@ -68,9 +64,8 @@ install: install-headers install-lib $(install-shlib-dep)
|
|||||||
|
|
||||||
LIBPGXXDIR = libpq++
|
LIBPGXXDIR = libpq++
|
||||||
LIBPGXXHEADERDIR = $(HEADERDIR)/$(LIBPGXXDIR)
|
LIBPGXXHEADERDIR = $(HEADERDIR)/$(LIBPGXXDIR)
|
||||||
MAINHEADER = libpq++.h
|
MAINHEADER = libpq++.H
|
||||||
LIBPGXXHEADERS = pgenv.h \
|
LIBPGXXHEADERS = pgconnection.h \
|
||||||
pgconnection.h \
|
|
||||||
pgdatabase.h \
|
pgdatabase.h \
|
||||||
pgtransdb.h \
|
pgtransdb.h \
|
||||||
pgcursordb.h \
|
pgcursordb.h \
|
||||||
@ -91,9 +86,6 @@ beforeinstall-headers:
|
|||||||
clean:
|
clean:
|
||||||
rm -f libpq++.a $(shlib) $(OBJS)
|
rm -f libpq++.a $(shlib) $(OBJS)
|
||||||
$(MAKE) -C examples clean
|
$(MAKE) -C examples clean
|
||||||
ifeq ($(PORTNAME), win)
|
|
||||||
rm -f pq++.def
|
|
||||||
endif
|
|
||||||
|
|
||||||
dep depend:
|
dep depend:
|
||||||
$(CXX) -MM $(CXXFLAGS) *.cc >depend
|
$(CXX) -MM $(CXXFLAGS) *.cc >depend
|
||||||
|
@ -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
|
Based on the original work by William Wanders (wwanders@sci.kun.nl)
|
||||||
(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
|
The API provided herein is subject to change in later versions of
|
||||||
people who would like to use C++ to build frontend applications to
|
PostgreSQL.
|
||||||
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/
|
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
|
|
||||||
|
6
src/interfaces/libpq++/TODO
Normal file
6
src/interfaces/libpq++/TODO
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
* Implement exceptions
|
||||||
|
* Binary Large Objects segfaulting
|
||||||
|
* Many other things I have yet to discover
|
||||||
|
|
||||||
|
|
@ -2,13 +2,11 @@
|
|||||||
# Dependencies for libpq++ C++ library for Postgres SQL
|
# Dependencies for libpq++ C++ library for Postgres SQL
|
||||||
#
|
#
|
||||||
# Author: Leo Shuster (lsh@lubrizol.com)
|
# 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.o :: pgconnection.cc \
|
||||||
pgconnection.h \
|
pgconnection.h \
|
||||||
pgenv.h \
|
|
||||||
$(LIBPQDIR)/libpq-fe.h \
|
$(LIBPQDIR)/libpq-fe.h \
|
||||||
$(LIBPQDIR)/fe-auth.h
|
$(LIBPQDIR)/fe-auth.h
|
||||||
|
|
||||||
@ -16,7 +14,6 @@ pgtransdb.o :: pgtransdb.cc \
|
|||||||
pgtransdb.h \
|
pgtransdb.h \
|
||||||
pgdatabase.h \
|
pgdatabase.h \
|
||||||
pgconnection.h \
|
pgconnection.h \
|
||||||
pgenv.h \
|
|
||||||
$(LIBPQDIR)/libpq-fe.h \
|
$(LIBPQDIR)/libpq-fe.h \
|
||||||
$(LIBPQDIR)/fe-auth.h
|
$(LIBPQDIR)/fe-auth.h
|
||||||
|
|
||||||
@ -24,13 +21,11 @@ pgcursordb.o :: pgcursordb.cc \
|
|||||||
pgcursordb.h \
|
pgcursordb.h \
|
||||||
pgdatabase.h \
|
pgdatabase.h \
|
||||||
pgconnection.h \
|
pgconnection.h \
|
||||||
pgenv.h \
|
|
||||||
$(LIBPQDIR)/libpq-fe.h \
|
$(LIBPQDIR)/libpq-fe.h \
|
||||||
$(LIBPQDIR)/fe-auth.h
|
$(LIBPQDIR)/fe-auth.h
|
||||||
|
|
||||||
pglobject.o :: pglobject.cc \
|
pglobject.o :: pglobject.cc \
|
||||||
pglobject.h \
|
pglobject.h \
|
||||||
pgconnection.h \
|
pgconnection.h \
|
||||||
pgenv.h \
|
|
||||||
$(LIBPQDIR)/libpq-fe.h \
|
$(LIBPQDIR)/libpq-fe.h \
|
||||||
$(LIBPQHEADERDIR)/libpq-fs.h
|
$(LIBPQHEADERDIR)/libpq-fs.h
|
||||||
|
@ -2,26 +2,23 @@
|
|||||||
# Makefile for example programs
|
# Makefile for example programs
|
||||||
#
|
#
|
||||||
|
|
||||||
SRCDIR= ../../..
|
|
||||||
include ../../../Makefile.global
|
|
||||||
|
|
||||||
LIBNAME= libpq++
|
LIBNAME= libpq++
|
||||||
|
HEADERDIR= /usr/local/pgsql/include
|
||||||
|
LIBPQDIR= /usr/local/pgsql/lib
|
||||||
|
|
||||||
|
|
||||||
# We have to override -Werror, which makes warnings, fatal, because we
|
# We have to override -Werror, which makes warnings, fatal, because we
|
||||||
# inevitably get the warning, "abstract declarator used as declaration"
|
# 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.
|
# 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)
|
CXXFLAGS+= $(INCLUDE_OPT)
|
||||||
|
|
||||||
LDFLAGS+= -L.. -lpq++ -L$(LIBPQDIR) -lpq
|
LDFLAGS+= -L$(LIBPQDIR) -lpq++
|
||||||
|
|
||||||
#
|
#
|
||||||
# And where libpq goes, so goes the authentication stuff...
|
# And where libpq goes, so goes the authentication stuff...
|
||||||
@ -34,17 +31,12 @@ endif
|
|||||||
PROGS= testlibpq0 testlibpq1 testlibpq2 testlibpq3 \
|
PROGS= testlibpq0 testlibpq1 testlibpq2 testlibpq3 \
|
||||||
testlibpq4 testlibpq5 testlibpq6 testlo
|
testlibpq4 testlibpq5 testlibpq6 testlo
|
||||||
|
|
||||||
all: submake $(PROGS)
|
all: $(PROGS)
|
||||||
|
|
||||||
$(PROGS): % : %.cc ../$(LIBNAME).a
|
$(PROGS): % : %.cc
|
||||||
$(CXX) $(CXXFLAGS) -o $@ $@.cc $(LDFLAGS)
|
$(CXX) $(CXXFLAGS) -o $@ $@.cc $(LDFLAGS)
|
||||||
|
|
||||||
.PHONY: submake
|
.PHONY: submake
|
||||||
submake:
|
|
||||||
$(MAKE) -C.. $(LIBNAME).a
|
|
||||||
|
|
||||||
../$(LIBNAME).a:
|
|
||||||
$(MAKE) -C.. $(LIBNAME).a
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(PROGS)
|
rm -f $(PROGS)
|
||||||
|
@ -9,18 +9,18 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 <iostream.h>
|
||||||
#include <libpq++.h>
|
#include <libpq++.H>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Open the connection to the database and make sure it's OK
|
// Open the connection to the database and make sure it's OK
|
||||||
PgDatabase data("template1");
|
PgDatabase data("dbname=template1");
|
||||||
if ( data.ConnectionBad() ) {
|
if ( data.ConnectionBad() ) {
|
||||||
cout << "Connection was unsuccessful..." << endl
|
cout << "Connection was unsuccessful..." << endl
|
||||||
<< "Error message returned: " << data.ErrorMessage() << endl;
|
<< "Error message returned: " << data.ErrorMessage() << endl;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include <iostream.h>
|
#include <iostream.h>
|
||||||
#include <iomanip.h>
|
#include <iomanip.h>
|
||||||
#include <libpq++.h>
|
#include <libpq++.H>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -16,7 +16,7 @@ int main()
|
|||||||
// When no parameters are given then the system will
|
// When no parameters are given then the system will
|
||||||
// try to use reasonable defaults by looking up environment variables
|
// try to use reasonable defaults by looking up environment variables
|
||||||
// or, failing that, using hardwired constants
|
// or, failing that, using hardwired constants
|
||||||
const char* dbName = "template1";
|
const char* dbName = "dbname=template1";
|
||||||
PgDatabase data(dbName);
|
PgDatabase data(dbName);
|
||||||
|
|
||||||
// check to see that the backend connection was successfully made
|
// check to see that the backend connection was successfully made
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include <iostream.h>
|
#include <iostream.h>
|
||||||
#include <iomanip.h>
|
#include <iomanip.h>
|
||||||
#include <libpq++.h>
|
#include <libpq++.H>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -16,7 +16,7 @@ int main()
|
|||||||
// When no parameters are given then the system will
|
// When no parameters are given then the system will
|
||||||
// try to use reasonable defaults by looking up environment variables
|
// try to use reasonable defaults by looking up environment variables
|
||||||
// or, failing that, using hardwired constants
|
// or, failing that, using hardwired constants
|
||||||
const char* dbName = "template1";
|
const char* dbName = "dbname=template1";
|
||||||
PgTransaction data(dbName);
|
PgTransaction data(dbName);
|
||||||
|
|
||||||
// check to see that the backend connection was successfully made
|
// check to see that the backend connection was successfully made
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include <iostream.h>
|
#include <iostream.h>
|
||||||
#include <iomanip.h>
|
#include <iomanip.h>
|
||||||
#include <libpq++.h>
|
#include <libpq++.H>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -19,7 +19,7 @@ int main()
|
|||||||
// or, failing that, using hardwired constants.
|
// or, failing that, using hardwired constants.
|
||||||
// Create a cursor database query object.
|
// Create a cursor database query object.
|
||||||
// All queries using cursor will be performed through this object.
|
// All queries using cursor will be performed through this object.
|
||||||
const char* dbName = "template1";
|
const char* dbName = "dbname=template1";
|
||||||
PgCursor cData(dbName, "myportal");
|
PgCursor cData(dbName, "myportal");
|
||||||
|
|
||||||
// check to see that the backend connection was successfully made
|
// check to see that the backend connection was successfully made
|
||||||
|
@ -19,7 +19,7 @@ INSERT INTO TBL1 values (10);
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <iostream.h>
|
#include <iostream.h>
|
||||||
#include <libpq++.h>
|
#include <libpq++.H>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@ -27,7 +27,7 @@ main()
|
|||||||
// Begin, by connecting to the backend using hardwired constants
|
// Begin, by connecting to the backend using hardwired constants
|
||||||
// and a test database created by the user prior to the invokation
|
// and a test database created by the user prior to the invokation
|
||||||
// of this test program.
|
// of this test program.
|
||||||
char* dbName = getenv("USER"); // change this to the name of your test database
|
char* dbName = "dbname=template1";
|
||||||
PgDatabase data(dbName);
|
PgDatabase data(dbName);
|
||||||
|
|
||||||
// Check to see that the backend connection was successfully made
|
// Check to see that the backend connection was successfully made
|
||||||
|
@ -27,7 +27,7 @@ tuple 1: got
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <iostream.h>
|
#include <iostream.h>
|
||||||
#include <libpq++.h>
|
#include <libpq++.H>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "postgres.h" // for Postgres types
|
#include "postgres.h" // for Postgres types
|
||||||
@ -39,7 +39,7 @@ main()
|
|||||||
// Begin, by connecting to the backend using hardwired constants
|
// Begin, by connecting to the backend using hardwired constants
|
||||||
// and a test database created by the user prior to the invokation
|
// and a test database created by the user prior to the invokation
|
||||||
// of this test program. Connect using cursor interface.
|
// 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");
|
PgCursor data(dbName, "mycursor");
|
||||||
|
|
||||||
// check to see that the backend connection was successfully made
|
// check to see that the backend connection was successfully made
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <iostream.h>
|
#include <iostream.h>
|
||||||
#include <libpq++.h>
|
#include <libpq++.H>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@ -13,7 +13,7 @@ main()
|
|||||||
// Begin, by connecting to the backend using hardwired constants
|
// Begin, by connecting to the backend using hardwired constants
|
||||||
// and a test database created by the user prior to the invokation
|
// and a test database created by the user prior to the invokation
|
||||||
// of this test program. Connect using transaction interface.
|
// 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);
|
PgTransaction data(dbName);
|
||||||
|
|
||||||
// check to see that the backend connection was successfully made
|
// check to see that the backend connection was successfully made
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 <iostream.h>
|
||||||
#include <libpq++.h>
|
#include <libpq++.H>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* libpq++.H
|
* libpq++.H
|
||||||
@ -12,9 +13,6 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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 <stdio.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "libpq-fe.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
|
|
||||||
//
|
|
||||||
// ****************************************************************
|
|
||||||
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();
|
|
||||||
};
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
// PGconnection - a connection made to a postgres backend
|
// PgConnection - a connection made to a postgres backend
|
||||||
//
|
//
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
class PGconnection {
|
class PgConnection {
|
||||||
friend class PGdatabase;
|
protected:
|
||||||
friend class PGlobj;
|
PGconn* pgConn; // Connection Structures
|
||||||
PGenv* env;
|
PGresult* pgResult; // Query Result
|
||||||
PGconn* conn;
|
int pgCloseConnection; // Flag indicating whether the connection should be closed
|
||||||
PGresult* result;
|
ConnStatusType Connect(const char* conninfo);
|
||||||
|
string IntToString(int);
|
||||||
|
PgConnection();
|
||||||
|
|
||||||
char errorMessage[ERROR_MSG_LENGTH];
|
|
||||||
public:
|
public:
|
||||||
PGconnection(); // use reasonable defaults
|
PgConnection(const char* conninfo); // use reasonable and environment defaults
|
||||||
PGconnection(PGenv* env, char* dbName); // connect to the database with
|
~PgConnection(); // close connection and clean up
|
||||||
// given environment and database name
|
|
||||||
ConnStatusType status();
|
ConnStatusType Status();
|
||||||
char* errormessage() {return errorMessage;};
|
int ConnectionBad();
|
||||||
|
const char* ErrorMessage();
|
||||||
|
|
||||||
// returns the database name of the connection
|
// 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:
|
protected:
|
||||||
ConnStatusType connect(PGenv* env, char* dbName);
|
PgDatabase() : PgConnection() {} // Do not connect
|
||||||
};
|
|
||||||
|
|
||||||
// ****************************************************************
|
|
||||||
//
|
|
||||||
// PGdatabase - a class for accessing databases
|
|
||||||
//
|
|
||||||
// ****************************************************************
|
|
||||||
class PGdatabase : public PGconnection {
|
|
||||||
public:
|
public:
|
||||||
PGdatabase() : PGconnection() {}; // use reasonable defaults
|
// connect to the database with conninfo
|
||||||
// connect to the database with
|
PgDatabase(const char *conninfo) : PgConnection(conninfo) {};
|
||||||
PGdatabase(PGenv* env, char* dbName) : PGconnection(env, dbName) {};
|
~PgDatabase() {}; // close connection and clean up
|
||||||
// query result access
|
// query result access
|
||||||
int ntuples()
|
int Tuples();
|
||||||
{return PQntuples(result);};
|
int Fields();
|
||||||
int nfields()
|
const char* FieldName(int field_num);
|
||||||
{return PQnfields(result);};
|
int FieldNum(const char *field_name);
|
||||||
char* fieldname(int field_num)
|
Oid FieldType(int field_num);
|
||||||
{return PQfname(result, field_num);};
|
Oid FieldType(const char *field_name);
|
||||||
int fieldnum(char* field_name)
|
short FieldSize(int field_num);
|
||||||
{return PQfnumber(result, field_name);};
|
short FieldSize(const char *field_name);
|
||||||
Oid fieldtype(int field_num)
|
const char* GetValue(int tup_num, int field_num);
|
||||||
{return PQftype(result, field_num);};
|
const char* GetValue(int tup_num, const char *field_name);
|
||||||
Oid fieldtype(char* field_name)
|
int GetLength(int tup_num, int field_num);
|
||||||
{return PQftype(result, fieldnum(field_name));};
|
int GetLength(int tup_num, const char* field_name);
|
||||||
int2 fieldsize(int field_num)
|
void DisplayTuples(FILE *out = 0, int fillAlign = 1,
|
||||||
{return PQfsize(result, field_num);};
|
const char* fieldSep = "|",int printHeader = 1, int quiet = 0) ;
|
||||||
int2 fieldsize(char* field_name)
|
void PrintTuples(FILE *out = 0, int printAttName = 1,
|
||||||
{return PQfsize(result, fieldnum(field_name));};
|
int terseOutput = 0, int width = 0) ;
|
||||||
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
|
// copy command related access
|
||||||
int getline(char* string, int length)
|
int GetLine(char* string, int length);
|
||||||
{return PQgetline(conn, string, length);};
|
void PutLine(const char* string);
|
||||||
void putline(char* string)
|
const char *OidStatus();
|
||||||
{PQputline(conn, string);};
|
int EndCopy();
|
||||||
const char *OidStatus()
|
|
||||||
{
|
|
||||||
return PQoidStatus(result);
|
|
||||||
}
|
|
||||||
int endcopy()
|
|
||||||
{return PQendcopy(conn);};
|
|
||||||
~PGdatabase() {}; // close connection and clean up
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
// PGlobj - a class for accessing Large Object in a database
|
// PGLargeObject - a class for accessing Large Object in a database
|
||||||
//
|
//
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
class PGlobj : public PGconnection {
|
class PgLargeObject : public PgConnection {
|
||||||
int fd;
|
|
||||||
Oid object;
|
|
||||||
public:
|
public:
|
||||||
PGlobj(); // use reasonable defaults and create large object
|
PgLargeObject(const char* conninfo = 0); // use reasonable defaults and create large object
|
||||||
PGlobj(Oid lobjId); // use reasonable defaults and open large object
|
PgLargeObject(Oid lobjId, const char* conninfo = 0); // use reasonable defaults and open large object
|
||||||
PGlobj(PGenv* env, char* dbName); // create large object
|
~PgLargeObject(); // close connection and clean up
|
||||||
PGlobj(PGenv* env, char* dbName, Oid lobjId); // open large object
|
|
||||||
int read(char* buf, int len)
|
void Create();
|
||||||
{return lo_read(conn, fd, buf, len);};
|
void Open();
|
||||||
int write(char* buf, int len)
|
void Close();
|
||||||
{return lo_write(conn, fd, buf, len);};
|
int Read(char* buf, int len);
|
||||||
int lseek(int offset, int whence)
|
int Write(const char* buf, int len);
|
||||||
{return lo_lseek(conn, fd, offset, whence);};
|
int Lseek(int offset, int whence);
|
||||||
int tell()
|
int Tell();
|
||||||
{return lo_tell(conn, fd);};
|
int Unlink();
|
||||||
int unlink();
|
Oid LOid();
|
||||||
int import(char* filename);
|
Oid Import(const char* filename);
|
||||||
int export(char* filename);
|
int Export(const char* filename);
|
||||||
~PGlobj(); // close connection and clean up
|
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
|
// buffer size
|
||||||
#define BUFSIZE 1024
|
#define BUFSIZE 1024
|
||||||
|
|
||||||
#endif /* LIBPQXX_H */
|
#endif /* LIBPQXX_H */
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
|
||||||
|
|
@ -9,21 +9,19 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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 <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strstream.h>
|
|
||||||
#include "pgconnection.h"
|
#include "pgconnection.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "fe-auth.h"
|
#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)
|
: 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
|
// 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)
|
: 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 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
|
// destructor - closes down the connection and cleanup
|
||||||
PgConnection::~PgConnection()
|
PgConnection::~PgConnection()
|
||||||
@ -74,39 +57,37 @@ PgConnection::~PgConnection()
|
|||||||
// This feature will most probably be used by the derived classes that
|
// This feature will most probably be used by the derived classes that
|
||||||
// need not close the connection after they are destructed.
|
// need not close the connection after they are destructed.
|
||||||
if ( pgCloseConnection ) {
|
if ( pgCloseConnection ) {
|
||||||
if (pgResult) PQclear(pgResult);
|
if(pgResult) PQclear(pgResult);
|
||||||
if (pgConn) PQfinish(pgConn);
|
if(pgConn) PQfinish(pgConn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PgConnection::connect
|
// PgConnection::connect
|
||||||
// establish a connection to a backend
|
// establish a connection to a backend
|
||||||
ConnStatusType PgConnection::Connect(const char* dbName)
|
ConnStatusType PgConnection::Connect(const char* conninfo)
|
||||||
{
|
{
|
||||||
// Turn the trace on
|
ConnStatusType cst;
|
||||||
#if defined(DEBUG)
|
// Turn the trace on
|
||||||
FILE *debug = fopen("/tmp/trace.out","w");
|
#if defined(DEBUG)
|
||||||
PQtrace(pgConn, debug);
|
FILE *debug = fopen("/tmp/trace.out","w");
|
||||||
#endif
|
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
|
return cst;
|
||||||
ostrstream conninfo;
|
|
||||||
conninfo << "dbname="<<dbName;
|
|
||||||
conninfo << pgEnv;
|
|
||||||
pgConn=PQconnectdb(conninfo.str());
|
|
||||||
conninfo.freeze(0);
|
|
||||||
|
|
||||||
if(ConnectionBad()) {
|
|
||||||
SetErrorMessage( PQerrorMessage(pgConn) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return Status();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PgConnection::status -- return connection or result status
|
// PgConnection::status -- return connection or result status
|
||||||
ConnStatusType PgConnection::Status()
|
ConnStatusType PgConnection::Status()
|
||||||
{
|
{
|
||||||
return PQstatus(pgConn);
|
return PQstatus(pgConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PgConnection::exec -- send a query to the backend
|
// PgConnection::exec -- send a query to the backend
|
||||||
@ -121,11 +102,9 @@ ExecStatusType PgConnection::Exec(const char* query)
|
|||||||
|
|
||||||
// Return the status
|
// Return the status
|
||||||
if (pgResult)
|
if (pgResult)
|
||||||
return PQresultStatus(pgResult);
|
return PQresultStatus(pgResult);
|
||||||
else {
|
else
|
||||||
SetErrorMessage( PQerrorMessage(pgConn) );
|
return PGRES_FATAL_ERROR;
|
||||||
return PGRES_FATAL_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if the Postgres command was executed OK
|
// Return true if the Postgres command was executed OK
|
||||||
@ -140,6 +119,9 @@ int PgConnection::ExecTuplesOk(const char* query)
|
|||||||
} // End ExecTuplesOk()
|
} // 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
|
// PgConnection::notifies() -- returns a notification from a list of unhandled notifications
|
||||||
PGnotify* PgConnection::Notifies()
|
PGnotify* PgConnection::Notifies()
|
||||||
{
|
{
|
||||||
@ -147,15 +129,6 @@ PGnotify* PgConnection::Notifies()
|
|||||||
return PQnotifies(pgConn);
|
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
|
// From Integer To String Conversion Function
|
||||||
string PgConnection::IntToString(int n)
|
string PgConnection::IntToString(int n)
|
||||||
@ -165,3 +138,24 @@ string PgConnection::IntToString(int n)
|
|||||||
sprintf(buffer, "%d", n);
|
sprintf(buffer, "%d", n);
|
||||||
return buffer;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
* Currently under construction.
|
* Currently under construction.
|
||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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
|
#define PGCONN_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "pgenv.h"
|
#include <string>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
@ -36,25 +38,21 @@ extern "C" {
|
|||||||
// derived from this class to obtain the connection interface.
|
// derived from this class to obtain the connection interface.
|
||||||
class PgConnection {
|
class PgConnection {
|
||||||
protected:
|
protected:
|
||||||
PgEnv pgEnv; // Current connection environment
|
|
||||||
PGconn* pgConn; // Connection Structures
|
PGconn* pgConn; // Connection Structures
|
||||||
PGresult* pgResult; // Query Result
|
PGresult* pgResult; // Query Result
|
||||||
string pgErrorMessage; // Error messages container
|
|
||||||
int pgCloseConnection; // Flag indicating whether the connection should be closed or not
|
int pgCloseConnection; // Flag indicating whether the connection should be closed or not
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PgConnection(const char* dbName); // use reasonable defaults
|
PgConnection(const char* conninfo); // use reasonable & environment defaults
|
||||||
PgConnection(const PgEnv& env, const char* dbName); // connect to the database with
|
~PgConnection(); // close connection and clean up
|
||||||
// given environment and database name
|
|
||||||
virtual ~PgConnection(); // close connection and clean up
|
|
||||||
|
|
||||||
// Connection status and error messages
|
// Connection status and error messages
|
||||||
ConnStatusType Status();
|
ConnStatusType Status();
|
||||||
int ConnectionBad() { return Status() == CONNECTION_BAD; }
|
int ConnectionBad();
|
||||||
const char* ErrorMessage() const { return pgErrorMessage.c_str(); }
|
const char* ErrorMessage();
|
||||||
|
|
||||||
// returns the database name of the connection
|
// returns the database name of the connection
|
||||||
const char* DBName() const { return PQdb(pgConn); }
|
const char* DBName();
|
||||||
|
|
||||||
// Query Execution interface
|
// Query Execution interface
|
||||||
ExecStatusType Exec(const char* query); // send a query to the backend
|
ExecStatusType Exec(const char* query); // send a query to the backend
|
||||||
@ -63,13 +61,11 @@ public:
|
|||||||
PGnotify* Notifies();
|
PGnotify* Notifies();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ConnStatusType Connect(const char* dbName);
|
ConnStatusType Connect(const char* conninfo);
|
||||||
void SetErrorMessage(const string&, int append = 0);
|
|
||||||
string IntToString(int);
|
string IntToString(int);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PgConnection();
|
PgConnection();
|
||||||
PgConnection(const PgConnection&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGCONN_H
|
#endif // PGCONN_H
|
||||||
|
@ -9,13 +9,14 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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"
|
#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
|
// Make a connection to the specified database with default environment
|
||||||
PgCursor::PgCursor(const char* dbName, const char* cursor)
|
// See PQconnectdb() for conninfo usage
|
||||||
: PgTransaction(dbName), pgCursor(cursor)
|
PgCursor::PgCursor(const char* conninfo, const char* cursor)
|
||||||
{}
|
: PgTransaction(conninfo), 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)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// Do not make a connection to the backend -- just query
|
// Do not make a connection to the backend -- just query
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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"
|
#include "pgtransdb.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
// PgCursor - a class for querying databases using a cursor
|
// PgCursor - a class for querying databases using a cursor
|
||||||
@ -32,11 +36,10 @@
|
|||||||
// operations, like fetch, forward, etc.
|
// operations, like fetch, forward, etc.
|
||||||
class PgCursor : public PgTransaction {
|
class PgCursor : public PgTransaction {
|
||||||
public:
|
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
|
// 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);
|
PgCursor(const PgConnection&, const char* cursor);
|
||||||
virtual ~PgCursor(); // close connection and clean up
|
~PgCursor(); // close connection and clean up
|
||||||
|
|
||||||
// Commands associated with cursor interface
|
// Commands associated with cursor interface
|
||||||
int Declare(const string& query, int binary = 0); // Declare a cursor with given name
|
int Declare(const string& query, int binary = 0); // Declare a cursor with given name
|
||||||
|
152
src/interfaces/libpq++/pgdatabase.cc
Normal file
152
src/interfaces/libpq++/pgdatabase.cc
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -12,6 +12,9 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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.
|
// results are being received.
|
||||||
class PgDatabase : public PgConnection {
|
class PgDatabase : public PgConnection {
|
||||||
public:
|
public:
|
||||||
PgDatabase(const char* dbName) : PgConnection(dbName) {} // use reasonable defaults
|
PgDatabase(const char* conninfo) : PgConnection(conninfo) {} // use reasonable defaults
|
||||||
// connect to the database with given environment and database name
|
~PgDatabase() {} ; // close connection and clean up
|
||||||
PgDatabase(const PgEnv& env, const char* dbName) : PgConnection(env, dbName) {}
|
|
||||||
PgDatabase(const PgConnection& conn) : PgConnection(conn) {pgCloseConnection = 0;}
|
|
||||||
~PgDatabase() {} // close connection and clean up
|
|
||||||
|
|
||||||
// query result access
|
// query result access
|
||||||
int Tuples()
|
int Tuples();
|
||||||
{ return PQntuples(pgResult); }
|
int Fields();
|
||||||
int Fields()
|
const char* FieldName(int field_num);
|
||||||
{ return PQnfields(pgResult); }
|
int FieldNum(const char* field_name);
|
||||||
const char* FieldName(int field_num)
|
Oid FieldType(int field_num);
|
||||||
{ return PQfname(pgResult, field_num); }
|
Oid FieldType(const char* field_name);
|
||||||
int FieldNum(const char* field_name)
|
short FieldSize(int field_num);
|
||||||
{ return PQfnumber(pgResult, field_name); }
|
short FieldSize(const char* field_name);
|
||||||
Oid FieldType(int field_num)
|
const char* GetValue(int tup_num, int field_num);
|
||||||
{ return PQftype(pgResult, field_num); }
|
const char* GetValue(int tup_num, const char* field_name);
|
||||||
Oid FieldType(const char* field_name)
|
int GetLength(int tup_num, int field_num);
|
||||||
{ return PQftype(pgResult, FieldNum(field_name)); }
|
int GetLength(int tup_num, const char* field_name);
|
||||||
short FieldSize(int field_num)
|
void DisplayTuples(FILE *out = 0, int fillAlign = 1,
|
||||||
{ return PQfsize(pgResult, field_num); }
|
const char* fieldSep = "|",int printHeader = 1, int quiet = 0) ;
|
||||||
short FieldSize(const char* field_name)
|
void PrintTuples(FILE *out = 0, int printAttName = 1,
|
||||||
{ return PQfsize(pgResult, FieldNum(field_name)); }
|
int terseOutput = 0, int width = 0) ;
|
||||||
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); }
|
|
||||||
|
|
||||||
// copy command related access
|
// copy command related access
|
||||||
int GetLine(char* string, int length)
|
int GetLine(char* string, int length);
|
||||||
{ return PQgetline(pgConn, string, length); }
|
void PutLine(const char* string);
|
||||||
void PutLine(const char* string)
|
const char* OidStatus();
|
||||||
{ PQputline(pgConn, string); }
|
int EndCopy();
|
||||||
const char* OidStatus()
|
|
||||||
{ return PQoidStatus(pgResult); }
|
|
||||||
int EndCopy()
|
|
||||||
{ return PQendcopy(pgConn); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PgDatabase() : PgConnection() {} // Do not connect
|
PgDatabase() : PgConnection() {} // Do not connect
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -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
|
|
@ -9,8 +9,6 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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"
|
#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
|
// default constructor
|
||||||
// creates a large object in the default database
|
// creates a large object in the default database
|
||||||
PgLargeObject::PgLargeObject(const char* dbName)
|
// See PQconnectdb() for conninfo usage
|
||||||
: PgConnection(dbName)
|
PgLargeObject::PgLargeObject(const char* conninfo)
|
||||||
|
: PgConnection(conninfo)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
Create();
|
Create();
|
||||||
@ -40,33 +39,15 @@ PgLargeObject::PgLargeObject(const char* dbName)
|
|||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
// open an existing large object in the default database
|
// open an existing large object in the default database
|
||||||
PgLargeObject::PgLargeObject(Oid lobjId, const char* dbName)
|
// See PQconnectdb() for conninfo usage
|
||||||
: PgConnection(dbName)
|
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);
|
Init(lobjId);
|
||||||
if ( !pgObject )
|
if ( !pgObject ) {
|
||||||
Create();
|
Create();
|
||||||
|
}
|
||||||
Open();
|
Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +74,9 @@ void PgLargeObject::Create()
|
|||||||
|
|
||||||
// Check for possible errors
|
// Check for possible errors
|
||||||
if (!pgObject)
|
if (!pgObject)
|
||||||
SetErrorMessage( "PgLargeObject: can't create large object" );
|
loStatus = "PgLargeObject: can't create large object" ;
|
||||||
|
else
|
||||||
|
loStatus = "PgLargeObject: created large object" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PgLargeObject::open
|
// PgLargeObject::open
|
||||||
@ -106,9 +89,9 @@ void PgLargeObject::Open()
|
|||||||
// Check for possible errors
|
// Check for possible errors
|
||||||
string objStr( IntToString(pgObject) );
|
string objStr( IntToString(pgObject) );
|
||||||
if (pgFd < 0)
|
if (pgFd < 0)
|
||||||
SetErrorMessage( "PgLargeObject: can't open large object " + objStr );
|
loStatus = "PgLargeObject: can't open large object " + objStr ;
|
||||||
else
|
else
|
||||||
SetErrorMessage( "PgLargeObject: created and opened large object " + objStr );
|
loStatus = "PgLargeObject: created and opened large object " + objStr ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PgLargeObject::unlink
|
// PgLargeObject::unlink
|
||||||
@ -127,3 +110,53 @@ int PgLargeObject::Unlink()
|
|||||||
// Return the status
|
// Return the status
|
||||||
return temp;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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:
|
private:
|
||||||
int pgFd;
|
int pgFd;
|
||||||
Oid pgObject;
|
Oid pgObject;
|
||||||
|
string loStatus;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PgLargeObject(const char* dbName = 0); // use reasonable defaults and create large object
|
PgLargeObject(const char* conninfo = 0); // use reasonable defaults and create large object
|
||||||
PgLargeObject(Oid lobjId, const char* dbName = 0); // use reasonable defaults and open large object
|
PgLargeObject(Oid lobjId, const char* conninfo = 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(); // close connection and clean up
|
~PgLargeObject(); // close connection and clean up
|
||||||
|
|
||||||
void Create();
|
void Create();
|
||||||
void Open();
|
void Open();
|
||||||
void Close()
|
void Close();
|
||||||
{ if (pgFd >= 0) lo_close(pgConn, pgFd); }
|
int Read(char* buf, int len);
|
||||||
int Read(char* buf, int len)
|
int Write(const char* buf, int len);
|
||||||
{ return lo_read(pgConn, pgFd, buf, len); }
|
int LSeek(int offset, int whence);
|
||||||
int Write(const char* buf, int len)
|
int Tell();
|
||||||
{ 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); }
|
|
||||||
int Unlink();
|
int Unlink();
|
||||||
Oid Import(const char* filename) { return pgObject = lo_import(pgConn, (char*)filename); }
|
Oid LOid();
|
||||||
int Export(const char* filename) { return lo_export(pgConn, pgObject, (char*)filename); }
|
Oid Import(const char* filename);
|
||||||
|
int Export(const char* filename);
|
||||||
|
string Status();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init(Oid lobjId = 0);
|
void Init(Oid lobjId = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PGLOBJ_H
|
#endif // PGLOBJ_H
|
||||||
|
|
||||||
|
// sig 11's if the filename points to a binary file.
|
||||||
|
@ -9,14 +9,13 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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"
|
#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
|
// Make a connection to the specified database with default environment
|
||||||
PgTransaction::PgTransaction(const char* dbName)
|
// See PQconnectdb() for conninfo usage.
|
||||||
: PgDatabase(dbName)
|
PgTransaction::PgTransaction(const char* conninfo)
|
||||||
{
|
: PgDatabase(conninfo)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
BeginTransaction();
|
BeginTransaction();
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* 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"
|
#include "pgdatabase.h"
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
// PgTransaction - a class for running transactions against databases
|
// PgTransaction - a class for running transactions against databases
|
||||||
@ -31,11 +33,10 @@
|
|||||||
// the object is destroyed.
|
// the object is destroyed.
|
||||||
class PgTransaction : public PgDatabase {
|
class PgTransaction : public PgDatabase {
|
||||||
public:
|
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
|
// connect to the database with given environment and database name
|
||||||
PgTransaction(const PgEnv& env, const char* dbName);
|
|
||||||
PgTransaction(const PgConnection&);
|
PgTransaction(const PgConnection&);
|
||||||
virtual ~PgTransaction(); // close connection and clean up
|
~PgTransaction(); // close connection and clean up
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ExecStatusType BeginTransaction();
|
ExecStatusType BeginTransaction();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user