Skip to content

Commit a4485ea

Browse files
committed
Indent libpq++ as mentioned in email. Format was terrible, and this
will make fixing things easier.
1 parent c9a7345 commit a4485ea

19 files changed

+982
-915
lines changed
Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
/*-------------------------------------------------------------------------
2-
*
3-
* testlibpq0.c--
4-
* small test program for libpq++,
5-
* small interactive loop where queries can be entered interactively
6-
* and sent to the backend
7-
*
8-
* Copyright (c) 1994, Regents of the University of California
9-
*
10-
*
11-
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.6 2000/05/29 21:25:04 momjian Exp $
13-
*
14-
*-------------------------------------------------------------------------
15-
*/
2+
*
3+
* testlibpq0.c--
4+
* small test program for libpq++,
5+
* small interactive loop where queries can be entered interactively
6+
* and sent to the backend
7+
*
8+
* Copyright (c) 1994, Regents of the University of California
9+
*
10+
*
11+
* IDENTIFICATION
12+
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.7 2002/07/02 16:32:19 momjian Exp $
13+
*
14+
*-------------------------------------------------------------------------
15+
*/
1616

1717
#include <iostream.h>
1818
#include "libpq++.h"
1919

2020
int main()
2121
{
22-
// Open the connection to the database and make sure it's OK
23-
PgDatabase data("dbname=template1");
24-
if ( data.ConnectionBad() ) {
25-
cout << "Connection was unsuccessful..." << endl
26-
<< "Error message returned: " << data.ErrorMessage() << endl;
27-
return 1;
28-
}
29-
else
30-
cout << "Connection successful... Enter queries below:" << endl;
31-
32-
// Interactively obtain and execute queries
33-
ExecStatusType status;
34-
string buf;
35-
int done = 0;
36-
while (!done)
37-
{
38-
cout << "> ";
39-
cout.flush();
40-
getline(cin, buf);
41-
if ( buf != "" )
42-
if ( (status = data.Exec( buf.c_str() )) == PGRES_TUPLES_OK )
43-
data.DisplayTuples();
44-
else
45-
cout << "No tuples returned..." << endl
46-
<< "status = " << status << endl
47-
<< "Error returned: " << data.ErrorMessage() << endl;
48-
else
49-
done = 1;
50-
}
51-
return 0;
22+
// Open the connection to the database and make sure it's OK
23+
PgDatabase data("dbname=template1");
24+
if ( data.ConnectionBad() )
25+
{
26+
cout << "Connection was unsuccessful..." << endl
27+
<< "Error message returned: " << data.ErrorMessage() << endl;
28+
return 1;
29+
}
30+
else
31+
cout << "Connection successful... Enter queries below:" << endl;
32+
33+
// Interactively obtain and execute queries
34+
ExecStatusType status;
35+
string buf;
36+
int done = 0;
37+
while (!done)
38+
{
39+
cout << "> ";
40+
cout.flush();
41+
getline(cin, buf);
42+
if ( buf != "" )
43+
if ( (status = data.Exec( buf.c_str() )) == PGRES_TUPLES_OK )
44+
data.DisplayTuples();
45+
else
46+
cout << "No tuples returned..." << endl
47+
<< "status = " << status << endl
48+
<< "Error returned: " << data.ErrorMessage() << endl;
49+
else
50+
done = 1;
51+
}
52+
return 0;
5253
} // End main()
Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,73 @@
11
/*
2-
* testlibpq1.cc
3-
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
4-
*
5-
* queries the template1 database for a list of database names
6-
*
7-
*/
2+
* testlibpq1.cc
3+
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
4+
*
5+
* queries the template1 database for a list of database names
6+
*
7+
*/
88

99
#include <iostream.h>
1010
#include <iomanip.h>
1111
#include "libpq++.h"
1212

1313
int main()
1414
{
15-
// Begin, by establishing a connection to the backend.
16-
// When no parameters are given then the system will
17-
// try to use reasonable defaults by looking up environment variables
18-
// or, failing that, using hardwired constants
19-
const char* dbName = "dbname=template1";
20-
PgDatabase data(dbName);
15+
// Begin, by establishing a connection to the backend.
16+
// When no parameters are given then the system will
17+
// try to use reasonable defaults by looking up environment variables
18+
// or, failing that, using hardwired constants
19+
const char* dbName = "dbname=template1";
20+
PgDatabase data(dbName);
2121

22-
// check to see that the backend connection was successfully made
23-
if ( data.ConnectionBad() ) {
24-
cerr << "Connection to database '" << dbName << "' failed." << endl
25-
<< "Error returned: " << data.ErrorMessage() << endl;
26-
exit(1);
27-
}
22+
// check to see that the backend connection was successfully made
23+
if ( data.ConnectionBad() )
24+
{
25+
cerr << "Connection to database '" << dbName << "' failed." << endl
26+
<< "Error returned: " << data.ErrorMessage() << endl;
27+
exit(1);
28+
}
2829

29-
// start a transaction block
30-
if ( !data.ExecCommandOk("BEGIN") ) {
31-
cerr << "BEGIN command failed" << endl;
32-
exit(1);
33-
}
30+
// start a transaction block
31+
if ( !data.ExecCommandOk("BEGIN") )
32+
{
33+
cerr << "BEGIN command failed" << endl;
34+
exit(1);
35+
}
3436

35-
// submit command to the backend
36-
if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") ) {
37-
cerr << "DECLARE CURSOR command failed" << endl;
38-
exit(1);
39-
}
37+
// submit command to the backend
38+
if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") )
39+
{
40+
cerr << "DECLARE CURSOR command failed" << endl;
41+
exit(1);
42+
}
4043

41-
// fetch instances from the pg_database, the system catalog of databases
42-
if ( !data.ExecTuplesOk("FETCH ALL in myportal") ) {
43-
cerr << "FETCH ALL command didn't return tuples properly" << endl;
44-
exit(1);
45-
}
46-
47-
// first, print out the attribute names
48-
int nFields = data.Fields();
49-
for (int i=0; i < nFields; i++)
50-
cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
51-
cout << endl << endl;
44+
// fetch instances from the pg_database, the system catalog of databases
45+
if ( !data.ExecTuplesOk("FETCH ALL in myportal") )
46+
{
47+
cerr << "FETCH ALL command didn't return tuples properly" << endl;
48+
exit(1);
49+
}
5250

53-
// next, print out the instances
54-
for (int i=0; i < data.Tuples(); i++) {
55-
for (int j=0; j < nFields; j++)
56-
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i,j);
57-
cout << endl;
58-
}
51+
// first, print out the attribute names
52+
int nFields = data.Fields();
53+
for (int i = 0; i < nFields; i++)
54+
cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
55+
cout << endl << endl;
5956

60-
// Close the portal
61-
data.Exec("CLOSE myportal");
57+
// next, print out the instances
58+
for (int i = 0; i < data.Tuples(); i++)
59+
{
60+
for (int j = 0; j < nFields; j++)
61+
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j);
62+
cout << endl;
63+
}
6264

63-
// End the transaction
64-
data.Exec("END");
65-
return 0;
65+
// Close the portal
66+
data.Exec("CLOSE myportal");
67+
68+
// End the transaction
69+
data.Exec("END");
70+
return 0;
6671
}
67-
72+
6873

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
11
/*
2-
* testlibpq2.cc
3-
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
4-
*
5-
* queries the template1 database for a list of database names using transaction block
6-
*
7-
*/
2+
* testlibpq2.cc
3+
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
4+
*
5+
* queries the template1 database for a list of database names using transaction block
6+
*
7+
*/
88

99
#include <iostream.h>
1010
#include <iomanip.h>
1111
#include "libpq++.h"
1212

1313
int main()
1414
{
15-
// Begin, by establishing a connection to the backend.
16-
// When no parameters are given then the system will
17-
// try to use reasonable defaults by looking up environment variables
18-
// or, failing that, using hardwired constants
19-
const char* dbName = "dbname=template1";
20-
PgTransaction data(dbName);
21-
22-
// check to see that the backend connection was successfully made
23-
if ( data.ConnectionBad() ) {
24-
cerr << "Connection to database '" << dbName << "' failed." << endl
25-
<< "Error returned: " << data.ErrorMessage() << endl;
26-
exit(1);
27-
}
28-
29-
// submit command to the backend
30-
if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") ) {
31-
cerr << "DECLARE CURSOR command failed" << endl;
32-
exit(1);
33-
}
34-
35-
// fetch instances from the pg_database, the system catalog of databases
36-
if ( !data.ExecTuplesOk("FETCH ALL in myportal") ) {
37-
cerr << "FETCH ALL command didn't return tuples properly" << endl;
38-
exit(1);
39-
}
40-
41-
// first, print out the attribute names
42-
int nFields = data.Fields();
43-
for (int i=0; i < nFields; i++)
44-
cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
45-
cout << endl << endl;
46-
47-
// next, print out the instances
48-
for (int i=0; i < data.Tuples(); i++) {
49-
for (int j=0; j < nFields; j++)
50-
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i,j);
51-
cout << endl;
52-
}
53-
54-
// close the portal
55-
data.Exec("CLOSE myportal");
56-
return 0;
15+
// Begin, by establishing a connection to the backend.
16+
// When no parameters are given then the system will
17+
// try to use reasonable defaults by looking up environment variables
18+
// or, failing that, using hardwired constants
19+
const char* dbName = "dbname=template1";
20+
PgTransaction data(dbName);
21+
22+
// check to see that the backend connection was successfully made
23+
if ( data.ConnectionBad() )
24+
{
25+
cerr << "Connection to database '" << dbName << "' failed." << endl
26+
<< "Error returned: " << data.ErrorMessage() << endl;
27+
exit(1);
28+
}
29+
30+
// submit command to the backend
31+
if ( !data.ExecCommandOk("DECLARE myportal CURSOR FOR select * from pg_database") )
32+
{
33+
cerr << "DECLARE CURSOR command failed" << endl;
34+
exit(1);
35+
}
36+
37+
// fetch instances from the pg_database, the system catalog of databases
38+
if ( !data.ExecTuplesOk("FETCH ALL in myportal") )
39+
{
40+
cerr << "FETCH ALL command didn't return tuples properly" << endl;
41+
exit(1);
42+
}
43+
44+
// first, print out the attribute names
45+
int nFields = data.Fields();
46+
for (int i = 0; i < nFields; i++)
47+
cout << setiosflags(ios::right) << setw(15) << data.FieldName(i);
48+
cout << endl << endl;
49+
50+
// next, print out the instances
51+
for (int i = 0; i < data.Tuples(); i++)
52+
{
53+
for (int j = 0; j < nFields; j++)
54+
cout << setiosflags(ios::right) << setw(15) << data.GetValue(i, j);
55+
cout << endl;
56+
}
57+
58+
// close the portal
59+
data.Exec("CLOSE myportal");
60+
return 0;
5761
}

0 commit comments

Comments
 (0)