summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq++/examples/testlibpq6.cc
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1997-02-13 10:01:05 +0000
committerMarc G. Fournier <scrappy@hub.org>1997-02-13 10:01:05 +0000
commiteacd0fd938663b8c673d8e3ac9549c9f3b7b463d (patch)
tree6c4f11621fc2fd649d2864a7b9a907cbcbf97df7 /src/interfaces/libpq++/examples/testlibpq6.cc
parentd62267c70706b7d60895401aae1346cf6cd7cead (diff)
downloadpostgresql-eacd0fd938663b8c673d8e3ac9549c9f3b7b463d.tar.gz
Bring in Leo's <lsh@lubrizol.com> massive changes to libpq++
Diffstat (limited to 'src/interfaces/libpq++/examples/testlibpq6.cc')
-rw-r--r--src/interfaces/libpq++/examples/testlibpq6.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/interfaces/libpq++/examples/testlibpq6.cc b/src/interfaces/libpq++/examples/testlibpq6.cc
new file mode 100644
index 0000000000..bbf1043a0b
--- /dev/null
+++ b/src/interfaces/libpq++/examples/testlibpq6.cc
@@ -0,0 +1,59 @@
+/*
+ * 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>
+
+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.
+ char* dbName = getenv("USER"); // change this to the name of your test database
+ 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 char16, 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");
+}