mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-07-13 12:39:17 +02: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)
|
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
|
and Jolly Chen (jolly@cs.berkeley.edu), this is the first set of
|
||||||
changes to libpq++ since ~1997. Pgenv has been removed, deprecated
|
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
|
The API provided herein is subject to change in later versions of
|
||||||
PostgreSQL.
|
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 Section 3 in Part 1 of
|
||||||
subdirectory and the test programs in the examples/ subdirectory.
|
the PostgreSQL Developer's Guide and the test programs in the
|
||||||
|
examples/ subdirectory.
|
||||||
|
|
||||||
** PgConnection has been changed to accept either the environment
|
** PgConnection has been changed to accept either the environment
|
||||||
variables or conninfo style strings. See the PQconnectdb in the
|
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++
|
LIBNAME= libpq++
|
||||||
HEADERDIR= /usr/local/pgsql/include
|
HEADERDIR= $(includedir)
|
||||||
LIBPQDIR= /usr/local/pgsql/lib
|
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= $(CFLAGS)
|
||||||
|
|
||||||
CXXFLAGS+= -I$(HEADERDIR)
|
CXXFLAGS+= -I$(HEADERDIR)
|
||||||
|
@ -16,14 +16,17 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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
|
#ifndef LIBPQXX_H
|
||||||
#define LIBPQXX_H
|
#define LIBPQXX_H
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "libpq++/pgconnection.h"
|
#include "libpq++/pgconnection.h"
|
||||||
#include "libpq++/pgdatabase.h"
|
#include "libpq++/pgdatabase.h"
|
||||||
#include "libpq++/pglobject.h"
|
#include "libpq++/pglobject.h"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* 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/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;
|
using namespace std;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
// PgConnection Implementation
|
// PgConnection Implementation
|
||||||
@ -38,9 +37,8 @@ PgConnection::PgConnection()
|
|||||||
PgConnection::PgConnection(const char* conninfo)
|
PgConnection::PgConnection(const char* conninfo)
|
||||||
: pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
|
: pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Connect to the database
|
// Connect to the database
|
||||||
Connect( conninfo );
|
Connect(conninfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -59,12 +57,14 @@ PgConnection::~PgConnection()
|
|||||||
void PgConnection::CloseConnection()
|
void PgConnection::CloseConnection()
|
||||||
{
|
{
|
||||||
// if the connection is open, close it first
|
// if the connection is open, close it first
|
||||||
if ( pgCloseConnection ) {
|
if (pgCloseConnection) {
|
||||||
if(pgResult) PQclear(pgResult);
|
if (pgResult)
|
||||||
pgResult=NULL;
|
PQclear(pgResult);
|
||||||
if(pgConn) PQfinish(pgConn);
|
pgResult = NULL;
|
||||||
pgConn=NULL;
|
if (pgConn)
|
||||||
pgCloseConnection=false;
|
PQfinish(pgConn);
|
||||||
|
pgConn = NULL;
|
||||||
|
pgCloseConnection = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ ConnStatusType PgConnection::Status() const
|
|||||||
// PgConnection::exec -- send a query to the backend
|
// PgConnection::exec -- send a query to the backend
|
||||||
ExecStatusType PgConnection::Exec(const char* query)
|
ExecStatusType PgConnection::Exec(const char* query)
|
||||||
{
|
{
|
||||||
// Clear the Result Stucture if needed
|
// Clear the result stucture if needed
|
||||||
if (pgResult)
|
if (pgResult)
|
||||||
PQclear(pgResult);
|
PQclear(pgResult);
|
||||||
|
|
||||||
@ -113,25 +113,21 @@ ExecStatusType PgConnection::Exec(const char* query)
|
|||||||
int PgConnection::ExecCommandOk(const char* query)
|
int PgConnection::ExecCommandOk(const char* query)
|
||||||
{
|
{
|
||||||
return Exec(query) == PGRES_COMMAND_OK;
|
return Exec(query) == PGRES_COMMAND_OK;
|
||||||
} // End ExecCommandOk()
|
}
|
||||||
|
|
||||||
int PgConnection::ExecTuplesOk(const char* query)
|
int PgConnection::ExecTuplesOk(const char* query)
|
||||||
{
|
{
|
||||||
return Exec(query) == PGRES_TUPLES_OK;
|
return Exec(query) == PGRES_TUPLES_OK;
|
||||||
} // End ExecTuplesOk()
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Don't know why these next two need to be part of Connection
|
// 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()
|
||||||
{
|
{
|
||||||
Exec(" ");
|
|
||||||
return PQnotifies(pgConn);
|
return PQnotifies(pgConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// From Integer To String Conversion Function
|
// From Integer To String Conversion Function
|
||||||
string PgConnection::IntToString(int n)
|
string PgConnection::IntToString(int n)
|
||||||
{
|
{
|
||||||
@ -140,27 +136,23 @@ string PgConnection::IntToString(int n)
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool PgConnection::ConnectionBad() const
|
bool PgConnection::ConnectionBad() const
|
||||||
{
|
{
|
||||||
return Status() == CONNECTION_BAD;
|
return Status() == CONNECTION_BAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* PgConnection::ErrorMessage() const
|
const char* PgConnection::ErrorMessage() const
|
||||||
{
|
{
|
||||||
return (const char *)PQerrorMessage(pgConn);
|
return (const char *)PQerrorMessage(pgConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* PgConnection::DBName() const
|
const char* PgConnection::DBName() const
|
||||||
{
|
{
|
||||||
return (const char *)PQdb(pgConn);
|
return (const char *)PQdb(pgConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
PQnoticeProcessor PgConnection::SetNoticeProcessor(PQnoticeProcessor proc, void *arg)
|
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) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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
|
/* 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 const
|
||||||
#undef inline
|
#undef inline
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* 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/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 += " BINARY";
|
||||||
cmd += " CURSOR FOR " + query;
|
cmd += " CURSOR FOR " + query;
|
||||||
return ExecCommandOk( cmd.c_str() );
|
return ExecCommandOk( cmd.c_str() );
|
||||||
} // End Declare()
|
}
|
||||||
|
|
||||||
// Fetch ALL tuples in given direction
|
// Fetch ALL tuples in given direction
|
||||||
int PgCursor::Fetch(const char* dir)
|
int PgCursor::Fetch(const char* dir)
|
||||||
{
|
{
|
||||||
return Fetch("ALL", dir);
|
return Fetch("ALL", dir);
|
||||||
} // End Fetch()
|
}
|
||||||
|
|
||||||
// Fetch specified amount of tuples in given direction
|
// Fetch specified amount of tuples in given direction
|
||||||
int PgCursor::Fetch(unsigned num, const char* dir)
|
int PgCursor::Fetch(unsigned num, const char* dir)
|
||||||
{
|
{
|
||||||
return Fetch( IntToString(num), dir );
|
return Fetch( IntToString(num), dir );
|
||||||
} // End Fetch()
|
}
|
||||||
|
|
||||||
// Create and execute the actual fetch command with the given arguments
|
// Create and execute the actual fetch command with the given arguments
|
||||||
int PgCursor::Fetch(string num, string dir)
|
int PgCursor::Fetch(string num, string dir)
|
||||||
{
|
{
|
||||||
string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
|
string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
|
||||||
return ExecTuplesOk( cmd.c_str() );
|
return ExecTuplesOk( cmd.c_str() );
|
||||||
} // End Fetch()
|
}
|
||||||
|
|
||||||
// Close the cursor: no more queries using the cursor should be allowed
|
// Close the cursor: no more queries using the cursor should be allowed
|
||||||
// Actually, the backend should take care of it.
|
// Actually, the backend should take care of it.
|
||||||
@ -87,4 +87,4 @@ int PgCursor::Close()
|
|||||||
{
|
{
|
||||||
string cmd = "CLOSE " + pgCursor;
|
string cmd = "CLOSE " + pgCursor;
|
||||||
return ExecCommandOk( cmd.c_str() );
|
return ExecCommandOk( cmd.c_str() );
|
||||||
} // End CloseCursor()
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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
|
#define PGSTD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************
|
// ****************************************************************
|
||||||
//
|
//
|
||||||
// PgCursor - a class for querying databases using a cursor
|
// PgCursor - a class for querying databases using a cursor
|
||||||
@ -50,7 +49,7 @@ public:
|
|||||||
~PgCursor(); // close connection and clean up
|
~PgCursor(); // close connection and clean up
|
||||||
|
|
||||||
// Commands associated with cursor interface
|
// 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(const char* dir = "FORWARD"); // Fetch ALL tuples in given direction
|
||||||
int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples
|
int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples
|
||||||
int Close(); // Close the cursor
|
int Close(); // Close the cursor
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* 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/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
|
// 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()
|
int PgLargeObject::Unlink()
|
||||||
{
|
{
|
||||||
// Unlink the object
|
// Unlink the object
|
||||||
@ -155,13 +155,13 @@ int PgLargeObject::Tell() const
|
|||||||
|
|
||||||
Oid PgLargeObject::Import(const char* filename)
|
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)
|
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