-
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
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
+#-------------------------------------------------------------------------
#
-# 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
-
-
-# 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.
+HEADERDIR= $(includedir)
+LIBPQDIR= $(libdir)
-#CXXFLAGS= $(CFLAGS) -Wno-error -Wno-unused -Wl,-Bdynamic
CXXFLAGS= $(CFLAGS)
CXXFLAGS+= -I$(HEADERDIR)
* 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"
* 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 $
*
*-------------------------------------------------------------------------
*/
using namespace std;
#endif
-
// ****************************************************************
//
// PgConnection Implementation
PgConnection::PgConnection(const char* conninfo)
: pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
{
-
// Connect to the database
- Connect( conninfo );
+ Connect(conninfo);
}
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;
}
}
// 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);
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)
{
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);
}
* 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 $
*
*-------------------------------------------------------------------------
*/
}
/* 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
* 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 $
*
*-------------------------------------------------------------------------
*/
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.
{
string cmd = "CLOSE " + pgCursor;
return ExecCommandOk( cmd.c_str() );
-} // End CloseCursor()
+}
* 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 $
*
*-------------------------------------------------------------------------
*/
#define PGSTD
#endif
-
// ****************************************************************
//
// PgCursor - a class for querying databases using a cursor
~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
* 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 $
*
*-------------------------------------------------------------------------
*/
}
// 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
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);
}