aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq++/examples/testlibpq1.cc
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/testlibpq1.cc
parentc9a734521712797b1cd6a77bf9cabfe4c503e186 (diff)
downloadpostgresql-a4485ea894ddd622daa81009d1556c95cd357781.tar.gz
postgresql-a4485ea894ddd622daa81009d1556c95cd357781.zip
Indent libpq++ as mentioned in email. Format was terrible, and this
will make fixing things easier.
Diffstat (limited to 'src/interfaces/libpq++/examples/testlibpq1.cc')
-rw-r--r--src/interfaces/libpq++/examples/testlibpq1.cc107
1 files changed, 56 insertions, 51 deletions
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;
}
-
+