diff options
| author | Bruce Momjian <bruce@momjian.us> | 2002-07-02 16:32:19 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 2002-07-02 16:32:19 +0000 |
| commit | a4485ea894ddd622daa81009d1556c95cd357781 (patch) | |
| tree | 40b5d89b6807e7e2088300eb5b113bf9604b47c8 /src/interfaces/libpq++/examples/testlibpq3.cc | |
| parent | c9a734521712797b1cd6a77bf9cabfe4c503e186 (diff) | |
| download | postgresql-a4485ea894ddd622daa81009d1556c95cd357781.tar.gz | |
Indent libpq++ as mentioned in email. Format was terrible, and this
will make fixing things easier.
Diffstat (limited to 'src/interfaces/libpq++/examples/testlibpq3.cc')
| -rw-r--r-- | src/interfaces/libpq++/examples/testlibpq3.cc | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/src/interfaces/libpq++/examples/testlibpq3.cc b/src/interfaces/libpq++/examples/testlibpq3.cc index da0c48df35..fa2625f5b2 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; } |
