mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
This patch fixes a few minor problems with libpq++: remove the deprecated
PQExec(" ") in the wrapper around PQnotifies(), fix the Makefile for the examples so that they will actually compile properly (with the exception of #5, which depends on internal headers), make a minor change to libpq++.h so that "make examples" now works on my machine, update some documentation, fix some grammatical problems, and remove some of the more hideous comments. Neil Conway
This commit is contained in:
parent
133df7ce70
commit
2e58024066
@ -1,4 +1,3 @@
|
||||
|
||||
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
|
||||
@ -10,8 +9,9 @@ the function of libpq++.
|
||||
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.
|
||||
For details on how to to use libpq++, see Section 3 in Part 1 of
|
||||
the PostgreSQL Developer's Guide and the test programs in the
|
||||
examples/ subdirectory.
|
||||
|
||||
** PgConnection has been changed to accept either the environment
|
||||
variables or conninfo style strings. See the PQconnectdb in the
|
||||
|
@ -1,18 +1,22 @@
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile for example programs
|
||||
# Makefile for libpq++ examples
|
||||
#
|
||||
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
# Portions Copyright (c) 1994, Regents of the University of California
|
||||
#
|
||||
# $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/Makefile,v 1.13 2002/06/15 18:49:29 momjian Exp $
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
subdir = src/interfaces/libpq++/examples
|
||||
top_builddir = ../../../..
|
||||
include $(top_builddir)/src/Makefile.global
|
||||
|
||||
LIBNAME= libpq++
|
||||
HEADERDIR= /usr/local/pgsql/include
|
||||
LIBPQDIR= /usr/local/pgsql/lib
|
||||
HEADERDIR= $(includedir)
|
||||
LIBPQDIR= $(libdir)
|
||||
|
||||
|
||||
# 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 -Wno-unused -Wl,-Bdynamic
|
||||
CXXFLAGS= $(CFLAGS)
|
||||
|
||||
CXXFLAGS+= -I$(HEADERDIR)
|
||||
|
@ -16,14 +16,17 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpq++.h,v 1.10 2001/01/24 19:43:32 momjian Exp $
|
||||
* $Id: libpq++.h,v 1.11 2002/06/15 18:49:29 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LIBPQXX_H
|
||||
#define LIBPQXX_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "libpq++/pgconnection.h"
|
||||
#include "libpq++/pgdatabase.h"
|
||||
#include "libpq++/pglobject.h"
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.13 2002/03/11 15:08:18 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.14 2002/06/15 18:49:29 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -21,7 +21,6 @@
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
// PgConnection Implementation
|
||||
@ -38,9 +37,8 @@ PgConnection::PgConnection()
|
||||
PgConnection::PgConnection(const char* conninfo)
|
||||
: pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
|
||||
{
|
||||
|
||||
// Connect to the database
|
||||
Connect( conninfo );
|
||||
Connect(conninfo);
|
||||
}
|
||||
|
||||
|
||||
@ -59,12 +57,14 @@ PgConnection::~PgConnection()
|
||||
void PgConnection::CloseConnection()
|
||||
{
|
||||
// if the connection is open, close it first
|
||||
if ( pgCloseConnection ) {
|
||||
if(pgResult) PQclear(pgResult);
|
||||
pgResult=NULL;
|
||||
if(pgConn) PQfinish(pgConn);
|
||||
pgConn=NULL;
|
||||
pgCloseConnection=false;
|
||||
if (pgCloseConnection) {
|
||||
if (pgResult)
|
||||
PQclear(pgResult);
|
||||
pgResult = NULL;
|
||||
if (pgConn)
|
||||
PQfinish(pgConn);
|
||||
pgConn = NULL;
|
||||
pgCloseConnection = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ ConnStatusType PgConnection::Status() const
|
||||
// PgConnection::exec -- send a query to the backend
|
||||
ExecStatusType PgConnection::Exec(const char* query)
|
||||
{
|
||||
// Clear the Result Stucture if needed
|
||||
// Clear the result stucture if needed
|
||||
if (pgResult)
|
||||
PQclear(pgResult);
|
||||
|
||||
@ -113,25 +113,21 @@ ExecStatusType PgConnection::Exec(const char* query)
|
||||
int PgConnection::ExecCommandOk(const char* query)
|
||||
{
|
||||
return Exec(query) == PGRES_COMMAND_OK;
|
||||
} // End ExecCommandOk()
|
||||
}
|
||||
|
||||
int PgConnection::ExecTuplesOk(const char* query)
|
||||
{
|
||||
return Exec(query) == PGRES_TUPLES_OK;
|
||||
} // End ExecTuplesOk()
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Don't know why these next two need to be part of Connection
|
||||
|
||||
// PgConnection::notifies() -- returns a notification from a list of unhandled notifications
|
||||
PGnotify* PgConnection::Notifies()
|
||||
{
|
||||
Exec(" ");
|
||||
return PQnotifies(pgConn);
|
||||
}
|
||||
|
||||
|
||||
// From Integer To String Conversion Function
|
||||
string PgConnection::IntToString(int n)
|
||||
{
|
||||
@ -140,27 +136,23 @@ string PgConnection::IntToString(int n)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool PgConnection::ConnectionBad() const
|
||||
{
|
||||
return Status() == CONNECTION_BAD;
|
||||
return Status() == CONNECTION_BAD;
|
||||
}
|
||||
|
||||
|
||||
const char* PgConnection::ErrorMessage() const
|
||||
{
|
||||
return (const char *)PQerrorMessage(pgConn);
|
||||
return (const char *)PQerrorMessage(pgConn);
|
||||
}
|
||||
|
||||
|
||||
const char* PgConnection::DBName() const
|
||||
{
|
||||
return (const char *)PQdb(pgConn);
|
||||
return (const char *)PQdb(pgConn);
|
||||
}
|
||||
|
||||
PQnoticeProcessor PgConnection::SetNoticeProcessor(PQnoticeProcessor proc, void *arg)
|
||||
{
|
||||
return PQsetNoticeProcessor(pgConn, proc, arg);
|
||||
return PQsetNoticeProcessor(pgConn, proc, arg);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pgconnection.h,v 1.16 2002/03/11 15:08:18 momjian Exp $
|
||||
* $Id: pgconnection.h,v 1.17 2002/06/15 18:49:29 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -26,7 +26,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
/* We assume that the C++ compiler will have these keywords, even though
|
||||
* pg_config.h may have #define'd them to empty because C compiler doesn't.
|
||||
* pg_config.h may have #define'd them to empty because the C compiler doesn't.
|
||||
*/
|
||||
#undef const
|
||||
#undef inline
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.6 2001/09/30 22:30:37 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.7 2002/06/15 18:49:29 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -60,26 +60,26 @@ int PgCursor::Declare(string query, bool binary)
|
||||
cmd += " BINARY";
|
||||
cmd += " CURSOR FOR " + query;
|
||||
return ExecCommandOk( cmd.c_str() );
|
||||
} // End Declare()
|
||||
}
|
||||
|
||||
// Fetch ALL tuples in given direction
|
||||
int PgCursor::Fetch(const char* dir)
|
||||
{
|
||||
return Fetch("ALL", dir);
|
||||
} // End Fetch()
|
||||
}
|
||||
|
||||
// Fetch specified amount of tuples in given direction
|
||||
int PgCursor::Fetch(unsigned num, const char* dir)
|
||||
{
|
||||
return Fetch( IntToString(num), dir );
|
||||
} // End Fetch()
|
||||
}
|
||||
|
||||
// Create and execute the actual fetch command with the given arguments
|
||||
int PgCursor::Fetch(string num, string dir)
|
||||
{
|
||||
string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
|
||||
return ExecTuplesOk( cmd.c_str() );
|
||||
} // End Fetch()
|
||||
}
|
||||
|
||||
// Close the cursor: no more queries using the cursor should be allowed
|
||||
// Actually, the backend should take care of it.
|
||||
@ -87,4 +87,4 @@ int PgCursor::Close()
|
||||
{
|
||||
string cmd = "CLOSE " + pgCursor;
|
||||
return ExecCommandOk( cmd.c_str() );
|
||||
} // End CloseCursor()
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* $Id: pgcursordb.h,v 1.9 2001/09/30 22:30:37 tgl Exp $
|
||||
* $Id: pgcursordb.h,v 1.10 2002/06/15 18:49:29 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -32,7 +32,6 @@
|
||||
#define PGSTD
|
||||
#endif
|
||||
|
||||
|
||||
// ****************************************************************
|
||||
//
|
||||
// PgCursor - a class for querying databases using a cursor
|
||||
@ -50,7 +49,7 @@ public:
|
||||
~PgCursor(); // close connection and clean up
|
||||
|
||||
// Commands associated with cursor interface
|
||||
int Declare(PGSTD string query, bool binary=false); // Declare a cursor with given name
|
||||
int Declare(PGSTD string query, bool binary = false); // 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
|
||||
|
@ -10,7 +10,7 @@
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.8 2001/09/30 22:30:37 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.9 2002/06/15 18:49:29 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -104,7 +104,7 @@ void PgLargeObject::Open()
|
||||
}
|
||||
|
||||
// PgLargeObject::unlink
|
||||
// destruct large object and delete from it from the database
|
||||
// destroy large object and delete from it from the database
|
||||
int PgLargeObject::Unlink()
|
||||
{
|
||||
// Unlink the object
|
||||
@ -155,13 +155,13 @@ int PgLargeObject::Tell() const
|
||||
|
||||
Oid PgLargeObject::Import(const char* filename)
|
||||
{
|
||||
return pgObject = lo_import(pgConn, (char*)filename);
|
||||
return pgObject = lo_import(pgConn, filename);
|
||||
}
|
||||
|
||||
|
||||
int PgLargeObject::Export(const char* filename)
|
||||
{
|
||||
return lo_export(pgConn, pgObject, (char*)filename);
|
||||
return lo_export(pgConn, pgObject, filename);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user