pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedlibpq++: suggested patches for PgTransaction
2+ messages / 2 participants
[nested] [flat]
* libpq++: suggested patches for PgTransaction
@ 2001-02-28 12:55 J. T. Vermeulen <jtv@cistron-office.nl>
2001-02-28 17:14 ` Re: libpq++: suggested patches for PgTransaction Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: J. T. Vermeulen @ 2001-02-28 12:55 UTC (permalink / raw)
To: pgsql-interfaces
The original PgTransaction, apparently having been written without exceptions
in mind, didn't know how to abort a transaction. The suggested change makes
it abort if the transaction object is destroyed without an explicit commit,
as would happen if the program fell out of the transaction code through an
unhandled exception (plus the patch makes constructors explicit where
appropriate).
Actually this still isn't very effective; I think it would be more useful to
have a separate transaction object "latch onto" an existing connection and
represent a single transaction delimited by the object's entire lifetime.
That would make it easier to perform multiple independent (but presumably
non-overlapping) transactions over the lifetime of a single connection in
an exception-safe manner.
inline patch 1: postgresql-7.0.3-jtv/src/interfaces/libpq++/pgtransdb.cc, postgresql-7.0.3-jtv/src/interfaces/libpq++/pgtransdb.h (+11/-5 lines) download inline-1.patch
--- postgresql-7.0.3/src/interfaces/libpq++/pgtransdb.cc Sun May 30 17:17:58 1999
+++ postgresql-7.0.3-jtv/src/interfaces/libpq++/pgtransdb.cc Wed Feb 28 13:34:20 2001
@@ -25,7 +25,8 @@
// Make a connection to the specified database with default environment
// See PQconnectdb() for conninfo usage.
PgTransaction::PgTransaction(const char* conninfo)
- : PgDatabase(conninfo)
+ : PgDatabase(conninfo),
+ pgCommitted(true)
{
BeginTransaction();
}
@@ -33,17 +34,20 @@
// Destructor: End the transaction block
PgTransaction::~PgTransaction()
{
- EndTransaction();
+ if (!pgCommitted) Exec("ABORT");
}
// Begin the transaction block
ExecStatusType PgTransaction::BeginTransaction()
{
+ pgCommitted = false;
return Exec("BEGIN");
} // End BeginTransaction()
// Begin the transaction block
ExecStatusType PgTransaction::EndTransaction()
{
+ pgCommitted = true;
return Exec("END");
} // End EndTransaction()
+
--- postgresql-7.0.3/src/interfaces/libpq++/pgtransdb.h Sun Apr 23 00:39:15 2000
+++ postgresql-7.0.3-jtv/src/interfaces/libpq++/pgtransdb.h Wed Feb 28 13:34:42 2001
@@ -36,9 +36,9 @@
// the object is destroyed.
class PgTransaction : public PgDatabase {
public:
- PgTransaction(const char* conninfo); // use reasonable & environment defaults
+ explicit PgTransaction(const char conninfo[]); // use reasonable & environment defaults
// connect to the database with given environment and database name
- // PgTransaction(const PgConnection&);
+ // explicit PgTransaction(const PgConnection&);
~PgTransaction(); // close connection and clean up
protected:
@@ -46,9 +46,11 @@
ExecStatusType EndTransaction();
protected:
- PgTransaction() : PgDatabase() {} // Do not connect
+ PgTransaction() : PgDatabase(), pgCommitted(true) {} // Do not connect
private:
+ bool pgCommitted;
+
// We don't support copying of PgTransaction objects,
// so make copy constructor and assignment op private.
PgTransaction(const PgTransaction&);
Jeroen
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: libpq++: suggested patches for PgTransaction
2001-02-28 12:55 libpq++: suggested patches for PgTransaction J. T. Vermeulen <jtv@cistron-office.nl>
@ 2001-02-28 17:14 ` Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Bruce Momjian @ 2001-02-28 17:14 UTC (permalink / raw)
To: J. T. Vermeulen <jtv@cistron-office.nl>; +Cc: pgsql-interfaces
I will keep this for 7.2. Thanks.
> The original PgTransaction, apparently having been written without exceptions
> in mind, didn't know how to abort a transaction. The suggested change makes
> it abort if the transaction object is destroyed without an explicit commit,
> as would happen if the program fell out of the transaction code through an
> unhandled exception (plus the patch makes constructors explicit where
> appropriate).
>
> Actually this still isn't very effective; I think it would be more useful to
> have a separate transaction object "latch onto" an existing connection and
> represent a single transaction delimited by the object's entire lifetime.
> That would make it easier to perform multiple independent (but presumably
> non-overlapping) transactions over the lifetime of a single connection in
> an exception-safe manner.
>
>
> --- postgresql-7.0.3/src/interfaces/libpq++/pgtransdb.cc Sun May 30 17:17:58 1999
> +++ postgresql-7.0.3-jtv/src/interfaces/libpq++/pgtransdb.cc Wed Feb 28 13:34:20 2001
> @@ -25,7 +25,8 @@
> // Make a connection to the specified database with default environment
> // See PQconnectdb() for conninfo usage.
> PgTransaction::PgTransaction(const char* conninfo)
> - : PgDatabase(conninfo)
> + : PgDatabase(conninfo),
> + pgCommitted(true)
> {
> BeginTransaction();
> }
> @@ -33,17 +34,20 @@
> // Destructor: End the transaction block
> PgTransaction::~PgTransaction()
> {
> - EndTransaction();
> + if (!pgCommitted) Exec("ABORT");
> }
>
> // Begin the transaction block
> ExecStatusType PgTransaction::BeginTransaction()
> {
> + pgCommitted = false;
> return Exec("BEGIN");
> } // End BeginTransaction()
>
> // Begin the transaction block
> ExecStatusType PgTransaction::EndTransaction()
> {
> + pgCommitted = true;
> return Exec("END");
> } // End EndTransaction()
> +
>
>
>
> --- postgresql-7.0.3/src/interfaces/libpq++/pgtransdb.h Sun Apr 23 00:39:15 2000
> +++ postgresql-7.0.3-jtv/src/interfaces/libpq++/pgtransdb.h Wed Feb 28 13:34:42 2001
> @@ -36,9 +36,9 @@
> // the object is destroyed.
> class PgTransaction : public PgDatabase {
> public:
> - PgTransaction(const char* conninfo); // use reasonable & environment defaults
> + explicit PgTransaction(const char conninfo[]); // use reasonable & environment defaults
> // connect to the database with given environment and database name
> - // PgTransaction(const PgConnection&);
> + // explicit PgTransaction(const PgConnection&);
> ~PgTransaction(); // close connection and clean up
>
> protected:
> @@ -46,9 +46,11 @@
> ExecStatusType EndTransaction();
>
> protected:
> - PgTransaction() : PgDatabase() {} // Do not connect
> + PgTransaction() : PgDatabase(), pgCommitted(true) {} // Do not connect
>
> private:
> + bool pgCommitted;
> +
> // We don't support copying of PgTransaction objects,
> // so make copy constructor and assignment op private.
> PgTransaction(const PgTransaction&);
>
>
>
> Jeroen
>
>
--
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-02-28 17:14 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-02-28 12:55 libpq++: suggested patches for PgTransaction J. T. Vermeulen <jtv@cistron-office.nl>
2001-02-28 17:14 ` Bruce Momjian <pgman@candle.pha.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox