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--
* small test program for libpq++,
* small interactive loop where queries can be entered interactively
* and sent to the backend
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.6 2000/05/29 21:25:04 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* testlibpq0.c--
* small test program for libpq++,
* small interactive loop where queries can be entered interactively
* and sent to the backend
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $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 "libpq++.h"
......@@ -21,7 +21,8 @@ int main()
{
// Open the connection to the database and make sure it's OK
PgDatabase data("dbname=template1");
if ( data.ConnectionBad() ) {
if ( data.ConnectionBad() )
{
cout << "Connection was unsuccessful..." << endl
<< "Error message returned: " << data.ErrorMessage() << endl;
return 1;
......
/*
* testlibpq1.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
*
* queries the template1 database for a list of database names
*
*/
* testlibpq1.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
*
* queries the template1 database for a list of database names
*
*/
#include <iostream.h>
#include <iomanip.h>
......@@ -20,40 +20,45 @@ int main()
PgDatabase data(dbName);
// 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;
exit(1);
}
// start a transaction block
if ( !data.ExecCommandOk("BEGIN") ) {
if ( !data.ExecCommandOk("BEGIN") )
{
cerr << "BEGIN command failed" << endl;
exit(1);
}
// 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);
}
// 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);
}
// first, print out the attribute names
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 << endl << endl;
// next, print out the instances
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 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;
}
......
/*
* testlibpq2.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
*
* queries the template1 database for a list of database names using transaction block
*
*/
* testlibpq2.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
*
* queries the template1 database for a list of database names using transaction block
*
*/
#include <iostream.h>
#include <iomanip.h>
......@@ -20,34 +20,38 @@ int main()
PgTransaction data(dbName);
// 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;
exit(1);
}
// 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);
}
// 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);
}
// first, print out the attribute names
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 << endl << endl;
// next, print out the instances
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 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;
}
......
/*
* testlibpq3.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
*
* queries the template1 database for a list of database names using transaction block
* and cursor interface.
*
*/
* testlibpq3.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
*
* queries the template1 database for a list of database names using transaction block
* and cursor interface.
*
*/
#include <iostream.h>
#include <iomanip.h>
......@@ -23,34 +23,38 @@ int main()
PgCursor cData(dbName, "myportal");
// 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;
exit(1);
}
// 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;
exit(1);
}
// 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;
exit(1);
}
// first, print out the attribute names
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 << 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);
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
* Test of the asynchronous notification interface
*
* testlibpq4.cc
* Test of the asynchronous notification interface
*
populate a test database with the following (use testlibpq4.sql):
CREATE TABLE TBL1 (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];
* Then start up this program
* After the program has begun, do
* Then start up this program
* After the program has begun, do
INSERT INTO TBL1 values (10);
*
*
*/
*
*
*/
#include <iostream.h>
#include "libpq++.h"
#include <stdlib.h>
......@@ -31,23 +31,27 @@ int main()
PgDatabase data(dbName);
// 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;
exit(1);
}
// Listen to a table
if ( !data.ExecCommandOk("LISTEN TBL2") ) {
if ( !data.ExecCommandOk("LISTEN TBL2") )
{
cerr << "LISTEN command failed" << endl;
exit(1);
}
// Test asynchronous notification
while (1) {
while (1)
{
// check for asynchronous returns
PGnotify* notify = data.Notifies();
if (notify) {
if (notify)
{
cerr << "ASYNC NOTIFY of '" << notify->relname
<< "' from backend pid '" << notify->be_pid
<< "' received" << endl;
......
/*
* testlibpq5.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
* tests the binary cursor interface
*
*
*
populate a database by doing the following (use testlibpq5.sql):
* testlibpq5.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
* tests the binary cursor interface
*
*
*
populate a database by doing the following (use testlibpq5.sql):
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);
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
i = (4 bytes) 1,
d = (4 bytes) 3.567000,
p = (4 bytes) 2 points boundbox = (hi=3.000000/4.000000, lo = 1.000000,2.000000)
i = (4 bytes) 1,
d = (4 bytes) 3.567000,
p = (4 bytes) 2 points boundbox = (hi=3.000000/4.000000, lo = 1.000000,2.000000)
tuple 1: got
i = (4 bytes) 2,
d = (4 bytes) 89.050003,
p = (4 bytes) 2 points boundbox = (hi=4.000000/3.000000, lo = 2.000000,1.000000)
i = (4 bytes) 2,
d = (4 bytes) 89.050003,
p = (4 bytes) 2 points boundbox = (hi=4.000000/3.000000, lo = 2.000000,1.000000)
*
*/
*
*/
#include <iostream.h>
#include "libpq++.h"
#include <stdlib.h>
extern "C" {
extern "C"
{
#include "postgres.h" // for Postgres types
#include "utils/geo_decls.h" // for the POLYGON type
}
......@@ -43,20 +44,23 @@ int main()
PgCursor data(dbName, "mycursor");
// 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();
exit(1);
}
// 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;
exit(1);
}
// fetch all instances from the current cursor
if ( !data.Fetch() ) {
if ( !data.Fetch() )
{
cerr << "FETCH ALL command didn't return tuples properly" << endl;
exit(1);
}
......@@ -66,33 +70,34 @@ int main()
int d_fnum = data.FieldNum("d");
int p_fnum = data.FieldNum("p");
/*
/*
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++) {
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);
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);
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"
<< " 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;
......
/*
* testlibpq4.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
* tests the copy in features
*
*/
* testlibpq4.cc
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
* tests the copy in features
*
*/
#include <iostream.h>
#include "libpq++.h"
#include <stdlib.h>
......@@ -17,26 +17,32 @@ int main()
PgTransaction data(dbName);
// 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();
exit(1);
}
else cout << "Connected to database '" << dbName << "'..." << endl;
else
cout << "Connected to database '" << dbName << "'..." << endl;
// 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);
}
else cout << "CREATEd TABLE foo successfully.." << endl;
else
cout << "CREATEd TABLE foo successfully.." << endl;
// 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);
}
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
data.PutLine("3\thello world\t4.5\n");
......@@ -47,12 +53,14 @@ int main()
cout << "Line: \"\\.\" copied..." << endl;
if ( !data.EndCopy() )
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") )
data.PrintTuples();
else cerr << "SELECT * FROM foo failed..." << endl;
else
cerr << "SELECT * FROM foo failed..." << endl;
// Drop the test table
data.Exec("DROP TABLE foo");
......
/*-------------------------------------------------------------------------
*
* lotest.cc--
* test using large objects with libpq
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlo.cc,v 1.8 2000/05/29 21:25:04 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* lotest.cc--
* test using large objects with libpq
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $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 "libpq++.h"
#include <stdlib.h>
......@@ -18,7 +18,8 @@
int main(int argc, char **argv)
{
// 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);
}
......@@ -33,7 +34,8 @@ int main(int argc, char **argv)
PgLargeObject object(lobjId, conninfo);
// 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();
exit(1);
......
/*-------------------------------------------------------------------------
*
* libpq++.h
*
*
* DESCRIPTION
* C++ client interface to Postgres
* used for building front-end applications
*
* NOTES
* This is intended to be included by client applications.
* It will not work as an inclusion in the libpq++ sources, since
* in the build environment the individual include files are not
* yet installed in a subdirectory.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq++.h,v 1.12 2002/06/20 20:29:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* libpq++.h
*
*
* DESCRIPTION
* C++ client interface to Postgres
* used for building front-end applications
*
* NOTES
* This is intended to be included by client applications.
* It will not work as an inclusion in the libpq++ sources, since
* in the build environment the individual include files are not
* yet installed in a subdirectory.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq++.h,v 1.13 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef LIBPQXX_H
......
/*-------------------------------------------------------------------------
*
* FILE
* pgconnection.cc
*
* DESCRIPTION
* implementation of the PgConnection class.
* PgConnection encapsulates a frontend to backend connection
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.14 2002/06/15 18:49:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* FILE
* pgconnection.cc
*
* DESCRIPTION
* implementation of the PgConnection class.
* PgConnection encapsulates a frontend to backend connection
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgconnection.cc,v 1.15 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgconnection.h"
......@@ -34,6 +34,7 @@ PgConnection::PgConnection()
// constructor -- checks environment variable for database name
// Now uses PQconnectdb
PgConnection::PgConnection(const char* conninfo)
: pgConn(NULL), pgResult(NULL), pgCloseConnection(true)
{
......@@ -57,7 +58,8 @@ PgConnection::~PgConnection()
void PgConnection::CloseConnection()
{
// if the connection is open, close it first
if (pgCloseConnection) {
if (pgCloseConnection)
{
if (pgResult)
PQclear(pgResult);
pgResult = NULL;
......
/*-------------------------------------------------------------------------
*
* pgconnection.h
*
*
* DESCRIPTION
* Postgres Connection Class:
* Manage Postgres backend connection
*
* NOTES
* Currently under construction.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pgconnection.h,v 1.18 2002/06/20 20:29:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* pgconnection.h
*
*
* DESCRIPTION
* Postgres Connection Class:
* Manage Postgres backend connection
*
* NOTES
* Currently under construction.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pgconnection.h,v 1.19 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PGCONNECTION_H
#define PGCONNECTION_H
extern "C" {
extern "C"
{
#include "pg_config.h"
}
......@@ -37,7 +38,8 @@ extern "C" {
#include <string>
#endif
extern "C" {
extern "C"
{
#include "libpq-fe.h"
}
......@@ -56,7 +58,8 @@ extern "C" {
// This class contains all the information about the connection
// to the backend process. All the database classes should be
// derived from this class to obtain the connection interface.
class DLLIMPORT PgConnection {
class DLLIMPORT PgConnection
{
protected:
PGconn* pgConn; // Connection Structure
PGresult* pgResult; // Current Query Result
......@@ -91,8 +94,8 @@ protected:
PgConnection();
private:
// We don't support copying of PgConnection objects,
// so make copy constructor and assignment op private.
// We don't support copying of PgConnection objects,
// so make copy constructor and assignment op private.
PgConnection(const PgConnection&);
PgConnection& operator= (const PgConnection&);
};
......
/*-------------------------------------------------------------------------
*
* FILE
* pgcursordb.cpp
*
* DESCRIPTION
* implementation of the PgCursor class.
* PgCursor encapsulates a cursor interface to the backend
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.7 2002/06/15 18:49:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* FILE
* pgcursordb.cpp
*
* DESCRIPTION
* implementation of the PgCursor class.
* PgCursor encapsulates a cursor interface to the backend
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgcursordb.cc,v 1.8 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgcursordb.h"
......@@ -41,6 +41,7 @@ PgCursor::PgCursor(const char* conninfo, const char* cursor)
//{}
// Destructor: End the transaction block
PgCursor::~PgCursor()
{
Close();
......
/*-------------------------------------------------------------------------
*
* pgcursordb.h
*
*
* DESCRIPTION
* Postgres Cursor Database Class:
* Query Postgres backend using a cursor
*
* NOTES
* Currently under construction.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgcursordb.h,v 1.11 2002/06/20 20:29:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* pgcursordb.h
*
*
* DESCRIPTION
* Postgres Cursor Database Class:
* Query Postgres backend using a cursor
*
* NOTES
* Currently under construction.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgcursordb.h,v 1.12 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PGCURSORDB_H
#define PGCURSORDB_H
......@@ -41,7 +41,8 @@
// manipulates data through it. The interface will introduce some
// ease of use through the methods that will allow cursor specific
// operations, like fetch, forward, etc.
class DLLIMPORT PgCursor : public PgTransaction {
class DLLIMPORT PgCursor : public PgTransaction
{
public:
PgCursor(const char* conninfo, const char* cursor); // use reasonable & environment defaults
// connect to the database with given environment and database name
......@@ -55,10 +56,16 @@ public:
int Close(); // Close the cursor
// 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!
// OBSOLESCENT
void Cursor(PGSTD string cursor) { pgCursor = cursor; }
void Cursor(PGSTD string cursor)
{
pgCursor = cursor;
}
protected:
int Fetch(PGSTD string num, PGSTD string dir);
......@@ -67,14 +74,17 @@ protected:
PGSTD string pgCursor;
protected:
PgCursor() : PgTransaction() {} // Do not connect
PgCursor() : PgTransaction()
{} // Do not connect
private:
// We don't support copying of PgCursor objects,
// so make copy constructor and assignment op private.
// We don't support copying of PgCursor objects,
// so make copy constructor and assignment op private.
PgCursor(const PgCursor&);
PgCursor& operator= (const PgCursor&);
}; // End PgCursor Class Declaration
}
; // End PgCursor Class Declaration
#undef PGSTD
......
/*-------------------------------------------------------------------------
*
* FILE
* pgdatabase.cpp
*
* DESCRIPTION
* implementation of the PgDatabase class.
* PgDatabase encapsulates some utility routines
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.12 2001/09/30 22:30:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*
* FILE
* pgdatabase.cpp
*
* DESCRIPTION
* implementation of the PgDatabase class.
* PgDatabase encapsulates some utility routines
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.13 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgdatabase.h"
......@@ -38,7 +38,7 @@ void PgDatabase::DisplayTuples(FILE *out,
po.tableOpt = po.caption = 0;
po.fieldName = 0;
PQprint(out,pgResult,&po);
PQprint(out, pgResult, &po);
}
......@@ -58,124 +58,124 @@ void PgDatabase::PrintTuples(FILE *out,
po.fieldSep = (char *) (terseOutput ? "" : "|");
po.fieldName = 0;
PQprint(out,pgResult,&po);
PQprint(out, pgResult, &po);
}
int PgDatabase::Tuples() const
{
return PQntuples(pgResult);
return PQntuples(pgResult);
}
int PgDatabase::CmdTuples() const
{
const char *a = PQcmdTuples(pgResult);
return a[0] ? atoi(a) : -1;
const char *a = PQcmdTuples(pgResult);
return a[0] ? atoi(a) : -1;
}
// TODO: Make const?
int PgDatabase::Fields()
{
return PQnfields(pgResult);
return PQnfields(pgResult);
}
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
{
return PQfnumber(pgResult, field_name);
return PQfnumber(pgResult, field_name);
}
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
{
return PQftype(pgResult, FieldNum(field_name));
return PQftype(pgResult, FieldNum(field_name));
}
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
{
return PQfsize(pgResult, FieldNum(field_name));
return PQfsize(pgResult, FieldNum(field_name));
}
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
{
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
{
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
{
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
{
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
{
return PQgetlength(pgResult, tup_num, FieldNum(field_name));
return PQgetlength(pgResult, tup_num, FieldNum(field_name));
}
int PgDatabase::GetLine(char str[], int length)
{
return PQgetline(pgConn, str, length);
return PQgetline(pgConn, str, length);
}
void PgDatabase::PutLine(const char str[])
{
PQputline(pgConn, str);
PQputline(pgConn, str);
}
const char* PgDatabase::OidStatus() const
{
return PQoidStatus(pgResult);
return PQoidStatus(pgResult);
}
int PgDatabase::EndCopy()
{
return PQendcopy(pgConn);
return PQendcopy(pgConn);
}
/*-------------------------------------------------------------------------
*
* pgdatabase.h
*
*
* DESCRIPTION
* Postgres Database Class:
* Query Postgres backend to obtain query results
*
* NOTES
* Currently under construction.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgdatabase.h,v 1.13 2002/06/20 20:29:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* pgdatabase.h
*
*
* DESCRIPTION
* Postgres Database Class:
* Query Postgres backend to obtain query results
*
* NOTES
* Currently under construction.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgdatabase.h,v 1.14 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PGDATABASE_H
#define PGDATABASE_H
......@@ -34,12 +34,16 @@
// This is the basic database access class. Its interface should
// be used only after a query has been sent to the backend and
// results are being received.
class DLLIMPORT PgDatabase : public PgConnection {
class DLLIMPORT PgDatabase : public PgConnection
{
public:
// 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;
......@@ -61,10 +65,10 @@ public:
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;
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);
......@@ -73,11 +77,13 @@ public:
int EndCopy();
protected:
PgDatabase() : PgConnection() {} // Do not connect
PgDatabase() : PgConnection()
{} // Do not connect
private:
// We don't support copying of PgDatabase objects,
// so make copy constructor and assignment op private.
// We don't support copying of PgDatabase objects,
// so make copy constructor and assignment op private.
PgDatabase(const PgDatabase&);
PgDatabase& operator= (const PgDatabase&);
};
......
/*-------------------------------------------------------------------------
*
* FILE
* pglobject.cc
*
* DESCRIPTION
* implementation of the PgLargeObject class.
* PgLargeObject encapsulates a frontend to backend connection
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.10 2002/06/15 19:30:40 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* FILE
* pglobject.cc
*
* DESCRIPTION
* implementation of the PgLargeObject class.
* PgLargeObject encapsulates a frontend to backend connection
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pglobject.cc,v 1.11 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pglobject.h"
extern "C" {
extern "C"
{
#include "libpq/libpq-fs.h"
}
......@@ -38,7 +39,8 @@ PgLargeObject::PgLargeObject(const char* conninfo)
: PgConnection(conninfo)
{
Init();
if (! ConnectionBad()) {
if (! ConnectionBad())
{
Create();
Open();
}
......@@ -51,7 +53,8 @@ PgLargeObject::PgLargeObject(Oid lobjId, const char* conninfo)
: PgConnection(conninfo)
{
Init(lobjId);
if (! ConnectionBad()) {
if (! ConnectionBad())
{
if ( !pgObject )
Create();
Open();
......@@ -77,7 +80,7 @@ void PgLargeObject::Init(Oid lobjId)
void PgLargeObject::Create()
{
// Create the object
pgObject = lo_creat(pgConn, INV_READ|INV_WRITE);
pgObject = lo_creat(pgConn, INV_READ | INV_WRITE);
// Check for possible errors
if (!pgObject)
......@@ -93,7 +96,7 @@ void PgLargeObject::Open()
// Close any prior object
Close();
// 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
string objStr( IntToString(pgObject) );
......@@ -111,7 +114,8 @@ int PgLargeObject::Unlink()
int temp = lo_unlink(pgConn, pgObject);
// Initialize the large object upon success
if (!temp) {
if (!temp)
{
Close();
Init();
}
......@@ -123,7 +127,8 @@ int PgLargeObject::Unlink()
void PgLargeObject::Close()
{
if (pgFd >= 0) lo_close(pgConn, pgFd);
if (pgFd >= 0)
lo_close(pgConn, pgFd);
pgFd = -1;
}
......@@ -169,6 +174,7 @@ string PgLargeObject::Status() const
return loStatus;
}
Oid PgLargeObject::LOid(){
Oid PgLargeObject::LOid()
{
return pgObject;
}
/*-------------------------------------------------------------------------
*
* FILE
* pglobject.h
*
* DESCRIPTION
* declaration of the PGlobj class.
* PGlobj encapsulates a large object interface to Postgres backend
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pglobject.h,v 1.10 2002/06/20 20:29:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* FILE
* pglobject.h
*
* DESCRIPTION
* declaration of the PGlobj class.
* PGlobj encapsulates a large object interface to Postgres backend
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pglobject.h,v 1.11 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PGLOBJECT_H
#define PGLOBJECT_H
......@@ -35,7 +35,8 @@
// PgLargeObject - a class for accessing Large Object in a database
//
// ****************************************************************
class DLLIMPORT PgLargeObject : public PgConnection {
class DLLIMPORT PgLargeObject : public PgConnection
{
private:
int pgFd;
Oid pgObject;
......@@ -61,8 +62,8 @@ public:
PGSTD string Status() const;
private:
// We don't support copying of PgLargeObject objects,
// so make copy constructor and assignment op private.
// We don't support copying of PgLargeObject objects,
// so make copy constructor and assignment op private.
PgLargeObject(const PgLargeObject&);
PgLargeObject& operator= (const PgLargeObject&);
};
......
/*-------------------------------------------------------------------------
*
* FILE
* pgtransdb.cpp
*
* DESCRIPTION
* implementation of the PgTransaction class.
* PgConnection encapsulates a transaction querying to backend
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgtransdb.cc,v 1.4 2001/05/09 17:29:10 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* FILE
* pgtransdb.cpp
*
* DESCRIPTION
* implementation of the PgTransaction class.
* PgConnection encapsulates a transaction querying to backend
*
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgtransdb.cc,v 1.5 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "pgtransdb.h"
......@@ -34,7 +34,8 @@ PgTransaction::PgTransaction(const char* conninfo)
// Destructor: End the transaction block
PgTransaction::~PgTransaction()
{
if (!pgCommitted) Exec("ABORT");
if (!pgCommitted)
Exec("ABORT");
}
// Begin the transaction block
......
/*-------------------------------------------------------------------------
*
* pgtransdb.h
*
*
* DESCRIPTION
* Postgres Transaction Database Class:
* Query Postgres backend using a transaction block
*
* NOTES
* Currently under construction.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgtransdb.h,v 1.9 2002/06/20 20:29:54 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*
* pgtransdb.h
*
*
* DESCRIPTION
* Postgres Transaction Database Class:
* Query Postgres backend using a transaction block
*
* NOTES
* Currently under construction.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* $Id: pgtransdb.h,v 1.10 2002/07/02 16:32:19 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PGTRANSDB_H
#define PGTRANSDB_H
......@@ -34,7 +34,8 @@
// This is the database access class that keeps an open
// transaction block during its lifetime. The block is ENDed when
// the object is destroyed.
class DLLIMPORT PgTransaction : public PgDatabase {
class DLLIMPORT PgTransaction : public PgDatabase
{
public:
explicit PgTransaction(const char* conninfo); // use reasonable & environment defaults
// connect to the database with given environment and database name
......@@ -46,15 +47,18 @@ protected:
ExecStatusType EndTransaction();
protected:
PgTransaction() : PgDatabase(), pgCommitted(true) {} // Do not connect
PgTransaction() : PgDatabase(), pgCommitted(true)
{} // Do not connect
private:
bool pgCommitted;
// We don't support copying of PgTransaction objects,
// so make copy constructor and assignment op private.
// We don't support copying of PgTransaction objects,
// so make copy constructor and assignment op private.
PgTransaction(const PgTransaction&);
PgTransaction& operator= (const PgTransaction&);
}; // End PgTransaction Class Declaration
}
; // End PgTransaction Class Declaration
#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