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

Commit4e82924

Browse files
committed
Row count patch from Bruce
1 parent7d2000e commit4e82924

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

‎src/interfaces/libpq/fe-exec.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.11 1996/07/3106:05:46 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.12 1996/07/3118:40:09 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -829,21 +829,22 @@ PQprint(FILE *fout,
829829
nFields=PQnfields(res);
830830

831831
if (nFields>0 ) {/* only print tuples with at least 1 field. */
832-
inti,j;
833-
intnTups;
834-
int*fieldMax=NULL;/* keep -Wall happy */
835-
unsignedchar*fieldNotNum=NULL;/* keep -Wall happy */
836-
char**fields=NULL;/*keep -Wall happy */
832+
inti,j;
833+
intnTups;
834+
int*fieldMax=NULL;/* in case we don't use them */
835+
unsignedchar*fieldNotNum=NULL;
836+
char*border=NULL;
837+
char**fields=NULL;
837838
char**fieldNames;
838839
intfieldMaxLen=0;
839-
char*border=NULL;
840-
intnumFieldName;
840+
intnumFieldName;
841841
intfs_len=strlen(po->fieldSep);
842-
inttotal_line_length=0;
843-
intusePipe=0;
844-
char*pagerenv;
842+
inttotal_line_length=0;
843+
intusePipe=0;
844+
char*pagerenv;
845+
charbuf[8192*2+1];
845846

846-
nTups=PQntuples(res);
847+
nTups=PQntuples(res);
847848
if (!(fieldNames=(char**)calloc(nFields,sizeof (char*))))
848849
{
849850
perror("calloc");
@@ -882,7 +883,10 @@ PQprint(FILE *fout,
882883

883884
if (fout==NULL)
884885
fout=stdout;
885-
if (po->pager&&fout==stdout&&isatty(fileno(stdout))) {
886+
if (po->pager&&fout==stdout&&
887+
isatty(fileno(stdin))&&
888+
isatty(fileno(stdout)))
889+
{
886890
/* try to pipe to the pager program if possible */
887891
#ifdefTIOCGWINSZ
888892
if (ioctl(fileno(stdout),TIOCGWINSZ,&screen_size)==-1||
@@ -907,8 +911,7 @@ PQprint(FILE *fout,
907911
screen_size.ws_row-
908912
(po->header!=0)*
909913
(total_line_length /screen_size.ws_col+1)*2
910-
/*- 1 *//* newline at end of tuple list */
911-
/*- (quiet == 0)*/
914+
- (po->header!=0)*2/* row count and newline */
912915
)))
913916
{
914917
fout=popen(pagerenv,"w");
@@ -927,7 +930,8 @@ PQprint(FILE *fout,
927930
perror("calloc");
928931
exit(1);
929932
}
930-
}else
933+
}
934+
else
931935
if (po->header&& !po->html3)
932936
{
933937
if (po->expanded)
@@ -936,7 +940,8 @@ PQprint(FILE *fout,
936940
fprintf(fout,"%-*s%s Value\n",fieldMaxLen-fs_len,"Field",po->fieldSep);
937941
else
938942
fprintf(fout,"%s%sValue\n","Field",po->fieldSep);
939-
}else
943+
}
944+
else
940945
{
941946
intlen=0;
942947
for (j=0;j<nFields;j++)
@@ -959,16 +964,17 @@ PQprint(FILE *fout,
959964
else
960965
fprintf(fout,"<centre><h2>Query retrieved %d tuples * %d fields</h2></centre>\n",nTups,nFields);
961966
}
962-
for (i=0;i<nTups;i++) {
963-
charbuf[8192*2+1];
967+
for (i=0;i<nTups;i++)
968+
{
964969
if (po->expanded)
965970
{
966971
if (po->html3)
967972
fprintf(fout,"<table %s><caption align=high>%d</caption>\n",po->tableOpt?po->tableOpt:"",i);
968973
else
969974
fprintf(fout,"-- RECORD %d --\n",i);
970975
}
971-
for (j=0;j<nFields;j++) {
976+
for (j=0;j<nFields;j++)
977+
{
972978
char*pval,*p,*o;
973979
intplen;
974980
if ((plen=PQgetlength(res,i,j))<1|| !(pval=PQgetvalue(res,i,j))|| !*pval)
@@ -996,7 +1002,8 @@ PQprint(FILE *fout,
9961002
exit(1);
9971003
}
9981004
strcpy(fields[i*nFields+j],buf);
999-
}else
1005+
}
1006+
else
10001007
{
10011008
if (po->expanded)
10021009
{
@@ -1089,7 +1096,8 @@ PQprint(FILE *fout,
10891096
{
10901097
fprintf(fout,"<th align=%s>%s</th>",fieldNotNum[j]?"left":"right",
10911098
fieldNames[j]);
1092-
}else
1099+
}
1100+
else
10931101
{
10941102
intn=strlen(s);
10951103
if (n>fieldMax[j])
@@ -1139,10 +1147,14 @@ PQprint(FILE *fout,
11391147
}
11401148
free(fields);
11411149
}
1150+
if (po->header&& !po->html3)
1151+
fprintf (fout,"(%d row%s)\n\n",PQntuples(res),
1152+
(PQntuples(res)==1) ?"" :"s");
11421153
free(fieldMax);
11431154
free(fieldNotNum);
11441155
free(fieldNames);
1145-
if (usePipe) {
1156+
if (usePipe)
1157+
{
11461158
pclose(fout);
11471159
signal(SIGPIPE,SIG_DFL);
11481160
}

‎src/interfaces/libpq/libpq-fe.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: libpq-fe.h,v 1.4 1996/07/27 02:55:23 scrappy Exp $
9+
* $Id: libpq-fe.h,v 1.5 1996/07/31 18:40:12 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -128,12 +128,12 @@ typedef struct pg_result{
128128
}PGresult;
129129

130130
struct_PQprintOpt {
131-
boolheader;/* print output fieldheaders or not */
131+
boolheader;/* print output fieldheadings and row count */
132132
boolalign;/* fill align the fields */
133133
boolstandard;/* old brain dead format */
134134
boolhtml3;/* output html tables */
135135
boolexpanded;/* expand tables */
136-
boolpager;/* use pager for output if needed */
136+
boolpager;/* use pager for output if needed */
137137
char*fieldSep;/* field separator */
138138
char*tableOpt;/* insert to HTML <table ...> */
139139
char*caption;/* HTML <caption> */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp