Skip to content

Commit 2e58024

Browse files
committed
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
1 parent 133df7c commit 2e58024

File tree

8 files changed

+51
-53
lines changed

8 files changed

+51
-53
lines changed

src/interfaces/libpq++/README

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Based on the original work by William Wanders (wwanders@sci.kun.nl)
32
and Jolly Chen (jolly@cs.berkeley.edu), this is the first set of
43
changes to libpq++ since ~1997. Pgenv has been removed, deprecated
@@ -10,8 +9,9 @@ the function of libpq++.
109
The API provided herein is subject to change in later versions of
1110
PostgreSQL.
1211

13-
For details on how to to use libpq++, see the man page in the man/
14-
subdirectory and the test programs in the examples/ subdirectory.
12+
For details on how to to use libpq++, see Section 3 in Part 1 of
13+
the PostgreSQL Developer's Guide and the test programs in the
14+
examples/ subdirectory.
1515

1616
** PgConnection has been changed to accept either the environment
1717
variables or conninfo style strings. See the PQconnectdb in the

src/interfaces/libpq++/examples/Makefile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
#-------------------------------------------------------------------------
12
#
2-
# Makefile for example programs
3+
# Makefile for libpq++ examples
34
#
5+
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
6+
# Portions Copyright (c) 1994, Regents of the University of California
7+
#
8+
# $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/Makefile,v 1.13 2002/06/15 18:49:29 momjian Exp $
9+
#
10+
#-------------------------------------------------------------------------
411

12+
subdir = src/interfaces/libpq++/examples
13+
top_builddir = ../../../..
14+
include $(top_builddir)/src/Makefile.global
515

616
LIBNAME= libpq++
7-
HEADERDIR= /usr/local/pgsql/include
8-
LIBPQDIR= /usr/local/pgsql/lib
9-
10-
11-
# We have to override -Werror, which makes warnings, fatal, because we
12-
# inevitably get the warning, "abstract declarator used as declaration"
13-
# because of our inclusion of c.h and we don't know how to stop that.
17+
HEADERDIR= $(includedir)
18+
LIBPQDIR= $(libdir)
1419

15-
#CXXFLAGS= $(CFLAGS) -Wno-error -Wno-unused -Wl,-Bdynamic
1620
CXXFLAGS= $(CFLAGS)
1721

1822
CXXFLAGS+= -I$(HEADERDIR)

src/interfaces/libpq++/libpq++.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1717
* Portions Copyright (c) 1994, Regents of the University of California
1818
*
19-
* $Id: libpq++.h,v 1.10 2001/01/24 19:43:32 momjian Exp $
19+
* $Id: libpq++.h,v 1.11 2002/06/15 18:49:29 momjian Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
2323

24+
2425
#ifndef LIBPQXX_H
2526
#define LIBPQXX_H
2627

28+
#include <string.h>
29+
2730
#include "libpq++/pgconnection.h"
2831
#include "libpq++/pgdatabase.h"
2932
#include "libpq++/pglobject.h"

src/interfaces/libpq++/pgconnection.cc

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.13 2002/03/11 15:08:18 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.14 2002/06/15 18:49:29 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -21,7 +21,6 @@
2121
using namespace std;
2222
#endif
2323

24-
2524
// ****************************************************************
2625
//
2726
// PgConnection Implementation
@@ -38,9 +37,8 @@ PgConnection::PgConnection()
3837
PgConnection::PgConnection(const char* conninfo)
3938
: pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
4039
{
41-
4240
// Connect to the database
43-
Connect( conninfo );
41+
Connect(conninfo);
4442
}
4543

4644

@@ -59,12 +57,14 @@ PgConnection::~PgConnection()
5957
void PgConnection::CloseConnection()
6058
{
6159
// if the connection is open, close it first
62-
if ( pgCloseConnection ) {
63-
if(pgResult) PQclear(pgResult);
64-
pgResult=NULL;
65-
if(pgConn) PQfinish(pgConn);
66-
pgConn=NULL;
67-
pgCloseConnection=false;
60+
if (pgCloseConnection) {
61+
if (pgResult)
62+
PQclear(pgResult);
63+
pgResult = NULL;
64+
if (pgConn)
65+
PQfinish(pgConn);
66+
pgConn = NULL;
67+
pgCloseConnection = false;
6868
}
6969
}
7070

@@ -95,7 +95,7 @@ ConnStatusType PgConnection::Status() const
9595
// PgConnection::exec -- send a query to the backend
9696
ExecStatusType PgConnection::Exec(const char* query)
9797
{
98-
// Clear the Result Stucture if needed
98+
// Clear the result stucture if needed
9999
if (pgResult)
100100
PQclear(pgResult);
101101

@@ -113,25 +113,21 @@ ExecStatusType PgConnection::Exec(const char* query)
113113
int PgConnection::ExecCommandOk(const char* query)
114114
{
115115
return Exec(query) == PGRES_COMMAND_OK;
116-
} // End ExecCommandOk()
116+
}
117117

118118
int PgConnection::ExecTuplesOk(const char* query)
119119
{
120120
return Exec(query) == PGRES_TUPLES_OK;
121-
} // End ExecTuplesOk()
122-
123-
121+
}
124122

125123
// Don't know why these next two need to be part of Connection
126124

127125
// PgConnection::notifies() -- returns a notification from a list of unhandled notifications
128126
PGnotify* PgConnection::Notifies()
129127
{
130-
Exec(" ");
131128
return PQnotifies(pgConn);
132129
}
133130

134-
135131
// From Integer To String Conversion Function
136132
string PgConnection::IntToString(int n)
137133
{
@@ -140,27 +136,23 @@ string PgConnection::IntToString(int n)
140136
return buffer;
141137
}
142138

143-
144-
145139
bool PgConnection::ConnectionBad() const
146140
{
147-
return Status() == CONNECTION_BAD;
141+
return Status() == CONNECTION_BAD;
148142
}
149143

150-
151144
const char* PgConnection::ErrorMessage() const
152145
{
153-
return (const char *)PQerrorMessage(pgConn);
146+
return (const char *)PQerrorMessage(pgConn);
154147
}
155148

156-
157149
const char* PgConnection::DBName() const
158150
{
159-
return (const char *)PQdb(pgConn);
151+
return (const char *)PQdb(pgConn);
160152
}
161153

162154
PQnoticeProcessor PgConnection::SetNoticeProcessor(PQnoticeProcessor proc, void *arg)
163155
{
164-
return PQsetNoticeProcessor(pgConn, proc, arg);
156+
return PQsetNoticeProcessor(pgConn, proc, arg);
165157
}
166158

src/interfaces/libpq++/pgconnection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $Id: pgconnection.h,v 1.16 2002/03/11 15:08:18 momjian Exp $
16+
* $Id: pgconnection.h,v 1.17 2002/06/15 18:49:29 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -26,7 +26,7 @@ extern "C" {
2626
}
2727

2828
/* We assume that the C++ compiler will have these keywords, even though
29-
* pg_config.h may have #define'd them to empty because C compiler doesn't.
29+
* pg_config.h may have #define'd them to empty because the C compiler doesn't.
3030
*/
3131
#undef const
3232
#undef inline

src/interfaces/libpq++/pgcursordb.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.6 2001/09/30 22:30:37 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.7 2002/06/15 18:49:29 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -60,31 +60,31 @@ int PgCursor::Declare(string query, bool binary)
6060
cmd += " BINARY";
6161
cmd += " CURSOR FOR " + query;
6262
return ExecCommandOk( cmd.c_str() );
63-
} // End Declare()
63+
}
6464

6565
// Fetch ALL tuples in given direction
6666
int PgCursor::Fetch(const char* dir)
6767
{
6868
return Fetch("ALL", dir);
69-
} // End Fetch()
69+
}
7070

7171
// Fetch specified amount of tuples in given direction
7272
int PgCursor::Fetch(unsigned num, const char* dir)
7373
{
7474
return Fetch( IntToString(num), dir );
75-
} // End Fetch()
75+
}
7676

7777
// Create and execute the actual fetch command with the given arguments
7878
int PgCursor::Fetch(string num, string dir)
7979
{
8080
string cmd = "FETCH " + dir + " " + num + " IN " + pgCursor;
8181
return ExecTuplesOk( cmd.c_str() );
82-
} // End Fetch()
82+
}
8383

8484
// Close the cursor: no more queries using the cursor should be allowed
8585
// Actually, the backend should take care of it.
8686
int PgCursor::Close()
8787
{
8888
string cmd = "CLOSE " + pgCursor;
8989
return ExecCommandOk( cmd.c_str() );
90-
} // End CloseCursor()
90+
}

src/interfaces/libpq++/pgcursordb.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
1616
*
17-
* $Id: pgcursordb.h,v 1.9 2001/09/30 22:30:37 tgl Exp $
17+
* $Id: pgcursordb.h,v 1.10 2002/06/15 18:49:29 momjian Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -32,7 +32,6 @@
3232
#define PGSTD
3333
#endif
3434

35-
3635
// ****************************************************************
3736
//
3837
// PgCursor - a class for querying databases using a cursor
@@ -50,7 +49,7 @@ class DLLIMPORT PgCursor : public PgTransaction {
5049
~PgCursor(); // close connection and clean up
5150

5251
// Commands associated with cursor interface
53-
int Declare(PGSTD string query, bool binary=false); // Declare a cursor with given name
52+
int Declare(PGSTD string query, bool binary = false); // Declare a cursor with given name
5453
int Fetch(const char* dir = "FORWARD"); // Fetch ALL tuples in given direction
5554
int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples
5655
int Close(); // Close the cursor

src/interfaces/libpq++/pglobject.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.8 2001/09/30 22:30:37 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.9 2002/06/15 18:49:29 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -104,7 +104,7 @@ void PgLargeObject::Open()
104104
}
105105

106106
// PgLargeObject::unlink
107-
// destruct large object and delete from it from the database
107+
// destroy large object and delete from it from the database
108108
int PgLargeObject::Unlink()
109109
{
110110
// Unlink the object
@@ -155,13 +155,13 @@ int PgLargeObject::Tell() const
155155

156156
Oid PgLargeObject::Import(const char* filename)
157157
{
158-
return pgObject = lo_import(pgConn, (char*)filename);
158+
return pgObject = lo_import(pgConn, filename);
159159
}
160160

161161

162162
int PgLargeObject::Export(const char* filename)
163163
{
164-
return lo_export(pgConn, pgObject, (char*)filename);
164+
return lo_export(pgConn, pgObject, filename);
165165
}
166166

167167

0 commit comments

Comments
 (0)