Commit a4485ea8 authored by Bruce Momjian's avatar Bruce Momjian

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

will make fixing things easier.
parent c9a73452
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* testlibpq0.c-- * testlibpq0.c--
* small test program for libpq++, * small test program for libpq++,
* small interactive loop where queries can be entered interactively * small interactive loop where queries can be entered interactively
* and sent to the backend * and sent to the backend
* *
* 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++/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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include <iostream.h> #include <iostream.h>
#include "libpq++.h" #include "libpq++.h"
...@@ -21,7 +21,8 @@ int main() ...@@ -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;
......
/* /*
* testlibpq1.cc * testlibpq1.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library. * Test the C++ version of LIBPQ, the POSTGRES frontend library.
* *
* queries the template1 database for a list of database names * queries the template1 database for a list of database names
* *
*/ */
#include <iostream.h> #include <iostream.h>
#include <iomanip.h> #include <iomanip.h>
...@@ -20,40 +20,45 @@ int main() ...@@ -20,40 +20,45 @@ 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);
} }
// first, print out the attribute names // first, print out the attribute names
int nFields = data.Fields(); int nFields = data.Fields();
for (int i=0; i < nFields; i++) for (int i = 0; i < nFields; i++)
cout << setiosflags(ios::right) << setw(15) << data.FieldName(i); cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
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++) {
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i,j); for (int j = 0; j < nFields; j++)
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j);
cout << endl; cout << endl;
} }
......
/* /*
* testlibpq2.cc * testlibpq2.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library. * Test the C++ version of LIBPQ, the POSTGRES frontend library.
* *
* queries the template1 database for a list of database names using transaction block * queries the template1 database for a list of database names using transaction block
* *
*/ */
#include <iostream.h> #include <iostream.h>
#include <iomanip.h> #include <iomanip.h>
...@@ -20,34 +20,38 @@ int main() ...@@ -20,34 +20,38 @@ 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);
} }
// first, print out the attribute names // first, print out the attribute names
int nFields = data.Fields(); int nFields = data.Fields();
for (int i=0; i < nFields; i++) for (int i = 0; i < nFields; i++)
cout << setiosflags(ios::right) << setw(15) << data.FieldName(i); cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
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++) {
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i,j); for (int j = 0; j < nFields; j++)
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j);
cout << endl; cout << endl;
} }
......
/* /*
* testlibpq3.cc * testlibpq3.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library. * Test the C++ version of LIBPQ, the POSTGRES frontend library.
* *
* queries the template1 database for a list of database names using transaction block * queries the template1 database for a list of database names using transaction block
* and cursor interface. * and cursor interface.
* *
*/ */
#include <iostream.h> #include <iostream.h>
#include <iomanip.h> #include <iomanip.h>
...@@ -23,34 +23,38 @@ int main() ...@@ -23,34 +23,38 @@ 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);
} }
// first, print out the attribute names // first, print out the attribute names
int nFields = cData.Fields(); int nFields = cData.Fields();
for (int i=0; i < nFields; i++) for (int i = 0; i < nFields; i++)
cout << setiosflags(ios::right) << setw(15) << cData.FieldName(i); cout << setiosflags(ios::right) << setw(15) << cData.FieldName(i);
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++) {
cout << setiosflags(ios::right) << setw(15) << cData.GetValue(i,j); for (int j = 0; j < nFields; j++)
cout << setiosflags(ios::right) << setw(15) << cData.GetValue(i, j);
cout << endl; cout << endl;
} }
return 0; return 0;
......
/* /*
* testlibpq4.cc * testlibpq4.cc
* Test of the asynchronous notification interface * Test of the asynchronous notification interface
* *
populate a test database with the following (use testlibpq4.sql): populate a test database with the following (use testlibpq4.sql):
CREATE TABLE TBL1 (i int4); CREATE TABLE TBL1 (i int4);
...@@ -10,14 +10,14 @@ CREATE TABLE TBL2 (i int4); ...@@ -10,14 +10,14 @@ CREATE TABLE TBL2 (i int4);
CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values (new.i); NOTIFY TBL2]; CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values (new.i); NOTIFY TBL2];
* Then start up this program * Then start up this program
* After the program has begun, do * After the program has begun, do
INSERT INTO TBL1 values (10); INSERT INTO TBL1 values (10);
* *
* *
*/ */
#include <iostream.h> #include <iostream.h>
#include "libpq++.h" #include "libpq++.h"
#include <stdlib.h> #include <stdlib.h>
...@@ -31,23 +31,27 @@ int main() ...@@ -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;
......
/* /*
* testlibpq5.cc * testlibpq5.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library. * Test the C++ version of LIBPQ, the POSTGRES frontend library.
* tests the binary cursor interface * tests the binary cursor interface
* *
* *
* *
populate a database by doing the following (use testlibpq5.sql): populate a database by doing the following (use testlibpq5.sql):
CREATE TABLE test1 (i int4, d float4, p polygon); CREATE TABLE test1 (i int4, d float4, p polygon);
...@@ -13,23 +13,24 @@ INSERT INTO test1 values (1, 3.567, '(3.0, 4.0, 1.0, 2.0)'::polygon); ...@@ -13,23 +13,24 @@ INSERT INTO test1 values (1, 3.567, '(3.0, 4.0, 1.0, 2.0)'::polygon);
INSERT INTO test1 values (2, 89.05, '(4.0, 3.0, 2.0, 1.0)'::polygon); INSERT INTO test1 values (2, 89.05, '(4.0, 3.0, 2.0, 1.0)'::polygon);
the expected output is: the expected output is:
tuple 0: got tuple 0: got
i = (4 bytes) 1, i = (4 bytes) 1,
d = (4 bytes) 3.567000, d = (4 bytes) 3.567000,
p = (4 bytes) 2 points boundbox = (hi=3.000000/4.000000, lo = 1.000000,2.000000) p = (4 bytes) 2 points boundbox = (hi=3.000000/4.000000, lo = 1.000000,2.000000)
tuple 1: got tuple 1: got
i = (4 bytes) 2, i = (4 bytes) 2,
d = (4 bytes) 89.050003, d = (4 bytes) 89.050003,
p = (4 bytes) 2 points boundbox = (hi=4.000000/3.000000, lo = 2.000000,1.000000) p = (4 bytes) 2 points boundbox = (hi=4.000000/3.000000, lo = 2.000000,1.000000)
* *
*/ */
#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() ...@@ -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);
} }
...@@ -66,33 +70,34 @@ int main() ...@@ -66,33 +70,34 @@ int main()
int d_fnum = data.FieldNum("d"); int d_fnum = data.FieldNum("d");
int p_fnum = data.FieldNum("p"); int p_fnum = data.FieldNum("p");
/* /*
for (i=0;i<3;i++) { for (i=0;i<3;i++) {
printf("type[%d] = %d, size[%d] = %d\n", printf("type[%d] = %d, size[%d] = %d\n",
i, data.FieldType(i), i, data.FieldType(i),
i, data.FieldSize(i)); i, data.FieldSize(i));
} }
*/ */
// 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);
int plen = data.GetLength(i,p_fnum); int plen = data.GetLength(i, p_fnum);
// Allocate correct memory space for the Polygon struct and copy // Allocate correct memory space for the Polygon struct and copy
// the extracted data into it. // the extracted data into it.
// plen doesn't include the length field so need to increment by VARHDSZ // plen doesn't include the length field so need to increment by VARHDSZ
POLYGON* pval = (POLYGON*) malloc(plen + VARHDRSZ); POLYGON* pval = (POLYGON*) malloc(plen + VARHDRSZ);
pval->size = plen; pval->size = plen;
memmove((char*)&pval->npts, data.GetValue(i,p_fnum), plen); memmove((char*)&pval->npts, data.GetValue(i, p_fnum), plen);
// Display Polygon Information // Display Polygon Information
cout << "tuple " << i << ": got" << endl cout << "tuple " << i << ": got" << endl
<< " i = (" << data.GetLength(i,i_fnum) << " bytes) " << *ival << "," << endl << " i = (" << data.GetLength(i, i_fnum) << " bytes) " << *ival << "," << endl
<< " d = (" << data.GetLength(i,d_fnum) << " bytes) " << *dval << "," << endl << " d = (" << data.GetLength(i, d_fnum) << " bytes) " << *dval << "," << endl
<< " p = (" << data.GetLength(i,d_fnum) << " bytes) " << pval->npts << " points" << " p = (" << data.GetLength(i, d_fnum) << " bytes) " << pval->npts << " points"
<< "\tboundbox = (hi=" << pval->boundbox.high.x << "/" << pval->boundbox.high.y << "," << "\tboundbox = (hi=" << pval->boundbox.high.x << "/" << pval->boundbox.high.y << ","
<< "lo = " << pval->boundbox.low.x << "," << pval->boundbox.low.y << ")" << endl; << "lo = " << pval->boundbox.low.x << "," << pval->boundbox.low.y << ")" << endl;
......
/* /*
* testlibpq4.cc * testlibpq4.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library. * Test the C++ version of LIBPQ, the POSTGRES frontend library.
* tests the copy in features * tests the copy in features
* *
*/ */
#include <iostream.h> #include <iostream.h>
#include "libpq++.h" #include "libpq++.h"
#include <stdlib.h> #include <stdlib.h>
...@@ -17,26 +17,32 @@ int main() ...@@ -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() ...@@ -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");
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* lotest.cc-- * lotest.cc--
* test using large objects with libpq * test using large objects with libpq
* *
* 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++/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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include <iostream.h> #include <iostream.h>
#include "libpq++.h" #include "libpq++.h"
#include <stdlib.h> #include <stdlib.h>
...@@ -18,7 +18,8 @@ ...@@ -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) ...@@ -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);
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* libpq++.h * libpq++.h
* *
* *
* DESCRIPTION * DESCRIPTION
* C++ client interface to Postgres * C++ client interface to Postgres
* used for building front-end applications * used for building front-end applications
* *
* NOTES * NOTES
* This is intended to be included by client applications. * This is intended to be included by client applications.
* It will not work as an inclusion in the libpq++ sources, since * It will not work as an inclusion in the libpq++ sources, since
* in the build environment the individual include files are not * in the build environment the individual include files are not
* yet installed in a subdirectory. * yet installed in a subdirectory.
* *
* 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef LIBPQXX_H #ifndef LIBPQXX_H
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* FILE * FILE
* pgconnection.cc * pgconnection.cc
* *
* DESCRIPTION * DESCRIPTION
* implementation of the PgConnection class. * implementation of the PgConnection class.
* PgConnection encapsulates a frontend to backend connection * PgConnection encapsulates a frontend to backend connection
* *
* 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "pgconnection.h" #include "pgconnection.h"
...@@ -34,6 +34,7 @@ PgConnection::PgConnection() ...@@ -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() ...@@ -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;
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* pgconnection.h * pgconnection.h
* *
* *
* DESCRIPTION * DESCRIPTION
* Postgres Connection Class: * Postgres Connection Class:
* Manage Postgres backend connection * Manage Postgres backend connection
* *
* NOTES * NOTES
* Currently under construction. * Currently under construction.
* *
* 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#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" { ...@@ -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" { ...@@ -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
...@@ -91,8 +94,8 @@ protected: ...@@ -91,8 +94,8 @@ protected:
PgConnection(); PgConnection();
private: private:
// We don't support copying of PgConnection objects, // We don't support copying of PgConnection objects,
// so make copy constructor and assignment op private. // so make copy constructor and assignment op private.
PgConnection(const PgConnection&); PgConnection(const PgConnection&);
PgConnection& operator= (const PgConnection&); PgConnection& operator= (const PgConnection&);
}; };
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* FILE * FILE
* pgcursordb.cpp * pgcursordb.cpp
* *
* DESCRIPTION * DESCRIPTION
* implementation of the PgCursor class. * implementation of the PgCursor class.
* PgCursor encapsulates a cursor interface to the backend * PgCursor encapsulates a cursor interface to the backend
* *
* 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "pgcursordb.h" #include "pgcursordb.h"
...@@ -41,6 +41,7 @@ PgCursor::PgCursor(const char* conninfo, const char* cursor) ...@@ -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();
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* pgcursordb.h * pgcursordb.h
* *
* *
* DESCRIPTION * DESCRIPTION
* Postgres Cursor Database Class: * Postgres Cursor Database Class:
* Query Postgres backend using a cursor * Query Postgres backend using a cursor
* *
* NOTES * NOTES
* Currently under construction. * Currently under construction.
* *
* 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: 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef PGCURSORDB_H #ifndef PGCURSORDB_H
#define PGCURSORDB_H #define PGCURSORDB_H
...@@ -41,7 +41,8 @@ ...@@ -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: ...@@ -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: ...@@ -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
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* FILE * FILE
* pgdatabase.cpp * pgdatabase.cpp
* *
* DESCRIPTION * DESCRIPTION
* implementation of the PgDatabase class. * implementation of the PgDatabase class.
* PgDatabase encapsulates some utility routines * PgDatabase encapsulates some utility routines
* *
* 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "pgdatabase.h" #include "pgdatabase.h"
...@@ -38,7 +38,7 @@ void PgDatabase::DisplayTuples(FILE *out, ...@@ -38,7 +38,7 @@ void PgDatabase::DisplayTuples(FILE *out,
po.tableOpt = po.caption = 0; po.tableOpt = po.caption = 0;
po.fieldName = 0; po.fieldName = 0;
PQprint(out,pgResult,&po); PQprint(out, pgResult, &po);
} }
...@@ -58,124 +58,124 @@ void PgDatabase::PrintTuples(FILE *out, ...@@ -58,124 +58,124 @@ void PgDatabase::PrintTuples(FILE *out,
po.fieldSep = (char *) (terseOutput ? "" : "|"); po.fieldSep = (char *) (terseOutput ? "" : "|");
po.fieldName = 0; po.fieldName = 0;
PQprint(out,pgResult,&po); PQprint(out, pgResult, &po);
} }
int PgDatabase::Tuples() const int PgDatabase::Tuples() const
{ {
return PQntuples(pgResult); return PQntuples(pgResult);
} }
int PgDatabase::CmdTuples() const int PgDatabase::CmdTuples() const
{ {
const char *a = PQcmdTuples(pgResult); const char *a = PQcmdTuples(pgResult);
return a[0] ? atoi(a) : -1; return a[0] ? atoi(a) : -1;
} }
// TODO: Make const? // TODO: Make const?
int PgDatabase::Fields() int PgDatabase::Fields()
{ {
return PQnfields(pgResult); return PQnfields(pgResult);
} }
const char* PgDatabase::FieldName(int field_num) const const char* PgDatabase::FieldName(int field_num) const
{ {
return PQfname(pgResult, field_num); return PQfname(pgResult, field_num);
} }
int PgDatabase::FieldNum(const char* field_name) const int PgDatabase::FieldNum(const char* field_name) const
{ {
return PQfnumber(pgResult, field_name); return PQfnumber(pgResult, field_name);
} }
Oid PgDatabase::FieldType(int field_num) const Oid PgDatabase::FieldType(int field_num) const
{ {
return PQftype(pgResult, field_num); return PQftype(pgResult, field_num);
} }
Oid PgDatabase::FieldType(const char* field_name) const Oid PgDatabase::FieldType(const char* field_name) const
{ {
return PQftype(pgResult, FieldNum(field_name)); return PQftype(pgResult, FieldNum(field_name));
} }
int PgDatabase::FieldSize(int field_num) const int PgDatabase::FieldSize(int field_num) const
{ {
return PQfsize(pgResult, field_num); return PQfsize(pgResult, field_num);
} }
int PgDatabase::FieldSize(const char* field_name) const int PgDatabase::FieldSize(const char* field_name) const
{ {
return PQfsize(pgResult, FieldNum(field_name)); return PQfsize(pgResult, FieldNum(field_name));
} }
const char* PgDatabase::GetValue(int tup_num, int field_num) const const char* PgDatabase::GetValue(int tup_num, int field_num) const
{ {
return PQgetvalue(pgResult, tup_num, field_num); return PQgetvalue(pgResult, tup_num, field_num);
} }
const char* PgDatabase::GetValue(int tup_num, const char* field_name) const const char* PgDatabase::GetValue(int tup_num, const char* field_name) const
{ {
return PQgetvalue(pgResult, tup_num, FieldNum(field_name)); return PQgetvalue(pgResult, tup_num, FieldNum(field_name));
} }
bool PgDatabase::GetIsNull(int tup_num, int field_num) const bool PgDatabase::GetIsNull(int tup_num, int field_num) const
{ {
return PQgetisnull(pgResult, tup_num, field_num); return PQgetisnull(pgResult, tup_num, field_num);
} }
bool PgDatabase::GetIsNull(int tup_num, const char* field_name) const bool PgDatabase::GetIsNull(int tup_num, const char* field_name) const
{ {
return PQgetisnull(pgResult, tup_num, FieldNum(field_name)); return PQgetisnull(pgResult, tup_num, FieldNum(field_name));
} }
int PgDatabase::GetLength(int tup_num, int field_num) const int PgDatabase::GetLength(int tup_num, int field_num) const
{ {
return PQgetlength(pgResult, tup_num, field_num); return PQgetlength(pgResult, tup_num, field_num);
} }
int PgDatabase::GetLength(int tup_num, const char* field_name) const int PgDatabase::GetLength(int tup_num, const char* field_name) const
{ {
return PQgetlength(pgResult, tup_num, FieldNum(field_name)); return PQgetlength(pgResult, tup_num, FieldNum(field_name));
} }
int PgDatabase::GetLine(char str[], int length) int PgDatabase::GetLine(char str[], int length)
{ {
return PQgetline(pgConn, str, length); return PQgetline(pgConn, str, length);
} }
void PgDatabase::PutLine(const char str[]) void PgDatabase::PutLine(const char str[])
{ {
PQputline(pgConn, str); PQputline(pgConn, str);
} }
const char* PgDatabase::OidStatus() const const char* PgDatabase::OidStatus() const
{ {
return PQoidStatus(pgResult); return PQoidStatus(pgResult);
} }
int PgDatabase::EndCopy() int PgDatabase::EndCopy()
{ {
return PQendcopy(pgConn); return PQendcopy(pgConn);
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* pgdatabase.h * pgdatabase.h
* *
* *
* DESCRIPTION * DESCRIPTION
* Postgres Database Class: * Postgres Database Class:
* Query Postgres backend to obtain query results * Query Postgres backend to obtain query results
* *
* NOTES * NOTES
* Currently under construction. * Currently under construction.
* *
* 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: 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef PGDATABASE_H #ifndef PGDATABASE_H
#define PGDATABASE_H #define PGDATABASE_H
...@@ -34,12 +34,16 @@ ...@@ -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;
...@@ -61,10 +65,10 @@ public: ...@@ -61,10 +65,10 @@ public:
int GetLength(size_type tup_num, const char* field_name) const; int GetLength(size_type tup_num, const char* field_name) const;
// OBSOLESCENT (use PQprint()): // OBSOLESCENT (use PQprint()):
void DisplayTuples(FILE *out=0, bool fillAlign=true, void DisplayTuples(FILE *out = 0, bool fillAlign = true,
const char* fieldSep="|", bool printHeader=true, bool quiet=false) const; const char* fieldSep = "|", bool printHeader = true, bool quiet = false) const;
void PrintTuples(FILE *out=0, bool printAttName=true, void PrintTuples(FILE *out = 0, bool printAttName = true,
bool terseOutput=false, bool fillAlign=false) const; bool terseOutput = false, bool fillAlign = false) const;
// copy command related access // copy command related access
int GetLine(char str[], int length); int GetLine(char str[], int length);
...@@ -73,11 +77,13 @@ public: ...@@ -73,11 +77,13 @@ 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,
// so make copy constructor and assignment op private. // so make copy constructor and assignment op private.
PgDatabase(const PgDatabase&); PgDatabase(const PgDatabase&);
PgDatabase& operator= (const PgDatabase&); PgDatabase& operator= (const PgDatabase&);
}; };
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* FILE * FILE
* pglobject.cc * pglobject.cc
* *
* DESCRIPTION * DESCRIPTION
* implementation of the PgLargeObject class. * implementation of the PgLargeObject class.
* PgLargeObject encapsulates a frontend to backend connection * PgLargeObject encapsulates a frontend to backend connection
* *
* 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) ...@@ -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) ...@@ -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();
...@@ -77,7 +80,7 @@ void PgLargeObject::Init(Oid lobjId) ...@@ -77,7 +80,7 @@ void PgLargeObject::Init(Oid lobjId)
void PgLargeObject::Create() void PgLargeObject::Create()
{ {
// Create the object // Create the object
pgObject = lo_creat(pgConn, INV_READ|INV_WRITE); pgObject = lo_creat(pgConn, INV_READ | INV_WRITE);
// Check for possible errors // Check for possible errors
if (!pgObject) if (!pgObject)
...@@ -93,7 +96,7 @@ void PgLargeObject::Open() ...@@ -93,7 +96,7 @@ void PgLargeObject::Open()
// Close any prior object // Close any prior object
Close(); Close();
// Open the object // Open the object
pgFd = lo_open(pgConn, pgObject, INV_READ|INV_WRITE); pgFd = lo_open(pgConn, pgObject, INV_READ | INV_WRITE);
// Check for possible errors // Check for possible errors
string objStr( IntToString(pgObject) ); string objStr( IntToString(pgObject) );
...@@ -111,7 +114,8 @@ int PgLargeObject::Unlink() ...@@ -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() ...@@ -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 ...@@ -169,6 +174,7 @@ string PgLargeObject::Status() const
return loStatus; return loStatus;
} }
Oid PgLargeObject::LOid(){ Oid PgLargeObject::LOid()
{
return pgObject; return pgObject;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* FILE * FILE
* pglobject.h * pglobject.h
* *
* DESCRIPTION * DESCRIPTION
* declaration of the PGlobj class. * declaration of the PGlobj class.
* PGlobj encapsulates a large object interface to Postgres backend * PGlobj encapsulates a large object interface to Postgres backend
* *
* 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: 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef PGLOBJECT_H #ifndef PGLOBJECT_H
#define PGLOBJECT_H #define PGLOBJECT_H
...@@ -35,7 +35,8 @@ ...@@ -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;
...@@ -61,8 +62,8 @@ public: ...@@ -61,8 +62,8 @@ public:
PGSTD string Status() const; PGSTD string Status() const;
private: private:
// We don't support copying of PgLargeObject objects, // We don't support copying of PgLargeObject objects,
// so make copy constructor and assignment op private. // so make copy constructor and assignment op private.
PgLargeObject(const PgLargeObject&); PgLargeObject(const PgLargeObject&);
PgLargeObject& operator= (const PgLargeObject&); PgLargeObject& operator= (const PgLargeObject&);
}; };
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* FILE * FILE
* pgtransdb.cpp * pgtransdb.cpp
* *
* DESCRIPTION * DESCRIPTION
* implementation of the PgTransaction class. * implementation of the PgTransaction class.
* PgConnection encapsulates a transaction querying to backend * PgConnection encapsulates a transaction querying to backend
* *
* 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "pgtransdb.h" #include "pgtransdb.h"
...@@ -34,7 +34,8 @@ PgTransaction::PgTransaction(const char* conninfo) ...@@ -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
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* pgtransdb.h * pgtransdb.h
* *
* *
* DESCRIPTION * DESCRIPTION
* Postgres Transaction Database Class: * Postgres Transaction Database Class:
* Query Postgres backend using a transaction block * Query Postgres backend using a transaction block
* *
* NOTES * NOTES
* Currently under construction. * Currently under construction.
* *
* 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: 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef PGTRANSDB_H #ifndef PGTRANSDB_H
#define PGTRANSDB_H #define PGTRANSDB_H
...@@ -34,7 +34,8 @@ ...@@ -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,15 +47,18 @@ protected: ...@@ -46,15 +47,18 @@ 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;
// We don't support copying of PgTransaction objects, // We don't support copying of PgTransaction objects,
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment