Обсуждение: libpq++ fixes
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.
I plan on doing some more work on libpq++ in the future -- this patch just
consists of the necessary code to get the examples to compile on my machine,
plus corrections for any of the minor things I noticed on the way through.
Cheers,
Neil
--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC
Вложения
On Sat, May 18, 2002 at 06:57:25PM -0400, Neil Conway wrote:
>
> I plan on doing some more work on libpq++ in the future -- this patch just
> consists of the necessary code to get the examples to compile on my machine,
> plus corrections for any of the minor things I noticed on the way through.
You may also want to take a look at libpqxx, which was written to replace
libpq++. It's been pretty solid so far, and it gets rid of a lot of the
design limitations of libpq++. IMHO trying to fix libpq++ will not get
around all of its problems, which is why I rewrote libpqxx from scratch.
The code has proven pretty solid so far.
You'll find libpqxx at
http://members.ams.chello.nl/j.vermeulen31/proj-libpqxx.html
Jeroen
On Sun, 19 May 2002 05:35:12 +0200 "jtv" <jtv@xs4all.nl> wrote: > On Sat, May 18, 2002 at 06:57:25PM -0400, Neil Conway wrote: > > > > I plan on doing some more work on libpq++ in the future -- this patch just > > consists of the necessary code to get the examples to compile on my machine, > > plus corrections for any of the minor things I noticed on the way through. > > You may also want to take a look at libpqxx, which was written to replace > libpq++. Wow, looks great! The website mentions your intention to get this code integrated into the PostgreSQL tree -- when would you like to see this happen? I'd definately vote in favour of it. Cheers, Neil -- Neil Conway <neilconway@rogers.com> PGP Key ID: DB3C29FC
On Sun, May 19, 2002 at 01:02:27AM -0400, Neil Conway wrote: > > The website mentions your intention to get this code integrated into > the PostgreSQL tree -- when would you like to see this happen? I'd > definately vote in favour of it. I would _like_ to do it straight away, but I've set myself one more milestone--a real-world application needs to be ported, to prove that libpqxx can survive more than a mere regression test. The idea is to make this a dependable piece of code from day one. Unfortunately I haven't had a lot of time to get the application I wanted to port back into a compilable state on my platform (somebody working on IPv6 support accidentally introduced a bunch of Solaris function calls). So I'm currently hoping for either the news that some other application has been written / ported to use libpqxx, or the time to do it myself. Jeroen
Neil Conway writes:
> 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.
Unfortunately, replacing #include <header.h> with #include <header> is
going to break a bunch of other platforms.
As for the formatting changes, maybe we should run pgindent over those
files. It seems it has never been done.
--
Peter Eisentraut peter_e@gmx.net
On Sun, 19 May 2002 17:14:23 +0200 (CEST)
"Peter Eisentraut" <peter_e@gmx.net> wrote:
> Neil Conway writes:
>
> > 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.
>
> Unfortunately, replacing #include <header.h> with #include <header> is
> going to break a bunch of other platforms.
Really? Which ones?
> As for the formatting changes, maybe we should run pgindent over those
> files. It seems it has never been done.
Yeah -- I was going to suggest that. But given how hideous most of
the libpq++ code is, and the availibility of a replacement for it
(see libpqxx), I'm not sure if it's worth the bother...
Cheers,
Neil
--
Neil Conway <neilconway@rogers.com>
PGP Key ID: DB3C29FC
Neil Conway <nconway@klamath.dyndns.org> writes:
> "Peter Eisentraut" <peter_e@gmx.net> wrote:
>> As for the formatting changes, maybe we should run pgindent over those
>> files. It seems it has never been done.
> Yeah -- I was going to suggest that.
I think the reason Bruce doesn't do that is that pgindent doesn't know
anything about C++.
regards, tom lane
On Sun, 19 May 2002 11:21:18 -0400 "Neil Conway" <nconway@klamath.dyndns.org> wrote: > On Sun, 19 May 2002 17:14:23 +0200 (CEST) > "Peter Eisentraut" <peter_e@gmx.net> wrote: > > Unfortunately, replacing #include <header.h> with #include <header> is > > going to break a bunch of other platforms. > > Really? Which ones? In any case, I've attached a revised patch with #include <cppheader> changed back to #include <cppheader.h> Cheers, Neil -- Neil Conway <neilconway@rogers.com> PGP Key ID: DB3C29FC
Вложения
Your patch has been added to the PostgreSQL unapplied patches list at:
http://candle.pha.pa.us/cgi-bin/pgpatches
I will try to apply it within the next 48 hours.
---------------------------------------------------------------------------
Neil Conway wrote:
> On Sun, 19 May 2002 11:21:18 -0400
> "Neil Conway" <nconway@klamath.dyndns.org> wrote:
> > On Sun, 19 May 2002 17:14:23 +0200 (CEST)
> > "Peter Eisentraut" <peter_e@gmx.net> wrote:
> > > Unfortunately, replacing #include <header.h> with #include <header> is
> > > going to break a bunch of other platforms.
> >
> > Really? Which ones?
>
> In any case, I've attached a revised patch with #include <cppheader> changed
> back to #include <cppheader.h>
>
> Cheers,
>
> Neil
>
> --
> Neil Conway <neilconway@rogers.com>
> PGP Key ID: DB3C29FC
[ Attachment, skipping... ]
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Patch applied:
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
---------------------------------------------------------------------------
Neil Conway wrote:
> On Sun, 19 May 2002 11:21:18 -0400
> "Neil Conway" <nconway@klamath.dyndns.org> wrote:
> > On Sun, 19 May 2002 17:14:23 +0200 (CEST)
> > "Peter Eisentraut" <peter_e@gmx.net> wrote:
> > > Unfortunately, replacing #include <header.h> with #include <header> is
> > > going to break a bunch of other platforms.
> >
> > Really? Which ones?
>
> In any case, I've attached a revised patch with #include <cppheader> changed
> back to #include <cppheader.h>
>
> Cheers,
>
> Neil
>
> --
> Neil Conway <neilconway@rogers.com>
> PGP Key ID: DB3C29FC
[ Attachment, skipping... ]
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
(Oops, sent it to the wrong thread last time.)
If on one is has outstanding libpq++ patches, I will run libpq++ through
my new tools src/tools/pgindent/pgcppindent. It uses astyle. I can
also wait for 7.3 beta and run it then.
Sample changes attached.
---------------------------------------------------------------------------
Neil Conway wrote:
> 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.
>
> I plan on doing some more work on libpq++ in the future -- this patch just
> consists of the necessary code to get the examples to compile on my machine,
> plus corrections for any of the minor things I noticed on the way through.
>
> Cheers,
>
> Neil
>
> --
> Neil Conway <neilconway@rogers.com>
> PGP Key ID: DB3C29FC
[ Attachment, skipping... ]
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Index: pgconnection.cc
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq++/pgconnection.cc,v
retrieving revision 1.14
diff -c -r1.14 pgconnection.cc
*** pgconnection.cc 15 Jun 2002 18:49:29 -0000 1.14
--- pgconnection.cc 15 Jun 2002 19:05:11 -0000
***************
*** 1,19 ****
/*-------------------------------------------------------------------------
! *
! * FILE
! * pgconnection.cc
! *
! * DESCRIPTION
! * implementation of the PgConnection class.
! * PgConnection encapsulates a frontend to backend connection
! *
! * Copyright (c) 1994, Regents of the University of California
! *
! * IDENTIFICATION
! * $Header: /cvsroot/pgsql/src/interfaces/libpq++/pgconnection.cc,v 1.14 2002/06/15 18:49:29 momjian Exp $
! *
! *-------------------------------------------------------------------------
! */
#include "pgconnection.h"
--- 1,19 ----
/*-------------------------------------------------------------------------
! *
! * FILE
! * pgconnection.cc
! *
! * DESCRIPTION
! * implementation of the PgConnection class.
! * PgConnection encapsulates a frontend to backend connection
! *
! * Copyright (c) 1994, Regents of the University of California
! *
! * IDENTIFICATION
! * $Header: /cvsroot/pgsql/src/interfaces/libpq++/pgconnection.cc,v 1.14 2002/06/15 18:49:29 momjian Exp $
! *
! *-------------------------------------------------------------------------
! */
#include "pgconnection.h"
***************
*** 28,71 ****
// ****************************************************************
// default constructor -- initialize everything
PgConnection::PgConnection()
! : pgConn(NULL), pgResult(NULL), pgCloseConnection(false)
{}
// constructor -- checks environment variable for database name
// Now uses PQconnectdb
PgConnection::PgConnection(const char* conninfo)
! : pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
{
! // Connect to the database
! Connect(conninfo);
}
// destructor - closes down the connection and cleanup
PgConnection::~PgConnection()
{
! // Close the connection only if needed
! // This feature will most probably be used by the derived classes that
! // need not close the connection after they are destructed.
! CloseConnection();
}
// PgConnection::CloseConnection()
// close down the connection if there is one
! 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;
! }
}
--- 28,73 ----
// ****************************************************************
// default constructor -- initialize everything
PgConnection::PgConnection()
! : pgConn(NULL), pgResult(NULL), pgCloseConnection(false)
{}
// constructor -- checks environment variable for database name
// Now uses PQconnectdb
+
PgConnection::PgConnection(const char* conninfo)
! : pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
{
! // Connect to the database
! Connect(conninfo);
}
// destructor - closes down the connection and cleanup
PgConnection::~PgConnection()
{
! // Close the connection only if needed
! // This feature will most probably be used by the derived classes that
! // need not close the connection after they are destructed.
! CloseConnection();
}
// PgConnection::CloseConnection()
// close down the connection if there is one
! 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;
! }
}
***************
*** 73,112 ****
// establish a connection to a backend
ConnStatusType PgConnection::Connect(const char conninfo[])
{
! // if the connection is open, close it first
! CloseConnection();
! // Connect to the database
! pgConn = PQconnectdb(conninfo);
! // Now we have a connection we must close (even if it's bad!)
! pgCloseConnection = true;
!
! // Status will return either CONNECTION_OK or CONNECTION_BAD
! return Status();
}
// PgConnection::status -- return connection or result status
ConnStatusType PgConnection::Status() const
{
! return PQstatus(pgConn);
}
// PgConnection::exec -- send a query to the backend
ExecStatusType PgConnection::Exec(const char* query)
{
! // Clear the result stucture if needed
! if (pgResult)
! PQclear(pgResult);
!
! // Execute the given query
! pgResult = PQexec(pgConn, query);
!
! // Return the status
! if (pgResult)
! return PQresultStatus(pgResult);
! else
! return PGRES_FATAL_ERROR;
}
// Return true if the Postgres command was executed OK
--- 75,114 ----
// establish a connection to a backend
ConnStatusType PgConnection::Connect(const char conninfo[])
{
! // if the connection is open, close it first
! CloseConnection();
!
! // Connect to the database
! pgConn = PQconnectdb(conninfo);
! // Now we have a connection we must close (even if it's bad!)
! pgCloseConnection = true;
! // Status will return either CONNECTION_OK or CONNECTION_BAD
! return Status();
}
// PgConnection::status -- return connection or result status
ConnStatusType PgConnection::Status() const
{
! return PQstatus(pgConn);
}
// PgConnection::exec -- send a query to the backend
ExecStatusType PgConnection::Exec(const char* query)
{
! // Clear the result stucture if needed
! if (pgResult)
! PQclear(pgResult);
!
! // Execute the given query
! pgResult = PQexec(pgConn, query);
!
! // Return the status
! if (pgResult)
! return PQresultStatus(pgResult);
! else
! return PGRES_FATAL_ERROR;
}
// Return true if the Postgres command was executed OK
***************
*** 125,158 ****
// PgConnection::notifies() -- returns a notification from a list of unhandled notifications
PGnotify* PgConnection::Notifies()
{
! return PQnotifies(pgConn);
}
// From Integer To String Conversion Function
string PgConnection::IntToString(int n)
{
! char buffer [4*sizeof(n) + 2];
! sprintf(buffer, "%d", n);
! return buffer;
}
bool PgConnection::ConnectionBad() const
! {
! return Status() == CONNECTION_BAD;
}
const char* PgConnection::ErrorMessage() const
! {
! return (const char *)PQerrorMessage(pgConn);
}
!
const char* PgConnection::DBName() const
! {
! return (const char *)PQdb(pgConn);
}
PQnoticeProcessor PgConnection::SetNoticeProcessor(PQnoticeProcessor proc, void *arg)
{
! return PQsetNoticeProcessor(pgConn, proc, arg);
}
--- 127,160 ----
// PgConnection::notifies() -- returns a notification from a list of unhandled notifications
PGnotify* PgConnection::Notifies()
{
! return PQnotifies(pgConn);
}
// From Integer To String Conversion Function
string PgConnection::IntToString(int n)
{
! char buffer [4*sizeof(n) + 2];
! sprintf(buffer, "%d", n);
! return buffer;
}
bool PgConnection::ConnectionBad() const
! {
! return Status() == CONNECTION_BAD;
}
const char* PgConnection::ErrorMessage() const
! {
! return (const char *)PQerrorMessage(pgConn);
}
!
const char* PgConnection::DBName() const
! {
! return (const char *)PQdb(pgConn);
}
PQnoticeProcessor PgConnection::SetNoticeProcessor(PQnoticeProcessor proc, void *arg)
{
! return PQsetNoticeProcessor(pgConn, proc, arg);
}
On Sat, Jun 15, 2002 at 03:16:19PM -0400, Bruce Momjian wrote: > > If on one is has outstanding libpq++ patches, I will run libpq++ through > my new tools src/tools/pgindent/pgcppindent. It uses astyle. I can > also wait for 7.3 beta and run it then. Which reminds me--is it a problem for me to maintain my own indentation style in libpqxx? Jeroen
jtv wrote: > On Sat, Jun 15, 2002 at 03:16:19PM -0400, Bruce Momjian wrote: > > > > If on one is has outstanding libpq++ patches, I will run libpq++ through > > my new tools src/tools/pgindent/pgcppindent. It uses astyle. I can > > also wait for 7.3 beta and run it then. > > Which reminds me--is it a problem for me to maintain my own indentation > style in libpqxx? It is up to you. If you want to, go ahead. We only auto-indent stuff that needs consistent indenting. If you already have that, and want to maintain it, you are welcome. -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026