summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq++/examples
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-07-02 16:32:19 +0000
committerBruce Momjian <bruce@momjian.us>2002-07-02 16:32:19 +0000
commita4485ea894ddd622daa81009d1556c95cd357781 (patch)
tree40b5d89b6807e7e2088300eb5b113bf9604b47c8 /src/interfaces/libpq++/examples
parentc9a734521712797b1cd6a77bf9cabfe4c503e186 (diff)
Indent libpq++ as mentioned in email. Format was terrible, and this
will make fixing things easier.
Diffstat (limited to 'src/interfaces/libpq++/examples')
-rw-r--r--src/interfaces/libpq++/examples/testlibpq0.cc89
-rw-r--r--src/interfaces/libpq++/examples/testlibpq1.cc107
-rw-r--r--src/interfaces/libpq++/examples/testlibpq2.cc100
-rw-r--r--src/interfaces/libpq++/examples/testlibpq3.cc94
-rw-r--r--src/interfaces/libpq++/examples/testlibpq4.cc86
-rw-r--r--src/interfaces/libpq++/examples/testlibpq5.cc167
-rw-r--r--src/interfaces/libpq++/examples/testlibpq6.cc104
-rw-r--r--src/interfaces/libpq++/examples/testlo.cc78
8 files changed, 429 insertions, 396 deletions
diff --git a/src/interfaces/libpq++/examples/testlibpq0.cc b/src/interfaces/libpq++/examples/testlibpq0.cc
index 041ced557fc..24fb03fc785 100644
--- a/src/interfaces/libpq++/examples/testlibpq0.cc
+++ b/src/interfaces/libpq++/examples/testlibpq0.cc
@@ -1,52 +1,53 @@
/*-------------------------------------------------------------------------
- *
- * 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"
int main()
{
- // Open the connection to the database and make sure it's OK
- PgDatabase data("dbname=template1");
- if ( data.ConnectionBad() ) {
- cout << "Connection was unsuccessful..." << endl
- << "Error message returned: " << data.ErrorMessage() << endl;
- return 1;
- }
- else
- cout << "Connection successful... Enter queries below:" << endl;
-
- // Interactively obtain and execute queries
- ExecStatusType status;
- string buf;
- int done = 0;
- while (!done)
- {
- cout << "> ";
- cout.flush();
- getline(cin, buf);
- if ( buf != "" )
- if ( (status = data.Exec( buf.c_str() )) == PGRES_TUPLES_OK )
- data.DisplayTuples();
- else
- cout << "No tuples returned..." << endl
- << "status = " << status << endl
- << "Error returned: " << data.ErrorMessage() << endl;
- else
- done = 1;
- }
- return 0;
+ // Open the connection to the database and make sure it's OK
+ PgDatabase data("dbname=template1");
+ if ( data.ConnectionBad() )
+ {
+ cout << "Connection was unsuccessful..." << endl
+ << "Error message returned: " << data.ErrorMessage() << endl;
+ return 1;
+ }
+ else
+ cout << "Connection successful... Enter queries below:" << endl;
+
+ // Interactively obtain and execute queries
+ ExecStatusType status;
+ string buf;
+ int done = 0;
+ while (!done)
+ {
+ cout << "> ";
+ cout.flush();
+ getline(cin, buf);
+ if ( buf != "" )
+ if ( (status = data.Exec( buf.c_str() )) == PGRES_TUPLES_OK )
+ data.DisplayTuples();
+ else
+ cout << "No tuples returned..." << endl
+ << "status = " << status << endl
+ << "Error returned: " << data.ErrorMessage() << endl;
+ else
+ done = 1;
+ }
+ return 0;
} // End main()
diff --git a/src/interfaces/libpq++/examples/testlibpq1.cc b/src/interfaces/libpq++/examples/testlibpq1.cc
index 5c71c906b9f..f6469b8a3a1 100644
--- a/src/interfaces/libpq++/examples/testlibpq1.cc
+++ b/src/interfaces/libpq++/examples/testlibpq1.cc
@@ -1,10 +1,10 @@
/*
- * 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>
@@ -12,57 +12,62 @@
int main()
{
- // Begin, by establishing a connection to the backend.
- // When no parameters are given then the system will
- // try to use reasonable defaults by looking up environment variables
- // or, failing that, using hardwired constants
- const char* dbName = "dbname=template1";
- PgDatabase data(dbName);
+ // Begin, by establishing a connection to the backend.
+ // When no parameters are given then the system will
+ // try to use reasonable defaults by looking up environment variables
+ // or, failing that, using hardwired constants
+ const char* dbName = "dbname=template1";
+ PgDatabase data(dbName);
- // check to see that the backend connection was successfully made
- if ( data.ConnectionBad() ) {
- cerr << "Connection to database '" << dbName << "' failed." << endl
- << "Error returned: " << data.ErrorMessage() << endl;
- exit(1);
- }
+ // check to see that the backend connection was successfully made
+ 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") ) {
- cerr << "BEGIN command failed" << endl;
- exit(1);
- }
+ // start a transaction block
+ 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") ) {
- cerr << "DECLARE CURSOR command failed" << endl;
- exit(1);
- }
+ // submit command to the backend
+ 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") ) {
- 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;
+ // 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;
+ exit(1);
+ }
- // 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);
- cout << endl;
- }
+ // 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;
- // Close the portal
- data.Exec("CLOSE myportal");
+ // 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);
+ cout << endl;
+ }
- // End the transaction
- data.Exec("END");
- return 0;
+ // Close the portal
+ data.Exec("CLOSE myportal");
+
+ // End the transaction
+ data.Exec("END");
+ return 0;
}
-
+
diff --git a/src/interfaces/libpq++/examples/testlibpq2.cc b/src/interfaces/libpq++/examples/testlibpq2.cc
index 1a602e16b73..9bad37e3cdf 100644
--- a/src/interfaces/libpq++/examples/testlibpq2.cc
+++ b/src/interfaces/libpq++/examples/testlibpq2.cc
@@ -1,10 +1,10 @@
/*
- * 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>
@@ -12,46 +12,50 @@
int main()
{
- // Begin, by establishing a connection to the backend.
- // When no parameters are given then the system will
- // try to use reasonable defaults by looking up environment variables
- // or, failing that, using hardwired constants
- const char* dbName = "dbname=template1";
- PgTransaction data(dbName);
-
- // check to see that the backend connection was successfully made
- 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") ) {
- 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;
- 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
- 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;
- }
-
- // close the portal
- data.Exec("CLOSE myportal");
- return 0;
+ // Begin, by establishing a connection to the backend.
+ // When no parameters are given then the system will
+ // try to use reasonable defaults by looking up environment variables
+ // or, failing that, using hardwired constants
+ const char* dbName = "dbname=template1";
+ PgTransaction data(dbName);
+
+ // check to see that the backend connection was successfully made
+ 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") )
+ {
+ 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;
+ 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
+ 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;
+ }
+
+ // close the portal
+ data.Exec("CLOSE myportal");
+ return 0;
}
diff --git a/src/interfaces/libpq++/examples/testlibpq3.cc b/src/interfaces/libpq++/examples/testlibpq3.cc
index da0c48df354..fa2625f5b28 100644
--- a/src/interfaces/libpq++/examples/testlibpq3.cc
+++ b/src/interfaces/libpq++/examples/testlibpq3.cc
@@ -1,11 +1,11 @@
/*
- * 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>
@@ -13,45 +13,49 @@
int main()
{
- // Begin, by establishing a connection to the backend.
- // When no parameters are given then the system will
- // try to use reasonable defaults by looking up environment variables
- // or, failing that, using hardwired constants.
- // Create a cursor database query object.
- // All queries using cursor will be performed through this object.
- const char* dbName = "dbname=template1";
- PgCursor cData(dbName, "myportal");
+ // Begin, by establishing a connection to the backend.
+ // When no parameters are given then the system will
+ // try to use reasonable defaults by looking up environment variables
+ // or, failing that, using hardwired constants.
+ // Create a cursor database query object.
+ // All queries using cursor will be performed through this object.
+ const char* dbName = "dbname=template1";
+ PgCursor cData(dbName, "myportal");
- // check to see that the backend connection was successfully made
- 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") ) {
- cerr << "DECLARE CURSOR command failed" << endl;
- exit(1);
- }
+ // check to see that the backend connection was successfully made
+ if ( cData.ConnectionBad() )
+ {
+ cerr << "Connection to database '" << dbName << "' failed." << endl
+ << "Error returned: " << cData.ErrorMessage() << endl;
+ exit(1);
+ }
- // fetch instances from the pg_cDatabase, the system catalog of cDatabases
- 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++)
- cout << setiosflags(ios::right) << setw(15) << cData.FieldName(i);
- cout << endl << endl;
+ // submit command to the backend
+ if ( !cData.Declare("select * from pg_database") )
+ {
+ cerr << "DECLARE CURSOR command failed" << endl;
+ exit(1);
+ }
- // 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;
+ // fetch instances from the pg_cDatabase, the system catalog of cDatabases
+ 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++)
+ 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;
}
diff --git a/src/interfaces/libpq++/examples/testlibpq4.cc b/src/interfaces/libpq++/examples/testlibpq4.cc
index a3248ea2586..6be620e0736 100644
--- a/src/interfaces/libpq++/examples/testlibpq4.cc
+++ b/src/interfaces/libpq++/examples/testlibpq4.cc
@@ -1,8 +1,8 @@
/*
- * testlibpq4.cc
- * Test of the asynchronous notification interface
- *
- populate a test database with the following (use testlibpq4.sql):
+* testlibpq4.cc
+* Test of the asynchronous notification interface
+*
+ populate a test database with the following (use testlibpq4.sql):
CREATE TABLE TBL1 (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];
- * 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>
int main()
{
- // Begin, by connecting to the backend using hardwired constants
- // and a test database created by the user prior to the invokation
- // of this test program.
- const char* dbName = "dbname=template1";
- PgDatabase data(dbName);
-
- // Check to see that the backend connection was successfully made
- if ( data.ConnectionBad() ) {
- cerr << "Connection to database '" << dbName << "' failed." << endl
- << data.ErrorMessage() << endl;
- exit(1);
- }
-
- // Listen to a table
- if ( !data.ExecCommandOk("LISTEN TBL2") ) {
- cerr << "LISTEN command failed" << endl;
- exit(1);
- }
-
- // Test asynchronous notification
- while (1) {
- // check for asynchronous returns
- PGnotify* notify = data.Notifies();
- if (notify) {
- cerr << "ASYNC NOTIFY of '" << notify->relname
- << "' from backend pid '" << notify->be_pid
- << "' received" << endl;
- free(notify);
- break;
- }
- }
- return 0;
+ // Begin, by connecting to the backend using hardwired constants
+ // and a test database created by the user prior to the invokation
+ // of this test program.
+ const char* dbName = "dbname=template1";
+ PgDatabase data(dbName);
+
+ // Check to see that the backend connection was successfully made
+ if ( data.ConnectionBad() )
+ {
+ cerr << "Connection to database '" << dbName << "' failed." << endl
+ << data.ErrorMessage() << endl;
+ exit(1);
+ }
+
+ // Listen to a table
+ if ( !data.ExecCommandOk("LISTEN TBL2") )
+ {
+ cerr << "LISTEN command failed" << endl;
+ exit(1);
+ }
+
+ // Test asynchronous notification
+ while (1)
+ {
+ // check for asynchronous returns
+ PGnotify* notify = data.Notifies();
+ if (notify)
+ {
+ cerr << "ASYNC NOTIFY of '" << notify->relname
+ << "' from backend pid '" << notify->be_pid
+ << "' received" << endl;
+ free(notify);
+ break;
+ }
+ }
+ return 0;
}
diff --git a/src/interfaces/libpq++/examples/testlibpq5.cc b/src/interfaces/libpq++/examples/testlibpq5.cc
index 04e600d5316..086a598cc7c 100644
--- a/src/interfaces/libpq++/examples/testlibpq5.cc
+++ b/src/interfaces/libpq++/examples/testlibpq5.cc
@@ -1,103 +1,108 @@
/*
- * 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);
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
}
int main()
{
- // Begin, by connecting to the backend using hardwired constants
- // and a test database created by the user prior to the invokation
- // of this test program. Connect using cursor interface.
- const char* dbName = "dbname=template1"; // change this to the name of your test database
- PgCursor data(dbName, "mycursor");
-
- // check to see that the backend connection was successfully made
- 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) ) {
- 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;
- exit(1);
- }
-
- // Find the field numbers for the columns 'i', 'd', and 'p'
- int i_fnum = data.FieldNum("i");
- 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));
- }
-*/
+ // Begin, by connecting to the backend using hardwired constants
+ // and a test database created by the user prior to the invokation
+ // of this test program. Connect using cursor interface.
+ const char* dbName = "dbname=template1"; // change this to the name of your test database
+ PgCursor data(dbName, "mycursor");
+
+ // check to see that the backend connection was successfully made
+ 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) )
+ {
+ 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;
+ exit(1);
+ }
+
+ // Find the field numbers for the columns 'i', 'd', and 'p'
+ int i_fnum = data.FieldNum("i");
+ 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++)
+ {
+ // 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
- 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;
-
- // Deallocate memory allocated for the Polygon structure
- free(pval);
- }
- return 0;
+ // Deallocate memory allocated for the Polygon structure
+ free(pval);
+ }
+ return 0;
}
diff --git a/src/interfaces/libpq++/examples/testlibpq6.cc b/src/interfaces/libpq++/examples/testlibpq6.cc
index 2a6dc92ed5c..29b84c0cbe2 100644
--- a/src/interfaces/libpq++/examples/testlibpq6.cc
+++ b/src/interfaces/libpq++/examples/testlibpq6.cc
@@ -1,60 +1,68 @@
/*
- * 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>
int main()
{
- // Begin, by connecting to the backend using hardwired constants
- // and a test database created by the user prior to the invokation
- // of this test program. Connect using transaction interface.
- const char* dbName = "dbname=template1";
- PgTransaction data(dbName);
+ // Begin, by connecting to the backend using hardwired constants
+ // and a test database created by the user prior to the invokation
+ // of this test program. Connect using transaction interface.
+ const char* dbName = "dbname=template1";
+ PgTransaction data(dbName);
- // check to see that the backend connection was successfully made
- if ( data.ConnectionBad() ) {
- cerr << "Connection to database '" << dbName << "' failed." << endl
- << data.ErrorMessage();
- exit(1);
- }
- else cout << "Connected to database '" << dbName << "'..." << endl;
+ // check to see that the backend connection was successfully made
+ if ( data.ConnectionBad() )
+ {
+ cerr << "Connection to database '" << dbName << "' failed." << endl
+ << data.ErrorMessage();
+ exit(1);
+ }
+ else
+ cout << "Connected to database '" << dbName << "'..." << endl;
- // Create a new table
- 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;
+ // Create a new table
+ 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;
- // Initiate Copy command
- if ( data.ExecCommandOk("COPY foo FROM STDIN") ) {
- cerr << "COPY foo FROM STDIN" << endl;
- exit(1);
- }
- else cout << "COPY foo FROM STDIN was successful.." << endl;
+ // Initiate Copy command
+ if ( data.ExecCommandOk("COPY foo FROM STDIN") )
+ {
+ cerr << "COPY foo FROM STDIN" << endl;
+ exit(1);
+ }
+ else
+ cout << "COPY foo FROM STDIN was successful.." << endl;
- // Put some test data into the table
- data.PutLine("3\thello world\t4.5\n");
- cout << "Line: \"3\thello world\t4.5\" copied..." << endl;
- data.PutLine("4\tgoodbye word\t7.11\n");
- cout << "Line: \"4\tgoodbye word\t7.11\" copied..." << endl;
- data.PutLine("\\.\n");
- cout << "Line: \"\\.\" copied..." << endl;
- if ( !data.EndCopy() )
- cout << "Ended COPY succesfully..." << 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;
-
- // Drop the test table
- data.Exec("DROP TABLE foo");
- return 0;
+ // Put some test data into the table
+ data.PutLine("3\thello world\t4.5\n");
+ cout << "Line: \"3\thello world\t4.5\" copied..." << endl;
+ data.PutLine("4\tgoodbye word\t7.11\n");
+ cout << "Line: \"4\tgoodbye word\t7.11\" copied..." << endl;
+ data.PutLine("\\.\n");
+ cout << "Line: \"\\.\" copied..." << endl;
+ if ( !data.EndCopy() )
+ cout << "Ended COPY succesfully..." << 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;
+
+ // Drop the test table
+ data.Exec("DROP TABLE foo");
+ return 0;
}
diff --git a/src/interfaces/libpq++/examples/testlo.cc b/src/interfaces/libpq++/examples/testlo.cc
index 0fd516c04fc..04ea8071dc0 100644
--- a/src/interfaces/libpq++/examples/testlo.cc
+++ b/src/interfaces/libpq++/examples/testlo.cc
@@ -1,50 +1,52 @@
/*-------------------------------------------------------------------------
- *
- * 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>
int main(int argc, char **argv)
{
- // Check if the program was invoked correctly; if not, signal error
- if (argc < 4 || argc > 5) {
- cerr << "Usage: " << argv[0] << " conninfo_str in_filename out_filename [oid]" << endl;
- exit(1);
- }
+ // Check if the program was invoked correctly; if not, signal error
+ if (argc < 4 || argc > 5)
+ {
+ cerr << "Usage: " << argv[0] << " conninfo_str in_filename out_filename [oid]" << endl;
+ exit(1);
+ }
- // Get the arguments passed to the program
- char* conninfo = argv[1];
- char* in_filename = argv[2];
- char* out_filename = argv[3];
+ // Get the arguments passed to the program
+ char* conninfo = argv[1];
+ char* in_filename = argv[2];
+ char* out_filename = argv[3];
- // Set up the connection and create a large object
- int lobjId = ( argc == 4 ? 0 : atoi(argv[4]) );
- PgLargeObject object(lobjId, conninfo);
+ // Set up the connection and create a large object
+ int lobjId = ( argc == 4 ? 0 : atoi(argv[4]) );
+ PgLargeObject object(lobjId, conninfo);
- // check to see that the backend connection was successfully made
- if ( object.ConnectionBad() ) {
- cerr << "Connection with conninfo '" << conninfo << "' failed." << endl
- << object.ErrorMessage();
- exit(1);
- }
+ // check to see that the backend connection was successfully made
+ if ( object.ConnectionBad() )
+ {
+ cerr << "Connection with conninfo '" << conninfo << "' failed." << endl
+ << object.ErrorMessage();
+ exit(1);
+ }
- // Test the import and export features of the Large Object interface
- object.Exec("BEGIN");
- cout << "Importing file \"" << in_filename << "\"..." << endl;
- object.Import(in_filename);
- cout << "Exporting large object to file \"" << out_filename << "\"..." << endl;
- object.Export(out_filename);
- object.Exec("END"); // WHY DOES IT CORE DUMP HERE ???
- return 0;
+ // Test the import and export features of the Large Object interface
+ object.Exec("BEGIN");
+ cout << "Importing file \"" << in_filename << "\"..." << endl;
+ object.Import(in_filename);
+ cout << "Exporting large object to file \"" << out_filename << "\"..." << endl;
+ object.Export(out_filename);
+ object.Exec("END"); // WHY DOES IT CORE DUMP HERE ???
+ return 0;
}