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"
int main() 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 {
<< "Error message returned: " << data.ErrorMessage() << endl; cout << "Connection was unsuccessful..." << endl
return 1; << "Error message returned: " << data.ErrorMessage() << endl;
} return 1;
else }
cout << "Connection successful... Enter queries below:" << endl; else
cout << "Connection successful... Enter queries below:" << endl;
// Interactively obtain and execute queries
ExecStatusType status; // Interactively obtain and execute queries
string buf; ExecStatusType status;
int done = 0; string buf;
while (!done) int done = 0;
{ while (!done)
cout << "> "; {
cout.flush(); cout << "> ";
getline(cin, buf); cout.flush();
if ( buf != "" ) getline(cin, buf);
if ( (status = data.Exec( buf.c_str() )) == PGRES_TUPLES_OK ) if ( buf != "" )
data.DisplayTuples(); if ( (status = data.Exec( buf.c_str() )) == PGRES_TUPLES_OK )
else data.DisplayTuples();
cout << "No tuples returned..." << endl else
<< "status = " << status << endl cout << "No tuples returned..." << endl
<< "Error returned: " << data.ErrorMessage() << endl; << "status = " << status << endl
else << "Error returned: " << data.ErrorMessage() << endl;
done = 1; else
} done = 1;
return 0; }
return 0;
} // End main() } // End main()
/* /*
* 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>
...@@ -12,57 +12,62 @@ ...@@ -12,57 +12,62 @@
int main() int main()
{ {
// Begin, by establishing a connection to the backend. // Begin, by establishing a connection to the backend.
// When no parameters are given then the system will // When no parameters are given then the system will
// try to use reasonable defaults by looking up environment variables // try to use reasonable defaults by looking up environment variables
// or, failing that, using hardwired constants // or, failing that, using hardwired constants
const char* dbName = "dbname=template1"; const char* dbName = "dbname=template1";
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 {
<< "Error returned: " << data.ErrorMessage() << endl; cerr << "Connection to database '" << dbName << "' failed." << endl
exit(1); << "Error returned: " << data.ErrorMessage() << endl;
} exit(1);
}
// start a transaction block // start a transaction block
if ( !data.ExecCommandOk("BEGIN") ) { if ( !data.ExecCommandOk("BEGIN") )
cerr << "BEGIN command failed" << endl; {
exit(1); cerr << "BEGIN command failed" << endl;
} 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; {
exit(1); cerr << "DECLARE CURSOR command failed" << endl;
} 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; {
exit(1); cerr << "FETCH ALL command didn't return tuples properly" << endl;
} exit(1);
}
// first, print out the attribute names
int nFields = data.Fields();
for (int i=0; i < nFields; i++)
cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
cout << endl << endl;
// next, print out the instances // first, print out the attribute names
for (int i=0; i < data.Tuples(); i++) { int nFields = data.Fields();
for (int j=0; j < nFields; j++) for (int i = 0; i < nFields; i++)
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i,j); cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
cout << endl; cout << endl << endl;
}
// Close the portal // next, print out the instances
data.Exec("CLOSE myportal"); 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);
cout << endl;
}
// End the transaction // Close the portal
data.Exec("END"); data.Exec("CLOSE myportal");
return 0;
// End the transaction
data.Exec("END");
return 0;
} }
/* /*
* 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>
...@@ -12,46 +12,50 @@ ...@@ -12,46 +12,50 @@
int main() int main()
{ {
// Begin, by establishing a connection to the backend. // Begin, by establishing a connection to the backend.
// When no parameters are given then the system will // When no parameters are given then the system will
// try to use reasonable defaults by looking up environment variables // try to use reasonable defaults by looking up environment variables
// or, failing that, using hardwired constants // or, failing that, using hardwired constants
const char* dbName = "dbname=template1"; const char* dbName = "dbname=template1";
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 {
<< "Error returned: " << data.ErrorMessage() << endl; cerr << "Connection to database '" << dbName << "' failed." << endl
exit(1); << "Error returned: " << data.ErrorMessage() << endl;
} exit(1);
}
// submit command to the backend
if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") ) { // submit command to the backend
cerr << "DECLARE CURSOR command failed" << endl; if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") )
exit(1); {
} cerr << "DECLARE CURSOR command failed" << endl;
exit(1);
// fetch instances from the pg_database, the system catalog of databases }
if ( !data.ExecTuplesOk("FETCH ALL in myportal") ) {
cerr << "FETCH ALL command didn't return tuples properly" << endl; // fetch instances from the pg_database, the system catalog of databases
exit(1); if ( !data.ExecTuplesOk("FETCH ALL in myportal") )
} {
cerr << "FETCH ALL command didn't return tuples properly" << endl;
// first, print out the attribute names exit(1);
int nFields = data.Fields(); }
for (int i=0; i < nFields; i++)
cout << setiosflags(ios::right) << setw(15) << data.FieldName(i); // first, print out the attribute names
cout << endl << endl; int nFields = data.Fields();
for (int i = 0; i < nFields; i++)
// next, print out the instances cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
for (int i=0; i < data.Tuples(); i++) { cout << endl << endl;
for (int j=0; j < nFields; j++)
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i,j); // next, print out the instances
cout << endl; for (int i = 0; i < data.Tuples(); i++)
} {
for (int j = 0; j < nFields; j++)
// close the portal cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j);
data.Exec("CLOSE myportal"); cout << endl;
return 0; }
// close the portal
data.Exec("CLOSE myportal");
return 0;
} }
/* /*
* 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>
...@@ -13,45 +13,49 @@ ...@@ -13,45 +13,49 @@
int main() int main()
{ {
// Begin, by establishing a connection to the backend. // Begin, by establishing a connection to the backend.
// When no parameters are given then the system will // When no parameters are given then the system will
// try to use reasonable defaults by looking up environment variables // try to use reasonable defaults by looking up environment variables
// or, failing that, using hardwired constants. // or, failing that, using hardwired constants.
// Create a cursor database query object. // Create a cursor database query object.
// All queries using cursor will be performed through this object. // All queries using cursor will be performed through this object.
const char* dbName = "dbname=template1"; const char* dbName = "dbname=template1";
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 {
<< "Error returned: " << cData.ErrorMessage() << endl; cerr << "Connection to database '" << dbName << "' failed." << endl
exit(1); << "Error returned: " << cData.ErrorMessage() << endl;
} exit(1);
}
// submit command to the backend
if ( !cData.Declare("select * from pg_database") ) {
cerr << "DECLARE CURSOR command failed" << endl;
exit(1);
}
// fetch instances from the pg_cDatabase, the system catalog of cDatabases // submit command to the backend
if ( !cData.Fetch() ) { if ( !cData.Declare("select * from pg_database") )
cerr << "FETCH ALL command didn't return tuples properly" << endl; {
exit(1); cerr << "DECLARE CURSOR command failed" << endl;
} exit(1);
}
// first, print out the attribute names
int nFields = cData.Fields();
for (int i=0; i < nFields; i++)
cout << setiosflags(ios::right) << setw(15) << cData.FieldName(i);
cout << endl << endl;
// next, print out the instances // fetch instances from the pg_cDatabase, the system catalog of cDatabases
for (int i=0; i < cData.Tuples(); i++) { if ( !cData.Fetch() )
for (int j=0; j < nFields; j++) {
cout << setiosflags(ios::right) << setw(15) << cData.GetValue(i,j); cerr << "FETCH ALL command didn't return tuples properly" << endl;
cout << endl; exit(1);
} }
return 0;
// first, print out the attribute names
int nFields = cData.Fields();
for (int i = 0; i < nFields; i++)
cout << setiosflags(ios::right) << setw(15) << cData.FieldName(i);
cout << endl << endl;
// next, print out the instances
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);
cout << endl;
}
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,50 +10,54 @@ CREATE TABLE TBL2 (i int4); ...@@ -10,50 +10,54 @@ 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>
int main() int main()
{ {
// Begin, by connecting to the backend using hardwired constants // Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation // and a test database created by the user prior to the invokation
// of this test program. // of this test program.
const char* dbName = "dbname=template1"; const char* dbName = "dbname=template1";
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 {
<< data.ErrorMessage() << endl; cerr << "Connection to database '" << dbName << "' failed." << endl
exit(1); << data.ErrorMessage() << endl;
} exit(1);
}
// Listen to a table
if ( !data.ExecCommandOk("LISTEN TBL2") ) { // Listen to a table
cerr << "LISTEN command failed" << endl; if ( !data.ExecCommandOk("LISTEN TBL2") )
exit(1); {
} cerr << "LISTEN command failed" << endl;
exit(1);
// Test asynchronous notification }
while (1) {
// check for asynchronous returns // Test asynchronous notification
PGnotify* notify = data.Notifies(); while (1)
if (notify) { {
cerr << "ASYNC NOTIFY of '" << notify->relname // check for asynchronous returns
<< "' from backend pid '" << notify->be_pid PGnotify* notify = data.Notifies();
<< "' received" << endl; if (notify)
free(notify); {
break; cerr << "ASYNC NOTIFY of '" << notify->relname
} << "' from backend pid '" << notify->be_pid
} << "' received" << endl;
return 0; free(notify);
break;
}
}
return 0;
} }
/* /*
* 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);
INSERT INTO test1 values (1, 3.567, '(3.0, 4.0, 1.0, 2.0)'::polygon); 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
} }
int main() int main()
{ {
// Begin, by connecting to the backend using hardwired constants // Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation // and a test database created by the user prior to the invokation
// of this test program. Connect using cursor interface. // of this test program. Connect using cursor interface.
const char* dbName = "dbname=template1"; // change this to the name of your test database const char* dbName = "dbname=template1"; // change this to the name of your test database
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 {
<< data.ErrorMessage(); cerr << "Connection to database '" << dbName << "' failed." << endl
exit(1); << data.ErrorMessage();
} exit(1);
}
// Declare a binary cursor for all the tuples in database 'test1'
if ( !data.Declare("select * from test1", 1) ) { // Declare a binary cursor for all the tuples in database 'test1'
cerr << "DECLARE CURSOR command failed" << endl; if ( !data.Declare("select * from test1", 1) )
exit(1); {
} cerr << "DECLARE CURSOR command failed" << endl;
exit(1);
// fetch all instances from the current cursor }
if ( !data.Fetch() ) {
cerr << "FETCH ALL command didn't return tuples properly" << endl; // fetch all instances from the current cursor
exit(1); if ( !data.Fetch() )
} {
cerr << "FETCH ALL command didn't return tuples properly" << endl;
// Find the field numbers for the columns 'i', 'd', and 'p' exit(1);
int i_fnum = data.FieldNum("i"); }
int d_fnum = data.FieldNum("d");
int p_fnum = data.FieldNum("p"); // Find the field numbers for the columns 'i', 'd', and 'p'
int i_fnum = data.FieldNum("i");
/* int d_fnum = data.FieldNum("d");
for (i=0;i<3;i++) { int p_fnum = data.FieldNum("p");
printf("type[%d] = %d, size[%d] = %d\n",
i, data.FieldType(i), /*
i, data.FieldSize(i)); for (i=0;i<3;i++) {
} printf("type[%d] = %d, size[%d] = %d\n",
*/ i, data.FieldType(i),
i, data.FieldSize(i));
}
*/
// Print out the information about the extracted tuple
for (int i = 0; i < data.Tuples(); i++)
{
// we hard-wire this to the 3 fields we know about
int* ival = (int*)data.GetValue(i, i_fnum);
float* dval = (float*)data.GetValue(i, d_fnum);
int plen = data.GetLength(i, p_fnum);
// Allocate correct memory space for the Polygon struct and copy
// the extracted data into it.
// plen doesn't include the length field so need to increment by VARHDSZ
POLYGON* pval = (POLYGON*) malloc(plen + VARHDRSZ);
pval->size = plen;
memmove((char*)&pval->npts, data.GetValue(i, p_fnum), plen);
// Display Polygon Information
cout << "tuple " << i << ": got" << endl
<< " i = (" << data.GetLength(i, i_fnum) << " bytes) " << *ival << "," << endl
<< " d = (" << data.GetLength(i, d_fnum) << " bytes) " << *dval << "," << endl
<< " p = (" << data.GetLength(i, d_fnum) << " bytes) " << pval->npts << " points"
<< "\tboundbox = (hi=" << pval->boundbox.high.x << "/" << pval->boundbox.high.y << ","
<< "lo = " << pval->boundbox.low.x << "," << pval->boundbox.low.y << ")" << endl;
// Print out the information about the extracted tuple // Deallocate memory allocated for the Polygon structure
for (int i=0; i < data.Tuples(); i++) { free(pval);
// we hard-wire this to the 3 fields we know about }
int* ival = (int*)data.GetValue(i,i_fnum); return 0;
float* dval = (float*)data.GetValue(i,d_fnum);
int plen = data.GetLength(i,p_fnum);
// Allocate correct memory space for the Polygon struct and copy
// the extracted data into it.
// plen doesn't include the length field so need to increment by VARHDSZ
POLYGON* pval = (POLYGON*) malloc(plen + VARHDRSZ);
pval->size = plen;
memmove((char*)&pval->npts, data.GetValue(i,p_fnum), plen);
// Display Polygon Information
cout << "tuple " << i << ": got" << endl
<< " i = (" << data.GetLength(i,i_fnum) << " bytes) " << *ival << "," << endl
<< " d = (" << data.GetLength(i,d_fnum) << " bytes) " << *dval << "," << endl
<< " p = (" << data.GetLength(i,d_fnum) << " bytes) " << pval->npts << " points"
<< "\tboundbox = (hi=" << pval->boundbox.high.x << "/" << pval->boundbox.high.y << ","
<< "lo = " << pval->boundbox.low.x << "," << pval->boundbox.low.y << ")" << endl;
// Deallocate memory allocated for the Polygon structure
free(pval);
}
return 0;
} }
/* /*
* 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>
int main() int main()
{ {
// Begin, by connecting to the backend using hardwired constants // Begin, by connecting to the backend using hardwired constants
// and a test database created by the user prior to the invokation // and a test database created by the user prior to the invokation
// of this test program. Connect using transaction interface. // of this test program. Connect using transaction interface.
const char* dbName = "dbname=template1"; const char* dbName = "dbname=template1";
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 {
<< data.ErrorMessage(); cerr << "Connection to database '" << dbName << "' failed." << endl
exit(1); << data.ErrorMessage();
} 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; {
exit(1); cerr << "CREATE TABLE foo command failed" << endl;
} 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; {
exit(1); cerr << "COPY foo FROM STDIN" << endl;
} 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");
cout << "Line: \"3\thello world\t4.5\" copied..." << endl; cout << "Line: \"3\thello world\t4.5\" copied..." << endl;
data.PutLine("4\tgoodbye word\t7.11\n"); data.PutLine("4\tgoodbye word\t7.11\n");
cout << "Line: \"4\tgoodbye word\t7.11\" copied..." << endl; cout << "Line: \"4\tgoodbye word\t7.11\" copied..." << endl;
data.PutLine("\\.\n"); data.PutLine("\\.\n");
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
if ( data.ExecTuplesOk("SELECT * FROM foo") ) // Print the data that was inserted into the table
data.PrintTuples(); if ( data.ExecTuplesOk("SELECT * FROM foo") )
else cerr << "SELECT * FROM foo failed..." << endl; data.PrintTuples();
else
// Drop the test table cerr << "SELECT * FROM foo failed..." << endl;
data.Exec("DROP TABLE foo");
return 0; // Drop the test table
data.Exec("DROP TABLE foo");
return 0;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* 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>
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; {
exit(1); cerr << "Usage: " << argv[0] << " conninfo_str in_filename out_filename [oid]" << endl;
} exit(1);
}
// Get the arguments passed to the program // Get the arguments passed to the program
char* conninfo = argv[1]; char* conninfo = argv[1];
char* in_filename = argv[2]; char* in_filename = argv[2];
char* out_filename = argv[3]; char* out_filename = argv[3];
// Set up the connection and create a large object // Set up the connection and create a large object
int lobjId = ( argc == 4 ? 0 : atoi(argv[4]) ); int lobjId = ( argc == 4 ? 0 : atoi(argv[4]) );
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 {
<< object.ErrorMessage(); cerr << "Connection with conninfo '" << conninfo << "' failed." << endl
exit(1); << object.ErrorMessage();
} exit(1);
}
// Test the import and export features of the Large Object interface // Test the import and export features of the Large Object interface
object.Exec("BEGIN"); object.Exec("BEGIN");
cout << "Importing file \"" << in_filename << "\"..." << endl; cout << "Importing file \"" << in_filename << "\"..." << endl;
object.Import(in_filename); object.Import(in_filename);
cout << "Exporting large object to file \"" << out_filename << "\"..." << endl; cout << "Exporting large object to file \"" << out_filename << "\"..." << endl;
object.Export(out_filename); object.Export(out_filename);
object.Exec("END"); // WHY DOES IT CORE DUMP HERE ??? object.Exec("END"); // WHY DOES IT CORE DUMP HERE ???
return 0; return 0;
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* 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"
...@@ -28,44 +28,46 @@ using namespace std; ...@@ -28,44 +28,46 @@ using namespace std;
// **************************************************************** // ****************************************************************
// default constructor -- initialize everything // default constructor -- initialize everything
PgConnection::PgConnection() PgConnection::PgConnection()
: pgConn(NULL), pgResult(NULL), pgCloseConnection(false) : pgConn(NULL), pgResult(NULL), pgCloseConnection(false)
{} {}
// 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)
{ {
// Connect to the database // Connect to the database
Connect(conninfo); Connect(conninfo);
} }
// destructor - closes down the connection and cleanup // destructor - closes down the connection and cleanup
PgConnection::~PgConnection() PgConnection::~PgConnection()
{ {
// Close the connection only if needed // Close the connection only if needed
// This feature will most probably be used by the derived classes that // This feature will most probably be used by the derived classes that
// need not close the connection after they are destructed. // need not close the connection after they are destructed.
CloseConnection(); CloseConnection();
} }
// PgConnection::CloseConnection() // PgConnection::CloseConnection()
// close down the connection if there is one // close down the connection if there is one
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) {
PQclear(pgResult); if (pgResult)
pgResult = NULL; PQclear(pgResult);
if (pgConn) pgResult = NULL;
PQfinish(pgConn); if (pgConn)
pgConn = NULL; PQfinish(pgConn);
pgCloseConnection = false; pgConn = NULL;
} pgCloseConnection = false;
}
} }
...@@ -73,40 +75,40 @@ void PgConnection::CloseConnection() ...@@ -73,40 +75,40 @@ void PgConnection::CloseConnection()
// establish a connection to a backend // establish a connection to a backend
ConnStatusType PgConnection::Connect(const char conninfo[]) ConnStatusType PgConnection::Connect(const char conninfo[])
{ {
// if the connection is open, close it first // if the connection is open, close it first
CloseConnection(); CloseConnection();
// Connect to the database
pgConn = PQconnectdb(conninfo);
// Connect to the database // Now we have a connection we must close (even if it's bad!)
pgConn = PQconnectdb(conninfo); pgCloseConnection = true;
// Now we have a connection we must close (even if it's bad!) // Status will return either CONNECTION_OK or CONNECTION_BAD
pgCloseConnection = true; return Status();
// Status will return either CONNECTION_OK or CONNECTION_BAD
return Status();
} }
// PgConnection::status -- return connection or result status // PgConnection::status -- return connection or result status
ConnStatusType PgConnection::Status() const ConnStatusType PgConnection::Status() const
{ {
return PQstatus(pgConn); return PQstatus(pgConn);
} }
// PgConnection::exec -- send a query to the backend // PgConnection::exec -- send a query to the backend
ExecStatusType PgConnection::Exec(const char* query) ExecStatusType PgConnection::Exec(const char* query)
{ {
// Clear the result stucture if needed // Clear the result stucture if needed
if (pgResult) if (pgResult)
PQclear(pgResult); PQclear(pgResult);
// Execute the given query // Execute the given query
pgResult = PQexec(pgConn, query); pgResult = PQexec(pgConn, query);
// Return the status // Return the status
if (pgResult) if (pgResult)
return PQresultStatus(pgResult); return PQresultStatus(pgResult);
else else
return PGRES_FATAL_ERROR; return PGRES_FATAL_ERROR;
} }
// Return true if the Postgres command was executed OK // Return true if the Postgres command was executed OK
...@@ -125,34 +127,34 @@ int PgConnection::ExecTuplesOk(const char* query) ...@@ -125,34 +127,34 @@ int PgConnection::ExecTuplesOk(const char* query)
// PgConnection::notifies() -- returns a notification from a list of unhandled notifications // PgConnection::notifies() -- returns a notification from a list of unhandled notifications
PGnotify* PgConnection::Notifies() PGnotify* PgConnection::Notifies()
{ {
return PQnotifies(pgConn); return PQnotifies(pgConn);
} }
// From Integer To String Conversion Function // From Integer To String Conversion Function
string PgConnection::IntToString(int n) string PgConnection::IntToString(int n)
{ {
char buffer [4*sizeof(n) + 2]; char buffer [4*sizeof(n) + 2];
sprintf(buffer, "%d", n); sprintf(buffer, "%d", n);
return buffer; return buffer;
} }
bool PgConnection::ConnectionBad() const bool PgConnection::ConnectionBad() const
{ {
return Status() == CONNECTION_BAD; return Status() == CONNECTION_BAD;
} }
const char* PgConnection::ErrorMessage() const const char* PgConnection::ErrorMessage() const
{ {
return (const char *)PQerrorMessage(pgConn); return (const char *)PQerrorMessage(pgConn);
} }
const char* PgConnection::DBName() const const char* PgConnection::DBName() const
{ {
return (const char *)PQdb(pgConn); return (const char *)PQdb(pgConn);
} }
PQnoticeProcessor PgConnection::SetNoticeProcessor(PQnoticeProcessor proc, void *arg) PQnoticeProcessor PgConnection::SetNoticeProcessor(PQnoticeProcessor proc, void *arg)
{ {
return PQsetNoticeProcessor(pgConn, proc, arg); return PQsetNoticeProcessor(pgConn, proc, arg);
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* 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"
} }
...@@ -54,47 +56,48 @@ extern "C" { ...@@ -54,47 +56,48 @@ 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
bool pgCloseConnection; // true if connection should be closed by destructor bool pgCloseConnection; // true if connection should be closed by destructor
public: public:
explicit PgConnection(const char* conninfo); // use reasonable & environment defaults explicit PgConnection(const char* conninfo); // use reasonable & environment defaults
virtual ~PgConnection(); // close connection and clean up virtual ~PgConnection(); // close connection and clean up
// Connection status and error messages // Connection status and error messages
ConnStatusType Status() const; ConnStatusType Status() const;
bool ConnectionBad() const; bool ConnectionBad() const;
const char* ErrorMessage() const; const char* ErrorMessage() const;
// returns the database name of the connection // returns the database name of the connection
const char* DBName() const; const char* DBName() const;
// Query Execution interface // Query Execution interface
ExecStatusType Exec(const char* query); // send a query to the backend ExecStatusType Exec(const char* query); // send a query to the backend
int ExecCommandOk(const char* query); // send a command and check if it's OK int ExecCommandOk(const char* query); // send a command and check if it's OK
int ExecTuplesOk(const char* query); // send a command and check if tuples are returned int ExecTuplesOk(const char* query); // send a command and check if tuples are returned
PGnotify* Notifies(); PGnotify* Notifies();
// set the notice processor // set the notice processor
PQnoticeProcessor SetNoticeProcessor(PQnoticeProcessor proc, void *arg); PQnoticeProcessor SetNoticeProcessor(PQnoticeProcessor proc, void *arg);
protected: protected:
ConnStatusType Connect(const char* conninfo); ConnStatusType Connect(const char* conninfo);
void CloseConnection(); void CloseConnection();
static PGSTD string IntToString(int); static PGSTD string IntToString(int);
// Default constructor is only available to subclasses // Default constructor is only available to subclasses
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"
#ifdef HAVE_NAMESPACE_STD #ifdef HAVE_NAMESPACE_STD
using namespace std; using namespace std;
#endif #endif
...@@ -30,17 +30,18 @@ using namespace std; ...@@ -30,17 +30,18 @@ using namespace std;
// Make a connection to the specified database with default environment // Make a connection to the specified database with default environment
// See PQconnectdb() for conninfo usage // See PQconnectdb() for conninfo usage
PgCursor::PgCursor(const char* conninfo, const char* cursor) PgCursor::PgCursor(const char* conninfo, const char* cursor)
: PgTransaction(conninfo), pgCursor(cursor) : PgTransaction(conninfo), pgCursor(cursor)
{} {}
// Do not make a connection to the backend -- just query // Do not make a connection to the backend -- just query
// Connection should not be closed after the object destructs since some // Connection should not be closed after the object destructs since some
// other object is using the connection // other object is using the connection
//PgCursor::PgCursor(const PgConnection& conn, const char* cursor) //PgCursor::PgCursor(const PgConnection& conn, const char* cursor)
// : PgTransaction(conn), pgCursor(cursor) // : PgTransaction(conn), pgCursor(cursor)
//{} //{}
// Destructor: End the transaction block // Destructor: End the transaction block
PgCursor::~PgCursor() PgCursor::~PgCursor()
{ {
Close(); Close();
...@@ -57,7 +58,7 @@ int PgCursor::Declare(string query, bool binary) ...@@ -57,7 +58,7 @@ int PgCursor::Declare(string query, bool binary)
{ {
string cmd = "DECLARE " + pgCursor; string cmd = "DECLARE " + pgCursor;
if ( binary ) if ( binary )
cmd += " BINARY"; cmd += " BINARY";
cmd += " CURSOR FOR " + query; cmd += " CURSOR FOR " + query;
return ExecCommandOk( cmd.c_str() ); return ExecCommandOk( cmd.c_str() );
} }
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* 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,40 +41,50 @@ ...@@ -41,40 +41,50 @@
// 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
// PgCursor(const PgConnection&, const char* cursor); // PgCursor(const PgConnection&, const char* cursor);
~PgCursor(); // close connection and clean up ~PgCursor(); // close connection and clean up
// Commands associated with cursor interface // Commands associated with cursor interface
int Declare(PGSTD string query, bool binary = false); // Declare a cursor with given name int Declare(PGSTD string query, bool binary = false); // Declare a cursor with given name
int Fetch(const char* dir = "FORWARD"); // Fetch ALL tuples in given direction int Fetch(const char* dir = "FORWARD"); // Fetch ALL tuples in given direction
int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples int Fetch(unsigned num, const char* dir = "FORWARD"); // Fetch specified amount of tuples
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
// TODO: Setter has same name as getter--ouch! {
// OBSOLESCENT return pgCursor.c_str();
void Cursor(PGSTD string cursor) { pgCursor = cursor; } }
// TODO: Setter has same name as getter--ouch!
// OBSOLESCENT
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);
protected: 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"
#ifdef HAVE_NAMESPACE_STD #ifdef HAVE_NAMESPACE_STD
...@@ -23,11 +23,11 @@ using namespace std; ...@@ -23,11 +23,11 @@ using namespace std;
// OBSOLESCENT (uses PQprint(), which is no longer being maintained) // OBSOLESCENT (uses PQprint(), which is no longer being maintained)
void PgDatabase::DisplayTuples(FILE *out, void PgDatabase::DisplayTuples(FILE *out,
bool fillAlign, bool fillAlign,
const char* fieldSep, const char* fieldSep,
bool printHeader, bool printHeader,
bool /* quiet */) const bool /* quiet */) const
{ {
PQprintOpt po; PQprintOpt po;
...@@ -38,16 +38,16 @@ void PgDatabase::DisplayTuples(FILE *out, ...@@ -38,16 +38,16 @@ 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);
} }
// OBSOLESCENT (uses PQprint(), which is no longer being maintained) // OBSOLESCENT (uses PQprint(), which is no longer being maintained)
void PgDatabase::PrintTuples(FILE *out, void PgDatabase::PrintTuples(FILE *out,
bool printAttName, bool printAttName,
bool terseOutput, bool terseOutput,
bool fillAlign) const bool fillAlign) const
{ {
PQprintOpt po; PQprintOpt 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
#ifndef PGCONNECTION_H #ifndef PGCONNECTION_H
#include "pgconnection.h" #include "pgconnection.h"
#endif #endif
...@@ -31,55 +31,61 @@ ...@@ -31,55 +31,61 @@
// PgDatabase - a class for accessing databases // PgDatabase - a class for accessing databases
// //
// **************************************************************** // ****************************************************************
// 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;
// query result access
size_type Tuples() const;
size_type CmdTuples() const;
int Fields();
const char* FieldName(int field_num) const;
int FieldNum(const char* field_name) const;
Oid FieldType(int field_num) const;
Oid FieldType(const char* field_name) const;
int FieldSize(int field_num) const;
int FieldSize(const char* field_name) const;
const char* GetValue(size_type tup_num, int field_num) const;
const char* GetValue(size_type tup_num, const char* field_name) const;
bool GetIsNull(size_type tup_num, int field_num) const;
bool GetIsNull(size_type tup_num, const char* field_name) const;
int GetLength(size_type tup_num, int field_num) const;
int GetLength(size_type tup_num, const char* field_name) const;
// OBSOLESCENT (use PQprint()): // query result access
void DisplayTuples(FILE *out=0, bool fillAlign=true, size_type Tuples() const;
const char* fieldSep="|", bool printHeader=true, bool quiet=false) const; size_type CmdTuples() const;
void PrintTuples(FILE *out=0, bool printAttName=true, int Fields();
bool terseOutput=false, bool fillAlign=false) const; const char* FieldName(int field_num) const;
int FieldNum(const char* field_name) const;
Oid FieldType(int field_num) const;
Oid FieldType(const char* field_name) const;
int FieldSize(int field_num) const;
int FieldSize(const char* field_name) const;
const char* GetValue(size_type tup_num, int field_num) const;
const char* GetValue(size_type tup_num, const char* field_name) const;
bool GetIsNull(size_type tup_num, int field_num) const;
bool GetIsNull(size_type tup_num, const char* field_name) const;
int GetLength(size_type tup_num, int field_num) const;
int GetLength(size_type tup_num, const char* field_name) const;
// OBSOLESCENT (use PQprint()):
void DisplayTuples(FILE *out = 0, bool fillAlign = true,
const char* fieldSep = "|", bool printHeader = true, bool quiet = false) const;
void PrintTuples(FILE *out = 0, bool printAttName = true,
bool terseOutput = false, bool fillAlign = false) const;
// copy command related access
int GetLine(char str[], int length);
void PutLine(const char str[]);
const char* OidStatus() const;
int EndCopy();
// copy command related access
int GetLine(char str[], int length);
void PutLine(const char str[]);
const char* OidStatus() const;
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&);
}; };
#endif // PGDATABASE_H #endif // PGDATABASE_H
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* 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"
} }
...@@ -35,140 +36,145 @@ using namespace std; ...@@ -35,140 +36,145 @@ using namespace std;
// creates a large object in the default database // creates a large object in the default database
// See PQconnectdb() for conninfo usage // See PQconnectdb() for conninfo usage
PgLargeObject::PgLargeObject(const char* conninfo) PgLargeObject::PgLargeObject(const char* conninfo)
: PgConnection(conninfo) : PgConnection(conninfo)
{ {
Init(); Init();
if (! ConnectionBad()) { if (! ConnectionBad())
Create(); {
Open(); Create();
} Open();
}
} }
// constructor // constructor
// open an existing large object in the default database // open an existing large object in the default database
// See PQconnectdb() for conninfo usage // See PQconnectdb() for conninfo usage
PgLargeObject::PgLargeObject(Oid lobjId, const char* conninfo) PgLargeObject::PgLargeObject(Oid lobjId, const char* conninfo)
: PgConnection(conninfo) : PgConnection(conninfo)
{ {
Init(lobjId); Init(lobjId);
if (! ConnectionBad()) { if (! ConnectionBad())
if ( !pgObject ) {
Create(); if ( !pgObject )
Open(); Create();
} Open();
}
} }
// destructor -- closes large object // destructor -- closes large object
PgLargeObject::~PgLargeObject() PgLargeObject::~PgLargeObject()
{ {
Close(); Close();
} }
// PgLargeObject::Init // PgLargeObject::Init
// Initialize the variables // Initialize the variables
void PgLargeObject::Init(Oid lobjId) void PgLargeObject::Init(Oid lobjId)
{ {
pgFd = -1; pgFd = -1;
pgObject = lobjId; pgObject = lobjId;
} }
// PgLargeObject::create // PgLargeObject::create
// create large object and check for errors // create large object and check for errors
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)
loStatus = "PgLargeObject: can't create large object" ; loStatus = "PgLargeObject: can't create large object" ;
else else
loStatus = "PgLargeObject: created large object" ; loStatus = "PgLargeObject: created large object" ;
} }
// PgLargeObject::open // PgLargeObject::open
// open large object and check for errors // open large object and check for errors
void PgLargeObject::Open() 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) );
if (pgFd < 0) if (pgFd < 0)
loStatus = "PgLargeObject: can't open large object " + objStr ; loStatus = "PgLargeObject: can't open large object " + objStr ;
else else
loStatus = "PgLargeObject: created and opened large object " + objStr ; loStatus = "PgLargeObject: created and opened large object " + objStr ;
} }
// PgLargeObject::unlink // PgLargeObject::unlink
// destroy large object and delete from it from the database // destroy large object and delete from it from the database
int PgLargeObject::Unlink() int PgLargeObject::Unlink()
{ {
// Unlink the object // Unlink the object
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(); {
Init(); Close();
} Init();
}
// Return the status
return temp; // Return the status
return temp;
} }
void PgLargeObject::Close() void PgLargeObject::Close()
{ {
if (pgFd >= 0) lo_close(pgConn, pgFd); if (pgFd >= 0)
pgFd = -1; lo_close(pgConn, pgFd);
pgFd = -1;
} }
int PgLargeObject::Read(char* buf, int len) int PgLargeObject::Read(char* buf, int len)
{ {
return lo_read(pgConn, pgFd, buf, len); return lo_read(pgConn, pgFd, buf, len);
} }
int PgLargeObject::Write(const char* buf, int len) int PgLargeObject::Write(const char* buf, int len)
{ {
return lo_write(pgConn, pgFd, (char*)buf, len); return lo_write(pgConn, pgFd, (char*)buf, len);
} }
int PgLargeObject::LSeek(int offset, int whence) int PgLargeObject::LSeek(int offset, int whence)
{ {
return lo_lseek(pgConn, pgFd, offset, whence); return lo_lseek(pgConn, pgFd, offset, whence);
} }
int PgLargeObject::Tell() const int PgLargeObject::Tell() const
{ {
return lo_tell(pgConn, pgFd); return lo_tell(pgConn, pgFd);
} }
Oid PgLargeObject::Import(const char* filename) Oid PgLargeObject::Import(const char* filename)
{ {
return pgObject = lo_import(pgConn, filename); return pgObject = lo_import(pgConn, filename);
} }
int PgLargeObject::Export(const char* filename) int PgLargeObject::Export(const char* filename)
{ {
return lo_export(pgConn, pgObject, filename); return lo_export(pgConn, pgObject, filename);
} }
string PgLargeObject::Status() const 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
#ifndef PGCONNECTION_H #ifndef PGCONNECTION_H
#include "pgconnection.h" #include "pgconnection.h"
#endif #endif
...@@ -35,36 +35,37 @@ ...@@ -35,36 +35,37 @@
// 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;
PGSTD string loStatus; PGSTD string loStatus;
void Init(Oid lobjId = 0); void Init(Oid lobjId = 0);
public: public:
explicit PgLargeObject(const char* conninfo = 0); // use reasonable defaults and create large object explicit PgLargeObject(const char* conninfo = 0); // use reasonable defaults and create large object
explicit PgLargeObject(Oid lobjId, const char* conninfo = 0); // use reasonable defaults and open large object explicit PgLargeObject(Oid lobjId, const char* conninfo = 0); // use reasonable defaults and open large object
~PgLargeObject(); // close connection and clean up ~PgLargeObject(); // close connection and clean up
void Create(); void Create();
void Open(); void Open();
void Close(); void Close();
int Read(char* buf, int len); int Read(char* buf, int len);
int Write(const char* buf, int len); int Write(const char* buf, int len);
int LSeek(int offset, int whence); int LSeek(int offset, int whence);
int Tell() const; int Tell() const;
int Unlink(); int Unlink();
Oid LOid(); Oid LOid();
Oid Import(const char* filename); Oid Import(const char* filename);
int Export(const char* filename); int Export(const char* filename);
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"
// **************************************************************** // ****************************************************************
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
// //
// **************************************************************** // ****************************************************************
// Make a connection to the specified database with default environment // Make a connection to the specified database with default environment
// See PQconnectdb() for conninfo usage. // See PQconnectdb() for conninfo usage.
PgTransaction::PgTransaction(const char* conninfo) PgTransaction::PgTransaction(const char* conninfo)
: PgDatabase(conninfo), : PgDatabase(conninfo),
pgCommitted(true) pgCommitted(true)
{ {
BeginTransaction(); BeginTransaction();
} }
...@@ -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,27 +34,31 @@ ...@@ -34,27 +34,31 @@
// 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
// explicit PgTransaction(const PgConnection&); // explicit PgTransaction(const PgConnection&);
~PgTransaction(); // close connection and clean up ~PgTransaction(); // close connection and clean up
protected: protected:
ExecStatusType BeginTransaction(); ExecStatusType BeginTransaction();
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