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

Commit2f42753

Browse files
committed
Massive examples fix from Nicola Bernardelli
1 parent0384d37 commit2f42753

File tree

8 files changed

+78
-59
lines changed

8 files changed

+78
-59
lines changed

‎src/include/utils/geo_decls.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: geo_decls.h,v 1.13 1997/09/20 16:25:28 thomas Exp $
8+
* $Id: geo_decls.h,v 1.14 1997/09/25 16:35:36 momjian Exp $
99
*
1010
* NOTE
1111
* These routines do *not* use the float types from adt/.
@@ -20,6 +20,7 @@
2020
#defineGEO_DECLS_H
2121

2222
#include"access/attnum.h"
23+
#include"postgres.h"/* float8 */
2324

2425
/*#ifndef FmgrIncluded -- seems like always included. (it's FMgrIncluded) AY */
2526

‎src/test/examples/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ LDFLAGS+= $(KRBLIBS)
1717
CFLAGS+=$(KRBFLAGS)
1818
endif
1919

20-
PROGS= testlibpq0 testlibpq1 testlibpq2 testlibpq3 testlibpq4 testlo
20+
# PROGS= testlibpq0 testlibpq1 testlibpq2 testlibpq3 testlibpq4 testlo
21+
PROGS = testlibpq testlibpq2 testlibpq3 testlibpq4 testlo testlo2
2122

2223
all:$(PROGS)
2324

‎src/test/examples/testlibpq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
#include<stdio.h>
88
#include"libpq-fe.h"
99

10-
void
10+
staticvoid
1111
exit_nicely(PGconn*conn)
1212
{
1313
PQfinish(conn);
1414
exit(1);
1515
}
1616

17+
int
1718
main()
1819
{
1920
char*pghost,

‎src/test/examples/testlibpq2.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,28 @@ INSERT INTO TBL1 values (10);
1919
*
2020
*/
2121
#include<stdio.h>
22+
#include<stdlib.h>
2223
#include"libpq-fe.h"
2324

24-
void
25+
staticvoid
2526
exit_nicely(PGconn*conn)
2627
{
2728
PQfinish(conn);
2829
exit(1);
2930
}
3031

32+
int
3133
main()
3234
{
3335
char*pghost,
3436
*pgport,
3537
*pgoptions,
3638
*pgtty;
3739
char*dbName;
38-
intnFields;
39-
inti,
40-
j;
40+
/* intnFields;
41+
* inti,
42+
*j;
43+
*/
4144

4245
PGconn*conn;
4346
PGresult*res;
@@ -103,5 +106,5 @@ main()
103106

104107
/* close the connection to the database and cleanup */
105108
PQfinish(conn);
106-
109+
return0;/* Though PQfinish(conn1) has called exit(1) */
107110
}

‎src/test/examples/testlibpq3.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,31 @@ tuple 1: got
2727
*
2828
*/
2929
#include<stdio.h>
30+
#include<string.h>
31+
#include"postgres.h"/* -> "c.h" -> int16, in access/attnum.h */
3032
#include"libpq-fe.h"
31-
#include"utils/geo-decls.h"/* for the POLYGON type */
33+
#include"utils/geo_decls.h"/* for the POLYGON type */
3234

33-
void
35+
staticvoid
3436
exit_nicely(PGconn*conn)
3537
{
3638
PQfinish(conn);
3739
exit(1);
3840
}
3941

42+
int
4043
main()
4144
{
4245
char*pghost,
4346
*pgport,
4447
*pgoptions,
4548
*pgtty;
4649
char*dbName;
47-
intnFields;
48-
inti,
49-
j;
50+
/* intnFields;
51+
* inti,
52+
*j;
53+
*/
54+
inti;
5055
inti_fnum,
5156
d_fnum,
5257
p_fnum;
@@ -157,10 +162,10 @@ main()
157162
printf(" p = (%d bytes) %d points \tboundbox = (hi=%f/%f, lo = %f,%f)\n",
158163
PQgetlength(res,i,d_fnum),
159164
pval->npts,
160-
pval->boundbox.xh,
161-
pval->boundbox.yh,
162-
pval->boundbox.xl,
163-
pval->boundbox.yl);
165+
pval->boundbox.high.x,
166+
pval->boundbox.high.y,
167+
pval->boundbox.low.x,
168+
pval->boundbox.low.y);
164169
}
165170

166171
PQclear(res);
@@ -175,5 +180,5 @@ main()
175180

176181
/* close the connection to the database and cleanup */
177182
PQfinish(conn);
178-
183+
return0;/* Though PQfinish(conn1) has called exit(1) */
179184
}

‎src/test/examples/testlibpq4.c

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include<stdio.h>
99
#include"libpq-fe.h"
1010

11-
void
11+
staticvoid
1212
exit_nicely(PGconn*conn1,PGconn*conn2)
1313
{
1414
if (conn1)
@@ -18,8 +18,8 @@ exit_nicely(PGconn *conn1, PGconn *conn2)
1818
exit(1);
1919
}
2020

21-
void
22-
check_conn(PGconn*conn)
21+
staticvoid
22+
check_conn(PGconn*conn,constchar*dbName)
2323
{
2424
/* check to see that the backend connection was successfully made */
2525
if (PQstatus(conn)==CONNECTION_BAD)
@@ -30,23 +30,26 @@ check_conn(PGconn *conn)
3030
}
3131
}
3232

33-
main()
33+
int
34+
main(intargc,char**argv)
3435
{
3536
char*pghost,
3637
*pgport,
3738
*pgoptions,
3839
*pgtty;
3940
char*dbName1,
40-
dbName2;
41+
*dbName2;
4142
char*tblName;
4243
intnFields;
4344
inti,
4445
j;
4546

4647
PGconn*conn1,
47-
conn2;
48-
PGresult*res1,
49-
res2;
48+
*conn2;
49+
/* PGresult *res1,
50+
**res2;
51+
*/
52+
PGresult*res1;
5053

5154
if (argc!=4)
5255
{
@@ -73,10 +76,10 @@ main()
7376

7477
/* make a connection to the database */
7578
conn1=PQsetdb(pghost,pgport,pgoptions,pgtty,dbName1);
76-
check_conn(conn1);
79+
check_conn(conn1,dbName1);
7780

7881
conn2=PQsetdb(pghost,pgport,pgoptions,pgtty,dbName2);
79-
check_conn(conn2);
82+
check_conn(conn2,dbName2);
8083

8184
/* start a transaction block */
8285
res1=PQexec(conn1,"BEGIN");
@@ -97,53 +100,54 @@ main()
97100
* fetch instances from the pg_database, the system catalog of
98101
* databases
99102
*/
100-
res=PQexec(conn,"DECLARE myportal CURSOR FOR select * from pg_database");
101-
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
103+
res1=PQexec(conn1,"DECLARE myportal CURSOR FOR select * from pg_database");
104+
if (PQresultStatus(res1)!=PGRES_COMMAND_OK)
102105
{
103106
fprintf(stderr,"DECLARE CURSOR command failed\n");
104-
PQclear(res);
105-
exit_nicely(conn);
107+
PQclear(res1);
108+
exit_nicely(conn1,(PGconn*)NULL);
106109
}
107-
PQclear(res);
110+
PQclear(res1);
108111

109-
res=PQexec(conn,"FETCH ALL in myportal");
110-
if (PQresultStatus(res)!=PGRES_TUPLES_OK)
112+
res1=PQexec(conn1,"FETCH ALL in myportal");
113+
if (PQresultStatus(res1)!=PGRES_TUPLES_OK)
111114
{
112115
fprintf(stderr,"FETCH ALL command didn't return tuples properly\n");
113-
PQclear(res);
114-
exit_nicely(conn);
116+
PQclear(res1);
117+
exit_nicely(conn1,(PGconn*)NULL);
115118
}
116119

117120
/* first, print out the attribute names */
118-
nFields=PQnfields(res);
121+
nFields=PQnfields(res1);
119122
for (i=0;i<nFields;i++)
120123
{
121-
printf("%-15s",PQfname(res,i));
124+
printf("%-15s",PQfname(res1,i));
122125
}
123126
printf("\n\n");
124127

125128
/* next, print out the instances */
126-
for (i=0;i<PQntuples(res);i++)
129+
for (i=0;i<PQntuples(res1);i++)
127130
{
128131
for (j=0;j<nFields;j++)
129132
{
130-
printf("%-15s",PQgetvalue(res,i,j));
133+
printf("%-15s",PQgetvalue(res1,i,j));
131134
}
132135
printf("\n");
133136
}
134137

135-
PQclear(res);
138+
PQclear(res1);
136139

137140
/* close the portal */
138-
res=PQexec(conn,"CLOSE myportal");
139-
PQclear(res);
141+
res1=PQexec(conn1,"CLOSE myportal");
142+
PQclear(res1);
140143

141144
/* end the transaction */
142-
res=PQexec(conn,"END");
143-
PQclear(res);
145+
res1=PQexec(conn1,"END");
146+
PQclear(res1);
144147

145148
/* close the connection to the database and cleanup */
146-
PQfinish(conn);
149+
PQfinish(conn1);
147150

148151
/* fclose(debug); */
152+
return0;/* Though PQfinish(conn1) has called exit(1) */
149153
}

‎src/test/examples/testlo.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/test/examples/testlo.c,v 1.6 1997/09/08 21:55:56 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/test/examples/testlo.c,v 1.7 1997/09/25 16:35:50 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,6 +17,7 @@
1717
#include<sys/types.h>
1818
#include<sys/stat.h>
1919
#include<fcntl.h>
20+
#include<unistd.h>
2021

2122
#include"libpq-fe.h"
2223
#include"libpq/libpq-fs.h"
@@ -28,7 +29,7 @@
2829
* import file "in_filename" into database as large object "lobjOid"
2930
*
3031
*/
31-
Oid
32+
staticOid
3233
importFile(PGconn*conn,char*filename)
3334
{
3435
OidlobjId;
@@ -76,7 +77,7 @@ importFile(PGconn *conn, char *filename)
7677
returnlobjId;
7778
}
7879

79-
void
80+
staticvoid
8081
pickout(PGconn*conn,OidlobjId,intstart,intlen)
8182
{
8283
intlobj_fd;
@@ -106,7 +107,7 @@ pickout(PGconn *conn, Oid lobjId, int start, int len)
106107
lo_close(conn,lobj_fd);
107108
}
108109

109-
void
110+
staticvoid
110111
overwrite(PGconn*conn,OidlobjId,intstart,intlen)
111112
{
112113
intlobj_fd;
@@ -145,7 +146,7 @@ overwrite(PGconn *conn, Oid lobjId, int start, int len)
145146
* export large object "lobjOid" to file "out_filename"
146147
*
147148
*/
148-
void
149+
staticvoid
149150
exportFile(PGconn*conn,OidlobjId,char*filename)
150151
{
151152
intlobj_fd;
@@ -193,7 +194,7 @@ exportFile(PGconn *conn, Oid lobjId, char *filename)
193194
return;
194195
}
195196

196-
void
197+
staticvoid
197198
exit_nicely(PGconn*conn)
198199
{
199200
PQfinish(conn);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp