diff options
Diffstat (limited to 'src/interfaces/libpq++/examples')
-rw-r--r-- | src/interfaces/libpq++/examples/Makefile | 38 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq0.cc | 52 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq1.cc | 68 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq2.cc | 57 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq2.sql | 5 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq3.cc | 57 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq3.sql | 6 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq4.cc | 59 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq4.sql | 5 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq5.cc | 103 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq5.sql | 6 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlibpq6.cc | 60 | ||||
-rw-r--r-- | src/interfaces/libpq++/examples/testlo.cc | 50 |
13 files changed, 0 insertions, 566 deletions
diff --git a/src/interfaces/libpq++/examples/Makefile b/src/interfaces/libpq++/examples/Makefile deleted file mode 100644 index d2e9b16a03e..00000000000 --- a/src/interfaces/libpq++/examples/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -#------------------------------------------------------------------------- -# -# Makefile for libpq++ examples -# -# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group -# Portions Copyright (c) 1994, Regents of the University of California -# -# $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/Makefile,v 1.14 2002/06/20 20:29:54 momjian Exp $ -# -#------------------------------------------------------------------------- - -subdir = src/interfaces/libpq++/examples -top_builddir = ../../../.. -include $(top_builddir)/src/Makefile.global - -LIBNAME= libpq++ -HEADERDIR= $(includedir) -LIBPQDIR= $(libdir) - -CXXFLAGS= $(CFLAGS) - -CXXFLAGS+= -I$(HEADERDIR) - -LDFLAGS+= -L$(LIBPQDIR) -lpq++ - -PROGS= testlibpq0 testlibpq1 testlibpq2 testlibpq3 \ - testlibpq4 testlibpq5 testlibpq6 testlo - -all: $(PROGS) - -$(PROGS): % : %.cc - $(CXX) $(CXXFLAGS) -o $@ $@.cc $(LDFLAGS) - -.PHONY: submake - -clean: - rm -f $(PROGS) - diff --git a/src/interfaces/libpq++/examples/testlibpq0.cc b/src/interfaces/libpq++/examples/testlibpq0.cc deleted file mode 100644 index 041ced557fc..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq0.cc +++ /dev/null @@ -1,52 +0,0 @@ -/*------------------------------------------------------------------------- - * - * 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 $ - * - *------------------------------------------------------------------------- - */ - -#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; -} // End main() diff --git a/src/interfaces/libpq++/examples/testlibpq1.cc b/src/interfaces/libpq++/examples/testlibpq1.cc deleted file mode 100644 index 5c71c906b9f..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq1.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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> -#include "libpq++.h" - -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); - - // 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); - } - - // 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"); - - // End the transaction - data.Exec("END"); - return 0; -} - - diff --git a/src/interfaces/libpq++/examples/testlibpq2.cc b/src/interfaces/libpq++/examples/testlibpq2.cc deleted file mode 100644 index 1a602e16b73..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq2.cc +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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> -#include "libpq++.h" - -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; -} diff --git a/src/interfaces/libpq++/examples/testlibpq2.sql b/src/interfaces/libpq++/examples/testlibpq2.sql deleted file mode 100644 index f9c74109328..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq2.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE TBL1 (i int4); - -CREATE TABLE TBL2 (i int4); - -CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values (new.i); NOTIFY TBL2]; diff --git a/src/interfaces/libpq++/examples/testlibpq3.cc b/src/interfaces/libpq++/examples/testlibpq3.cc deleted file mode 100644 index da0c48df354..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq3.cc +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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> -#include "libpq++.h" - -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"); - - // 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); - } - - // 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/testlibpq3.sql b/src/interfaces/libpq++/examples/testlibpq3.sql deleted file mode 100644 index f024c0b071b..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq3.sql +++ /dev/null @@ -1,6 +0,0 @@ -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); - diff --git a/src/interfaces/libpq++/examples/testlibpq4.cc b/src/interfaces/libpq++/examples/testlibpq4.cc deleted file mode 100644 index a3248ea2586..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq4.cc +++ /dev/null @@ -1,59 +0,0 @@ -/* - * testlibpq4.cc - * Test of the asynchronous notification interface - * - populate a test database with the following (use testlibpq4.sql): - -CREATE TABLE TBL1 (i int4); - -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 - -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; -} diff --git a/src/interfaces/libpq++/examples/testlibpq4.sql b/src/interfaces/libpq++/examples/testlibpq4.sql deleted file mode 100644 index 53d3fdfffad..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq4.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE TBL1 (i int4); - -CREATE TABLE TBL2 (i int4); - -CREATE RULE r1 AS ON INSERT TO TBL1 DO (INSERT INTO TBL2 values (new.i); NOTIFY TBL2); diff --git a/src/interfaces/libpq++/examples/testlibpq5.cc b/src/interfaces/libpq++/examples/testlibpq5.cc deleted file mode 100644 index 04e600d5316..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq5.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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: - -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) -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) - - * - */ -#include <iostream.h> -#include "libpq++.h" -#include <stdlib.h> -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)); - } -*/ - - // 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; -} diff --git a/src/interfaces/libpq++/examples/testlibpq5.sql b/src/interfaces/libpq++/examples/testlibpq5.sql deleted file mode 100644 index f024c0b071b..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq5.sql +++ /dev/null @@ -1,6 +0,0 @@ -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); - diff --git a/src/interfaces/libpq++/examples/testlibpq6.cc b/src/interfaces/libpq++/examples/testlibpq6.cc deleted file mode 100644 index 2a6dc92ed5c..00000000000 --- a/src/interfaces/libpq++/examples/testlibpq6.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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); - - // 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; - - // 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; -} diff --git a/src/interfaces/libpq++/examples/testlo.cc b/src/interfaces/libpq++/examples/testlo.cc deleted file mode 100644 index 0fd516c04fc..00000000000 --- a/src/interfaces/libpq++/examples/testlo.cc +++ /dev/null @@ -1,50 +0,0 @@ -/*------------------------------------------------------------------------- - * - * 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 $ - * - *------------------------------------------------------------------------- - */ -#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); - } - - // 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); - - // 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; -} |