Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteacd0fd

Browse files
committed
Bring in Leo's <lsh@lubrizol.com> massive changes to libpq++
1 parentd62267c commiteacd0fd

25 files changed

+1332
-603
lines changed

‎src/interfaces/libpq++/Makefile‎

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/Makefile,v 1.5 1996/11/18 01:43:54 bryanh Exp $
10+
# $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/Makefile,v 1.6 1997/02/13 10:00:23 scrappy Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

1414
SRCDIR= ..
1515
include ../Makefile.global
16+
SRCHEADERDIR = ../include
17+
LIBPQHEADERDIR =$(SRCHEADERDIR)/libpq
18+
19+
LIBNAME= libpq++
1620

1721
# We have to override -Werror, which makes warnings, fatal, because we
1822
# inevitably get the warning, "abstract declarator used as declaration"
@@ -22,48 +26,72 @@ CXXFLAGS= $(CFLAGS) -Wno-error
2226

2327
INCLUDE_OPT=\
2428
-I../backend\
25-
-I../include\
26-
-I$(LIBPQDIR)
29+
-I$(SRCHEADERDIR)\
30+
-I$(LIBPQDIR)
2731

2832
CXXFLAGS+=$(INCLUDE_OPT)
33+
#CXXFLAGS+= -DDEBUG
2934

3035
ifdefKRBVERS
3136
CXXFLAGS+=$(KRBFLAGS)
3237
endif
3338

34-
OBJS= pgenv.o pgconnection.o pglobject.o
3539

36-
all: libpq++.a examples
40+
OBJS = pgenv.o pgconnection.o pgtransdb.o pgcursordb.o pglobject.o
41+
42+
all:$(LIBNAME).a install examples
3743

38-
libpq++.a:$(OBJS)
44+
$(LIBNAME).a:$(OBJS)
3945
ifdefMK_NO_LORDER
40-
$(AR) $(AROPT)libpq++.a $(OBJS)
46+
$(AR) $(AROPT)$(LIBNAME).a $(OBJS)
4147
else
42-
$(AR) $(AROPT)libpq++.a `lorder $(OBJS) | tsort`
48+
$(AR) $(AROPT)$(LIBNAME).a `lorder $(OBJS) | tsort`
4349
endif
44-
$(RANLIB)libpq++.a
50+
$(RANLIB)$(LIBNAME).a
4551

4652
.PHONY: examples
4753
examples:
4854
$(MAKE) -C examples all
4955

5056
.PHONY: beforeinstall-headers install-headers
51-
.PHONY: install install-libpq++ doc
52-
53-
install: install-headers install-libpq++ doc
54-
55-
install-headers: beforeinstall-headers libpq++.H
56-
$(INSTALL)$(INSTLOPTS) libpq++.H$(HEADERDIR)/libpq++.H
57+
.PHONY: install install-$(LIBNAME) doc
58+
59+
install: install-headers install-$(LIBNAME) doc
60+
61+
LIBPGXXDIR =$(LIBNAME)
62+
LIBPGXXHEADERDIR =$(HEADERDIR)/$(LIBPGXXDIR)
63+
MAINHEADER =$(LIBNAME).h
64+
LIBPGXXHEADERS = pgenv.h\
65+
pgconnection.h\
66+
pgdatabase.h\
67+
pgtransdb.h\
68+
pgcursordb.h\
69+
pglobject.h
70+
71+
install-headers: beforeinstall-headers$(MAINHEADER)
72+
@$(INSTALL)$(INSTLOPTS)$(MAINHEADER)$(HEADERDIR)/$(MAINHEADER)
73+
@for iin${LIBPGXXHEADERS};do\
74+
echo"Installing$(LIBPGXXHEADERDIR)/$$i.";\
75+
$(INSTALL)$(INSTLOPTS)$$i$(LIBPGXXHEADERDIR)/$$i;\
76+
done
5777

5878
beforeinstall-headers:
5979
@if [!-d$(HEADERDIR) ];then mkdir$(HEADERDIR);fi
80+
@if [!-d$(LIBPGXXHEADERDIR) ];then mkdir$(LIBPGXXHEADERDIR);fi
6081

61-
install-libpq++: libpq++.a
62-
$(INSTALL)$(INSTL_LIB_OPTS)libpq++.a$(DESTDIR)$(LIBDIR)/libpq++.a
82+
install-$(LIBNAME):$(LIBNAME).a
83+
$(INSTALL)$(INSTL_LIB_OPTS)$(LIBNAME).a$(DESTDIR)$(LIBDIR)/$(LIBNAME).a
6384

6485
doc:
6586
$(MAKE) -C man install
6687

6788
clean:
68-
rmlibpq++.a$(OBJS)
89+
rm$(LIBNAME).a$(OBJS)
6990
$(MAKE) -C examples clean
91+
92+
93+
###########################################################################
94+
# Dependencies for the library
95+
###########################################################################
96+
include ./dependencies
97+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
###########################################################################
2+
# Dependencies for libpq++ C++ library for Postgres SQL
3+
#
4+
# Author: Leo Shuster (lsh@lubrizol.com)
5+
###########################################################################
6+
pgenv.o ::pgenv.cc \
7+
pgenv.h
8+
9+
pgconnection.o :: pgconnection.cc \
10+
pgconnection.h \
11+
pgenv.h \
12+
$(LIBPQDIR)/libpq-fe.h \
13+
$(LIBPQDIR)/fe-auth.h
14+
15+
pgtransdb.o :: pgtransdb.cc \
16+
pgtransdb.h \
17+
pgdatabase.h \
18+
pgconnection.h \
19+
pgenv.h \
20+
$(LIBPQDIR)/libpq-fe.h \
21+
$(LIBPQDIR)/fe-auth.h
22+
23+
pgcursordb.o :: pgcursordb.cc \
24+
pgcursordb.h \
25+
pgdatabase.h \
26+
pgconnection.h \
27+
pgenv.h \
28+
$(LIBPQDIR)/libpq-fe.h \
29+
$(LIBPQDIR)/fe-auth.h
30+
31+
pglobject.o ::pglobject.cc \
32+
pglobject.h \
33+
pgconnection.h \
34+
pgenv.h \
35+
$(LIBPQDIR)/libpq-fe.h \
36+
$(LIBPQHEADERDIR)/libpq-fs.h

‎src/interfaces/libpq++/examples/Makefile‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
SRCDIR= ../..
66
include ../../Makefile.global
77

8+
LIBNAME= libpq++
9+
810
# We have to override -Werror, which makes warnings, fatal, because we
911
# inevitably get the warning, "abstract declarator used as declaration"
1012
# because of our inclusion of c.h and we don't know how to stop that.
@@ -15,8 +17,8 @@ INCLUDE_OPT= \
1517
-I..\
1618
-I../../backend\
1719
-I../../include\
18-
-I$(LIBPQDIR)
19-
20+
-I$(LIBPQDIR)\
21+
-I$(HEADERDIR)
2022
CXXFLAGS+=$(INCLUDE_OPT)
2123

2224
LD_ADD+= -L.. -lpq++ -L$(LIBPQDIR) -lpq
@@ -29,19 +31,21 @@ LD_ADD+= $(KRBLIBS)
2931
CXXFLAGS+=$(KRBFLAGS)
3032
endif
3133

32-
PROGS= testlibpq0 testlibpq1 testlibpq2 testlibpq3 testlibpq4 testlo
34+
PROGS=testlibpq0 testlibpq1 testlibpq2 testlibpq3\
35+
testlibpq4 testlibpq5 testlibpq6 testlo
3336

3437
all: submake$(PROGS)
3538

36-
$(PROGS):% :%.cc ../libpq++.a
39+
$(PROGS):% :%.cc ../$(LIBNAME).a
3740
$(CXX)$(CXXFLAGS)$(LDFLAGS) -o$@$@.cc$(LD_ADD)
3841

3942
.PHONY: submake
4043
submake:
41-
$(MAKE) -C..libpq++.a
44+
$(MAKE) -C..$(LIBNAME).a
4245

43-
../libpq++.a:
44-
$(MAKE) -C..libpq++.a
46+
../$(LIBNAME).a:
47+
$(MAKE) -C..$(LIBNAME).a
4548

4649
clean:
4750
rm -f$(PROGS)
51+

‎src/interfaces/libpq++/examples/testlibpq0.cc‎

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,44 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.2 1996/11/18 01:44:23 bryanh Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/libpq++/examples/Attic/testlibpq0.cc,v 1.3 1997/02/13 10:00:42 scrappy Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
1616

17-
#include<stdio.h>
18-
#include"libpq++.H"
17+
#include<iostream.h>
18+
#include<libpq++.h>
1919

20-
int
21-
main()
20+
intmain()
2221
{
22+
// Open the connection to the database and make sure it's OK
23+
PgDatabasedata("template1");
24+
if ( data.ConnectionBad() ) {
25+
cout <<"Connection was unsuccessful..." << endl
26+
<<"Error message returned:" << data.ErrorMessage() << endl;
27+
return1;
28+
}
29+
else
30+
cout <<"Connection successful... Enter queries below:" << endl;
31+
32+
// Interactively obtain and execute queries
2333
ExecStatusType status;
24-
PGenv env;
25-
PGdatabase* data;
26-
27-
char buf[10000];
34+
string buf;
2835
int done =0;
29-
30-
data =newPGdatabase(&env,"template1");
31-
32-
if (data->status() == CONNECTION_BAD)
33-
printf("connection was unsuccessful\n%s\n", data->errormessage());
34-
else
35-
printf("connection successful\n");
36-
3736
while (!done)
3837
{
39-
printf(">");fflush(stdout);
40-
if (gets(buf) && buf[0]!='\0')
41-
if((status = data->exec(buf)) == PGRES_TUPLES_OK)
42-
data->printtuples(stdout,1,"|",1,0);
43-
else
44-
printf("status = %d\nerrorMessage = %s\n", status,
45-
data->errormessage());
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;
4648
else
47-
done =1;
48-
}
49-
}
49+
done =1;
50+
}
51+
return0;
52+
}// End main()
Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,67 @@
11
/*
2-
*testlibpq.cc
2+
*testlibpq1.cc
33
* Test the C++ version of LIBPQ, the POSTGRES frontend library.
44
*
55
* queries the template1 database for a list of database names
66
*
77
*/
8-
#include<stdio.h>
9-
#include"libpq++.H"
108

11-
main()
12-
{
13-
char* dbName;
14-
int nFields;
15-
int i,j;
16-
17-
/* begin, by creating the parameter environtment for a backend
18-
connection. When no parameters are given then the system will
19-
try to use reasonable defaults by looking up environment variables
20-
or, failing that, using hardwired constants*/
21-
PGenv env;
22-
PGdatabase* data;
9+
#include<iostream.h>
10+
#include<iomanip.h>
11+
#include<libpq++.h>
2312

24-
/* Select a database*/
25-
dbName ="template1";
26-
27-
/* make a connection to the database*/
28-
data =newPGdatabase(&env, dbName);
13+
intmain()
14+
{
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+
constchar* dbName ="template1";
20+
PgDatabasedata(dbName);
2921

30-
/* check to see that the backend connection was successfully made*/
31-
if (data->status() == CONNECTION_BAD) {
32-
fprintf(stderr,"Connection to database '%s' failed.\n", dbName);
33-
fprintf(stderr,"%s",data->errormessage());
34-
delete data;
35-
exit(1);
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);
3627
}
3728

38-
/* start a transaction block*/
39-
if(data->exec("BEGIN") != PGRES_COMMAND_OK) {
40-
fprintf(stderr,"BEGIN command failed\n");
41-
delete data;
29+
// start a transaction block
30+
if ( !data.ExecCommandOk("BEGIN") ) {
31+
cerr <<"BEGIN command failed" << endl;
4232
exit(1);
4333
}
4434

45-
/* fetch instances from the pg_database, the system catalog of databases*/
46-
if (data->exec("DECLARE myportal CURSOR FOR select * from pg_database")
47-
!= PGRES_COMMAND_OK) {
48-
fprintf(stderr,"DECLARE CURSOR command failed\n");
49-
delete data;
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;
5038
exit(1);
5139
}
5240

53-
if(data->exec("FETCH ALL in myportal") != PGRES_TUPLES_OK) {
54-
fprintf(stderr,"FETCH ALLcommand didn't return tuples properly\n");
55-
delete data;
41+
// fetch instances from the pg_database, the system catalog of databases
42+
if ( !data.ExecTuplesOk("FETCH ALLin myportal") ) {
43+
cerr <<"FETCH ALL command didn't return tuples properly" << endl;
5644
exit(1);
5745
}
5846

59-
/* first, print out the attribute names*/
60-
nFields = data->nfields();
61-
for (i=0; i < nFields; i++) {
62-
printf("%-15s",data->fieldname(i));
63-
}
64-
printf("\n\n");
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;
6552

66-
/* next, print out the instances*/
67-
for (i=0; i < data->ntuples(); i++) {
68-
for (j=0 ; j < nFields; j++) {
69-
printf("%-15s", data->getvalue(i,j));
70-
}
71-
printf("\n");
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;
7258
}
7359

74-
/* close the portal*/
75-
data->exec("CLOSE myportal");
76-
77-
/* end the transaction*/
78-
data->exec("END");
60+
// Close the portal
61+
data.Exec("CLOSE myportal");
7962

80-
/* close theconnection to the database and cleanup*/
81-
deletedata;
63+
// End thetransaction
64+
data.Exec("END");
8265
}
8366

8467

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp