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

Commitd7186cf

Browse files
committed
Add some modicum of error detection...
1 parent570ed46 commitd7186cf

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

‎src/test/examples/testlo.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/test/examples/testlo.c,v 1.15 2000/04/25 16:39:07 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/test/examples/testlo.c,v 1.16 2000/10/24 00:08:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -96,6 +96,8 @@ pickout(PGconn *conn, Oid lobjId, int start, int len)
9696
buf[nbytes]='\0';
9797
fprintf(stderr,">>> %s",buf);
9898
nread+=nbytes;
99+
if (nbytes <=0)
100+
break;/* no more data? */
99101
}
100102
fprintf(stderr,"\n");
101103
lo_close(conn,lobj_fd);
@@ -126,6 +128,11 @@ overwrite(PGconn *conn, Oid lobjId, int start, int len)
126128
{
127129
nbytes=lo_write(conn,lobj_fd,buf+nwritten,len-nwritten);
128130
nwritten+=nbytes;
131+
if (nbytes <=0)
132+
{
133+
fprintf(stderr,"\nWRITE FAILED!\n");
134+
break;
135+
}
129136
}
130137
fprintf(stderr,"\n");
131138
lo_close(conn,lobj_fd);
@@ -229,21 +236,24 @@ main(int argc, char **argv)
229236
/*lobjOid = importFile(conn, in_filename); */
230237
lobjOid=lo_import(conn,in_filename);
231238
if (lobjOid==0)
239+
{
232240
fprintf(stderr,"%s\n",PQerrorMessage(conn));
241+
}
242+
else
243+
{
244+
printf("\tas large object %u.\n",lobjOid);
233245

234-
printf("\tas large object %u.\n",lobjOid);
235-
236-
printf("picking out bytes 1000-2000 of the large object\n");
237-
pickout(conn,lobjOid,1000,1000);
238-
239-
printf("overwriting bytes 1000-2000 of the large object with X's\n");
240-
overwrite(conn,lobjOid,1000,1000);
246+
printf("picking out bytes 1000-2000 of the large object\n");
247+
pickout(conn,lobjOid,1000,1000);
241248

249+
printf("overwriting bytes 1000-2000 of the large object with X's\n");
250+
overwrite(conn,lobjOid,1000,1000);
242251

243-
printf("exporting large object to file \"%s\" ...\n",out_filename);
244-
/* exportFile(conn, lobjOid, out_filename); */
245-
if (!lo_export(conn,lobjOid,out_filename))
246-
fprintf(stderr,"%s\n",PQerrorMessage(conn));
252+
printf("exporting large object to file \"%s\" ...\n",out_filename);
253+
/*exportFile(conn, lobjOid, out_filename); */
254+
if (!lo_export(conn,lobjOid,out_filename))
255+
fprintf(stderr,"%s\n",PQerrorMessage(conn));
256+
}
247257

248258
res=PQexec(conn,"end");
249259
PQclear(res);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp