1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-03 01:21:48 +03:00

Indent libpq++ as mentioned in email. Format was terrible, and this

will make fixing things easier.
This commit is contained in:
Bruce Momjian 2002-07-02 16:32:19 +00:00
parent c9a7345217
commit a4485ea894
19 changed files with 969 additions and 902 deletions

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.6 2000/05/29 21:25:04 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.7 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -21,7 +21,8 @@ int main()
{ {
// Open the connection to the database and make sure it's OK // Open the connection to the database and make sure it's OK
PgDatabase data("dbname=template1"); PgDatabase data("dbname=template1");
if ( data.ConnectionBad() ) { if ( data.ConnectionBad() )
{
cout << "Connection was unsuccessful..." << endl cout << "Connection was unsuccessful..." << endl
<< "Error message returned: " << data.ErrorMessage() << endl; << "Error message returned: " << data.ErrorMessage() << endl;
return 1; return 1;

View File

@ -20,26 +20,30 @@ int main()
PgDatabase data(dbName); PgDatabase data(dbName);
// check to see that the backend connection was successfully made // check to see that the backend connection was successfully made
if ( data.ConnectionBad() ) { if ( data.ConnectionBad() )
{
cerr << "Connection to database '" << dbName << "' failed." << endl cerr << "Connection to database '" << dbName << "' failed." << endl
<< "Error returned: " << data.ErrorMessage() << endl; << "Error returned: " << data.ErrorMessage() << endl;
exit(1); exit(1);
} }
// start a transaction block // start a transaction block
if ( !data.ExecCommandOk("BEGIN") ) { if ( !data.ExecCommandOk("BEGIN") )
{
cerr << "BEGIN command failed" << endl; cerr << "BEGIN command failed" << endl;
exit(1); exit(1);
} }
// submit command to the backend // submit command to the backend
if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") ) { if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") )
{
cerr << "DECLARE CURSOR command failed" << endl; cerr << "DECLARE CURSOR command failed" << endl;
exit(1); exit(1);
} }
// fetch instances from the pg_database, the system catalog of databases // fetch instances from the pg_database, the system catalog of databases
if ( !data.ExecTuplesOk("FETCH ALL in myportal") ) { if ( !data.ExecTuplesOk("FETCH ALL in myportal") )
{
cerr << "FETCH ALL command didn't return tuples properly" << endl; cerr << "FETCH ALL command didn't return tuples properly" << endl;
exit(1); exit(1);
} }
@ -51,7 +55,8 @@ int main()
cout << endl << endl; cout << endl << endl;
// next, print out the instances // next, print out the instances
for (int i=0; i < data.Tuples(); i++) { for (int i = 0; i < data.Tuples(); i++)
{
for (int j = 0; j < nFields; j++) for (int j = 0; j < nFields; j++)
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j); cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j);
cout << endl; cout << endl;

View File

@ -20,20 +20,23 @@ int main()
PgTransaction data(dbName); PgTransaction data(dbName);
// check to see that the backend connection was successfully made // check to see that the backend connection was successfully made
if ( data.ConnectionBad() ) { if ( data.ConnectionBad() )
{
cerr << "Connection to database '" << dbName << "' failed." << endl cerr << "Connection to database '" << dbName << "' failed." << endl
<< "Error returned: " << data.ErrorMessage() << endl; << "Error returned: " << data.ErrorMessage() << endl;
exit(1); exit(1);
} }
// submit command to the backend // submit command to the backend
if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") ) { if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") )
{
cerr << "DECLARE CURSOR command failed" << endl; cerr << "DECLARE CURSOR command failed" << endl;
exit(1); exit(1);
} }
// fetch instances from the pg_database, the system catalog of databases // fetch instances from the pg_database, the system catalog of databases
if ( !data.ExecTuplesOk("FETCH ALL in myportal") ) { if ( !data.ExecTuplesOk("FETCH ALL in myportal") )
{
cerr << "FETCH ALL command didn't return tuples properly" << endl; cerr << "FETCH ALL command didn't return tuples properly" << endl;
exit(1); exit(1);
} }
@ -45,7 +48,8 @@ int main()
cout << endl << endl; cout << endl << endl;
// next, print out the instances // next, print out the instances
for (int i=0; i < data.Tuples(); i++) { for (int i = 0; i < data.Tuples(); i++)
{
for (int j = 0; j < nFields; j++) for (int j = 0; j < nFields; j++)
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j); cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j);
cout << endl; cout << endl;

View File

@ -23,20 +23,23 @@ int main()
PgCursor cData(dbName, "myportal"); PgCursor cData(dbName, "myportal");
// check to see that the backend connection was successfully made // check to see that the backend connection was successfully made
if ( cData.ConnectionBad() ) { if ( cData.ConnectionBad() )
{
cerr << "Connection to database '" << dbName << "' failed." << endl cerr << "Connection to database '" << dbName << "' failed." << endl
<< "Error returned: " << cData.ErrorMessage() << endl; << "Error returned: " << cData.ErrorMessage() << endl;
exit(1); exit(1);
} }
// submit command to the backend // submit command to the backend
if ( !cData.Declare("select * from pg_database") ) { if ( !cData.Declare("select * from pg_database") )
{
cerr << "DECLARE CURSOR command failed" << endl; cerr << "DECLARE CURSOR command failed" << endl;
exit(1); exit(1);
} }
// fetch instances from the pg_cDatabase, the system catalog of cDatabases // fetch instances from the pg_cDatabase, the system catalog of cDatabases
if ( !cData.Fetch() ) { if ( !cData.Fetch() )
{
cerr << "FETCH ALL command didn't return tuples properly" << endl; cerr << "FETCH ALL command didn't return tuples properly" << endl;
exit(1); exit(1);
} }
@ -48,7 +51,8 @@ int main()
cout << endl << endl; cout << endl << endl;
// next, print out the instances // next, print out the instances
for (int i=0; i < cData.Tuples(); i++) { for (int i = 0; i < cData.Tuples(); i++)
{
for (int j = 0; j < nFields; j++) for (int j = 0; j < nFields; j++)
cout << setiosflags(ios::right) << setw(15) << cData.GetValue(i, j); cout << setiosflags(ios::right) << setw(15) << cData.GetValue(i, j);
cout << endl; cout << endl;

View File

@ -31,23 +31,27 @@ int main()
PgDatabase data(dbName); PgDatabase data(dbName);
// Check to see that the backend connection was successfully made // Check to see that the backend connection was successfully made
if ( data.ConnectionBad() ) { if ( data.ConnectionBad() )
{
cerr << "Connection to database '" << dbName << "' failed." << endl cerr << "Connection to database '" << dbName << "' failed." << endl
<< data.ErrorMessage() << endl; << data.ErrorMessage() << endl;
exit(1); exit(1);
} }
// Listen to a table // Listen to a table
if ( !data.ExecCommandOk("LISTEN TBL2") ) { if ( !data.ExecCommandOk("LISTEN TBL2") )
{
cerr << "LISTEN command failed" << endl; cerr << "LISTEN command failed" << endl;
exit(1); exit(1);
} }
// Test asynchronous notification // Test asynchronous notification
while (1) { while (1)
{
// check for asynchronous returns // check for asynchronous returns
PGnotify* notify = data.Notifies(); PGnotify* notify = data.Notifies();
if (notify) { if (notify)
{
cerr << "ASYNC NOTIFY of '" << notify->relname cerr << "ASYNC NOTIFY of '" << notify->relname
<< "' from backend pid '" << notify->be_pid << "' from backend pid '" << notify->be_pid
<< "' received" << endl; << "' received" << endl;

View File

@ -29,7 +29,8 @@ tuple 1: got
#include <iostream.h> #include <iostream.h>
#include "libpq++.h" #include "libpq++.h"
#include <stdlib.h> #include <stdlib.h>
extern "C" { extern "C"
{
#include "postgres.h" // for Postgres types #include "postgres.h" // for Postgres types
#include "utils/geo_decls.h" // for the POLYGON type #include "utils/geo_decls.h" // for the POLYGON type
} }
@ -43,20 +44,23 @@ int main()
PgCursor data(dbName, "mycursor"); PgCursor data(dbName, "mycursor");
// check to see that the backend connection was successfully made // check to see that the backend connection was successfully made
if ( data.ConnectionBad() ) { if ( data.ConnectionBad() )
{
cerr << "Connection to database '" << dbName << "' failed." << endl cerr << "Connection to database '" << dbName << "' failed." << endl
<< data.ErrorMessage(); << data.ErrorMessage();
exit(1); exit(1);
} }
// Declare a binary cursor for all the tuples in database 'test1' // Declare a binary cursor for all the tuples in database 'test1'
if ( !data.Declare("select * from test1", 1) ) { if ( !data.Declare("select * from test1", 1) )
{
cerr << "DECLARE CURSOR command failed" << endl; cerr << "DECLARE CURSOR command failed" << endl;
exit(1); exit(1);
} }
// fetch all instances from the current cursor // fetch all instances from the current cursor
if ( !data.Fetch() ) { if ( !data.Fetch() )
{
cerr << "FETCH ALL command didn't return tuples properly" << endl; cerr << "FETCH ALL command didn't return tuples properly" << endl;
exit(1); exit(1);
} }
@ -75,7 +79,8 @@ int main()
*/ */
// Print out the information about the extracted tuple // Print out the information about the extracted tuple
for (int i=0; i < data.Tuples(); i++) { for (int i = 0; i < data.Tuples(); i++)
{
// we hard-wire this to the 3 fields we know about // we hard-wire this to the 3 fields we know about
int* ival = (int*)data.GetValue(i, i_fnum); int* ival = (int*)data.GetValue(i, i_fnum);
float* dval = (float*)data.GetValue(i, d_fnum); float* dval = (float*)data.GetValue(i, d_fnum);

View File

@ -17,26 +17,32 @@ int main()
PgTransaction data(dbName); PgTransaction data(dbName);
// check to see that the backend connection was successfully made // check to see that the backend connection was successfully made
if ( data.ConnectionBad() ) { if ( data.ConnectionBad() )
{
cerr << "Connection to database '" << dbName << "' failed." << endl cerr << "Connection to database '" << dbName << "' failed." << endl
<< data.ErrorMessage(); << data.ErrorMessage();
exit(1); exit(1);
} }
else cout << "Connected to database '" << dbName << "'..." << endl; else
cout << "Connected to database '" << dbName << "'..." << endl;
// Create a new table // Create a new table
if ( !data.ExecCommandOk("CREATE TABLE foo (a int4, b char(16), d float8)") ) { if ( !data.ExecCommandOk("CREATE TABLE foo (a int4, b char(16), d float8)") )
{
cerr << "CREATE TABLE foo command failed" << endl; cerr << "CREATE TABLE foo command failed" << endl;
exit(1); exit(1);
} }
else cout << "CREATEd TABLE foo successfully.." << endl; else
cout << "CREATEd TABLE foo successfully.." << endl;
// Initiate Copy command // Initiate Copy command
if ( data.ExecCommandOk("COPY foo FROM STDIN") ) { if ( data.ExecCommandOk("COPY foo FROM STDIN") )
{
cerr << "COPY foo FROM STDIN" << endl; cerr << "COPY foo FROM STDIN" << endl;
exit(1); exit(1);
} }
else cout << "COPY foo FROM STDIN was successful.." << endl; else
cout << "COPY foo FROM STDIN was successful.." << endl;
// Put some test data into the table // Put some test data into the table
data.PutLine("3\thello world\t4.5\n"); data.PutLine("3\thello world\t4.5\n");
@ -47,12 +53,14 @@ int main()
cout << "Line: \"\\.\" copied..." << endl; cout << "Line: \"\\.\" copied..." << endl;
if ( !data.EndCopy() ) if ( !data.EndCopy() )
cout << "Ended COPY succesfully..." << endl; cout << "Ended COPY succesfully..." << endl;
else cerr << "End Copy failed..." << endl; else
cerr << "End Copy failed..." << endl;
// Print the data that was inserted into the table // Print the data that was inserted into the table
if ( data.ExecTuplesOk("SELECT * FROM foo") ) if ( data.ExecTuplesOk("SELECT * FROM foo") )
data.PrintTuples(); data.PrintTuples();
else cerr << "SELECT * FROM foo failed..." << endl; else
cerr << "SELECT * FROM foo failed..." << endl;
// Drop the test table // Drop the test table
data.Exec("DROP TABLE foo"); data.Exec("DROP TABLE foo");

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlo.cc,v 1.8 2000/05/29 21:25:04 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlo.cc,v 1.9 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -18,7 +18,8 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// Check if the program was invoked correctly; if not, signal error // Check if the program was invoked correctly; if not, signal error
if (argc < 4 || argc > 5) { if (argc < 4 || argc > 5)
{
cerr << "Usage: " << argv[0] << " conninfo_str in_filename out_filename [oid]" << endl; cerr << "Usage: " << argv[0] << " conninfo_str in_filename out_filename [oid]" << endl;
exit(1); exit(1);
} }
@ -33,7 +34,8 @@ int main(int argc, char **argv)
PgLargeObject object(lobjId, conninfo); PgLargeObject object(lobjId, conninfo);
// check to see that the backend connection was successfully made // check to see that the backend connection was successfully made
if ( object.ConnectionBad() ) { if ( object.ConnectionBad() )
{
cerr << "Connection with conninfo '" << conninfo << "' failed." << endl cerr << "Connection with conninfo '" << conninfo << "' failed." << endl
<< object.ErrorMessage(); << object.ErrorMessage();
exit(1); exit(1);

View File

@ -16,7 +16,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, 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.12 2002/06/20 20:29:54 momjian Exp $ * $Id: libpq++.h,v 1.13 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */

View File

@ -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.14 2002/06/15 18:49:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.15 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -34,6 +34,7 @@ PgConnection::PgConnection()
// constructor -- checks environment variable for database name // constructor -- checks environment variable for database name
// Now uses PQconnectdb // Now uses PQconnectdb
PgConnection::PgConnection(const char* conninfo) PgConnection::PgConnection(const char* conninfo)
: pgConn(NULL), pgResult(NULL), pgCloseConnection(true) : pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
{ {
@ -57,7 +58,8 @@ 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) if (pgResult)
PQclear(pgResult); PQclear(pgResult);
pgResult = NULL; pgResult = NULL;

View File

@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, 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.18 2002/06/20 20:29:54 momjian Exp $ * $Id: pgconnection.h,v 1.19 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -21,7 +21,8 @@
#ifndef PGCONNECTION_H #ifndef PGCONNECTION_H
#define PGCONNECTION_H #define PGCONNECTION_H
extern "C" { extern "C"
{
#include "pg_config.h" #include "pg_config.h"
} }
@ -37,7 +38,8 @@ extern "C" {
#include <string> #include <string>
#endif #endif
extern "C" { extern "C"
{
#include "libpq-fe.h" #include "libpq-fe.h"
} }
@ -56,7 +58,8 @@ extern "C" {
// This class contains all the information about the connection // This class contains all the information about the connection
// to the backend process. All the database classes should be // to the backend process. All the database classes should be
// derived from this class to obtain the connection interface. // derived from this class to obtain the connection interface.
class DLLIMPORT PgConnection { class DLLIMPORT PgConnection
{
protected: protected:
PGconn* pgConn; // Connection Structure PGconn* pgConn; // Connection Structure
PGresult* pgResult; // Current Query Result PGresult* pgResult; // Current Query Result

View File

@ -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.7 2002/06/15 18:49:29 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.8 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -41,6 +41,7 @@ PgCursor::PgCursor(const char* conninfo, const char* cursor)
//{} //{}
// Destructor: End the transaction block // Destructor: End the transaction block
PgCursor::~PgCursor() PgCursor::~PgCursor()
{ {
Close(); Close();

View File

@ -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.11 2002/06/20 20:29:54 momjian Exp $ * $Id: pgcursordb.h,v 1.12 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -41,7 +41,8 @@
// manipulates data through it. The interface will introduce some // manipulates data through it. The interface will introduce some
// ease of use through the methods that will allow cursor specific // ease of use through the methods that will allow cursor specific
// operations, like fetch, forward, etc. // operations, like fetch, forward, etc.
class DLLIMPORT PgCursor : public PgTransaction { class DLLIMPORT PgCursor : public PgTransaction
{
public: public:
PgCursor(const char* conninfo, const char* cursor); // use reasonable & environment defaults PgCursor(const char* conninfo, const char* cursor); // use reasonable & environment defaults
// connect to the database with given environment and database name // connect to the database with given environment and database name
@ -55,10 +56,16 @@ public:
int Close(); // Close the cursor int Close(); // Close the cursor
// Accessors to the cursor name // Accessors to the cursor name
const char* Cursor() const { return pgCursor.c_str(); } const char* Cursor() const
{
return pgCursor.c_str();
}
// TODO: Setter has same name as getter--ouch! // TODO: Setter has same name as getter--ouch!
// OBSOLESCENT // OBSOLESCENT
void Cursor(PGSTD string cursor) { pgCursor = cursor; } void Cursor(PGSTD string cursor)
{
pgCursor = cursor;
}
protected: protected:
int Fetch(PGSTD string num, PGSTD string dir); int Fetch(PGSTD string num, PGSTD string dir);
@ -67,14 +74,17 @@ protected:
PGSTD string pgCursor; PGSTD string pgCursor;
protected: protected:
PgCursor() : PgTransaction() {} // Do not connect PgCursor() : PgTransaction()
{} // Do not connect
private: private:
// We don't support copying of PgCursor objects, // We don't support copying of PgCursor objects,
// so make copy constructor and assignment op private. // so make copy constructor and assignment op private.
PgCursor(const PgCursor&); PgCursor(const PgCursor&);
PgCursor& operator= (const PgCursor&); PgCursor& operator= (const PgCursor&);
}; // End PgCursor Class Declaration }
; // End PgCursor Class Declaration
#undef PGSTD #undef PGSTD

View File

@ -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/pgdatabase.cc,v 1.12 2001/09/30 22:30:37 tgl Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.13 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */

View File

@ -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: pgdatabase.h,v 1.13 2002/06/20 20:29:54 momjian Exp $ * $Id: pgdatabase.h,v 1.14 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -34,12 +34,16 @@
// This is the basic database access class. Its interface should // This is the basic database access class. Its interface should
// be used only after a query has been sent to the backend and // be used only after a query has been sent to the backend and
// results are being received. // results are being received.
class DLLIMPORT PgDatabase : public PgConnection { class DLLIMPORT PgDatabase : public PgConnection
{
public: public:
// connect to the database with conninfo // connect to the database with conninfo
explicit PgDatabase(const char* conninfo) : PgConnection(conninfo) {} explicit PgDatabase(const char* conninfo) : PgConnection(conninfo)
{}
~PgDatabase()
{} // close connection and clean up
~PgDatabase() {} // close connection and clean up
typedef int size_type; typedef int size_type;
@ -73,7 +77,9 @@ public:
int EndCopy(); int EndCopy();
protected: protected:
PgDatabase() : PgConnection() {} // Do not connect PgDatabase() : PgConnection()
{} // Do not connect
private: private:
// We don't support copying of PgDatabase objects, // We don't support copying of PgDatabase objects,

View File

@ -10,14 +10,15 @@
* 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.10 2002/06/15 19:30:40 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.11 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "pglobject.h" #include "pglobject.h"
extern "C" { extern "C"
{
#include "libpq/libpq-fs.h" #include "libpq/libpq-fs.h"
} }
@ -38,7 +39,8 @@ PgLargeObject::PgLargeObject(const char* conninfo)
: PgConnection(conninfo) : PgConnection(conninfo)
{ {
Init(); Init();
if (! ConnectionBad()) { if (! ConnectionBad())
{
Create(); Create();
Open(); Open();
} }
@ -51,7 +53,8 @@ PgLargeObject::PgLargeObject(Oid lobjId, const char* conninfo)
: PgConnection(conninfo) : PgConnection(conninfo)
{ {
Init(lobjId); Init(lobjId);
if (! ConnectionBad()) { if (! ConnectionBad())
{
if ( !pgObject ) if ( !pgObject )
Create(); Create();
Open(); Open();
@ -111,7 +114,8 @@ int PgLargeObject::Unlink()
int temp = lo_unlink(pgConn, pgObject); int temp = lo_unlink(pgConn, pgObject);
// Initialize the large object upon success // Initialize the large object upon success
if (!temp) { if (!temp)
{
Close(); Close();
Init(); Init();
} }
@ -123,7 +127,8 @@ int PgLargeObject::Unlink()
void PgLargeObject::Close() void PgLargeObject::Close()
{ {
if (pgFd >= 0) lo_close(pgConn, pgFd); if (pgFd >= 0)
lo_close(pgConn, pgFd);
pgFd = -1; pgFd = -1;
} }
@ -169,6 +174,7 @@ string PgLargeObject::Status() const
return loStatus; return loStatus;
} }
Oid PgLargeObject::LOid(){ Oid PgLargeObject::LOid()
{
return pgObject; return pgObject;
} }

View File

@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* *
* $Id: pglobject.h,v 1.10 2002/06/20 20:29:54 momjian Exp $ * $Id: pglobject.h,v 1.11 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -35,7 +35,8 @@
// PgLargeObject - a class for accessing Large Object in a database // PgLargeObject - a class for accessing Large Object in a database
// //
// **************************************************************** // ****************************************************************
class DLLIMPORT PgLargeObject : public PgConnection { class DLLIMPORT PgLargeObject : public PgConnection
{
private: private:
int pgFd; int pgFd;
Oid pgObject; Oid pgObject;

View File

@ -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/pgtransdb.cc,v 1.4 2001/05/09 17:29:10 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgtransdb.cc,v 1.5 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -34,7 +34,8 @@ PgTransaction::PgTransaction(const char* conninfo)
// Destructor: End the transaction block // Destructor: End the transaction block
PgTransaction::~PgTransaction() PgTransaction::~PgTransaction()
{ {
if (!pgCommitted) Exec("ABORT"); if (!pgCommitted)
Exec("ABORT");
} }
// Begin the transaction block // Begin the transaction block

View File

@ -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: pgtransdb.h,v 1.9 2002/06/20 20:29:54 momjian Exp $ * $Id: pgtransdb.h,v 1.10 2002/07/02 16:32:19 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -34,7 +34,8 @@
// This is the database access class that keeps an open // This is the database access class that keeps an open
// transaction block during its lifetime. The block is ENDed when // transaction block during its lifetime. The block is ENDed when
// the object is destroyed. // the object is destroyed.
class DLLIMPORT PgTransaction : public PgDatabase { class DLLIMPORT PgTransaction : public PgDatabase
{
public: public:
explicit 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 // connect to the database with given environment and database name
@ -46,7 +47,9 @@ protected:
ExecStatusType EndTransaction(); ExecStatusType EndTransaction();
protected: protected:
PgTransaction() : PgDatabase(), pgCommitted(true) {} // Do not connect PgTransaction() : PgDatabase(), pgCommitted(true)
{} // Do not connect
private: private:
bool pgCommitted; bool pgCommitted;
@ -55,6 +58,7 @@ private:
// so make copy constructor and assignment op private. // so make copy constructor and assignment op private.
PgTransaction(const PgTransaction&); PgTransaction(const PgTransaction&);
PgTransaction& operator= (const PgTransaction&); PgTransaction& operator= (const PgTransaction&);
}; // End PgTransaction Class Declaration }
; // End PgTransaction Class Declaration
#endif // PGTRANSDB_H #endif // PGTRANSDB_H