7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -829,21 +829,22 @@ PQprint(FILE *fout,
829
829
nFields = PQnfields (res );
830
830
831
831
if (nFields > 0 ) {/* only print tuples with at least 1 field. */
832
- int i ,j ;
833
- int nTups ;
834
- int * fieldMax = NULL ;/* keep -Wall happy */
835
- unsignedchar * fieldNotNum = NULL ;/* keep -Wall happy */
836
- char * * fields = NULL ;/*keep -Wall happy */
832
+ int i ,j ;
833
+ int nTups ;
834
+ int * fieldMax = NULL ;/* in case we don't use them */
835
+ unsignedchar * fieldNotNum = NULL ;
836
+ char * border = NULL ;
837
+ char * * fields = NULL ;
837
838
char * * fieldNames ;
838
839
int fieldMaxLen = 0 ;
839
- char * border = NULL ;
840
- int numFieldName ;
840
+ int numFieldName ;
841
841
int fs_len = strlen (po -> fieldSep );
842
- int total_line_length = 0 ;
843
- int usePipe = 0 ;
844
- char * pagerenv ;
842
+ int total_line_length = 0 ;
843
+ int usePipe = 0 ;
844
+ char * pagerenv ;
845
+ char buf [8192 * 2 + 1 ];
845
846
846
- nTups = PQntuples (res );
847
+ nTups = PQntuples (res );
847
848
if (!(fieldNames = (char * * )calloc (nFields ,sizeof (char * ))))
848
849
{
849
850
perror ("calloc" );
@@ -882,7 +883,10 @@ PQprint(FILE *fout,
882
883
883
884
if (fout == NULL )
884
885
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
+ {
886
890
/* try to pipe to the pager program if possible */
887
891
#ifdef TIOCGWINSZ
888
892
if (ioctl (fileno (stdout ),TIOCGWINSZ ,& screen_size )== -1 ||
@@ -907,8 +911,7 @@ PQprint(FILE *fout,
907
911
screen_size .ws_row -
908
912
(po -> header != 0 )*
909
913
(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 */
912
915
)))
913
916
{
914
917
fout = popen (pagerenv ,"w" );
@@ -927,7 +930,8 @@ PQprint(FILE *fout,
927
930
perror ("calloc" );
928
931
exit (1 );
929
932
}
930
- }else
933
+ }
934
+ else
931
935
if (po -> header && !po -> html3 )
932
936
{
933
937
if (po -> expanded )
@@ -936,7 +940,8 @@ PQprint(FILE *fout,
936
940
fprintf (fout ,"%-*s%s Value\n" ,fieldMaxLen - fs_len ,"Field" ,po -> fieldSep );
937
941
else
938
942
fprintf (fout ,"%s%sValue\n" ,"Field" ,po -> fieldSep );
939
- }else
943
+ }
944
+ else
940
945
{
941
946
int len = 0 ;
942
947
for (j = 0 ;j < nFields ;j ++ )
@@ -959,16 +964,17 @@ PQprint(FILE *fout,
959
964
else
960
965
fprintf (fout ,"<centre><h2>Query retrieved %d tuples * %d fields</h2></centre>\n" ,nTups ,nFields );
961
966
}
962
- for (i = 0 ;i < nTups ;i ++ ) {
963
- char buf [ 8192 * 2 + 1 ];
967
+ for (i = 0 ;i < nTups ;i ++ )
968
+ {
964
969
if (po -> expanded )
965
970
{
966
971
if (po -> html3 )
967
972
fprintf (fout ,"<table %s><caption align=high>%d</caption>\n" ,po -> tableOpt ?po -> tableOpt :"" ,i );
968
973
else
969
974
fprintf (fout ,"-- RECORD %d --\n" ,i );
970
975
}
971
- for (j = 0 ;j < nFields ;j ++ ) {
976
+ for (j = 0 ;j < nFields ;j ++ )
977
+ {
972
978
char * pval ,* p ,* o ;
973
979
int plen ;
974
980
if ((plen = PQgetlength (res ,i ,j ))< 1 || !(pval = PQgetvalue (res ,i ,j ))|| !* pval )
@@ -996,7 +1002,8 @@ PQprint(FILE *fout,
996
1002
exit (1 );
997
1003
}
998
1004
strcpy (fields [i * nFields + j ],buf );
999
- }else
1005
+ }
1006
+ else
1000
1007
{
1001
1008
if (po -> expanded )
1002
1009
{
@@ -1089,7 +1096,8 @@ PQprint(FILE *fout,
1089
1096
{
1090
1097
fprintf (fout ,"<th align=%s>%s</th>" ,fieldNotNum [j ]?"left" :"right" ,
1091
1098
fieldNames [j ]);
1092
- }else
1099
+ }
1100
+ else
1093
1101
{
1094
1102
int n = strlen (s );
1095
1103
if (n > fieldMax [j ])
@@ -1139,10 +1147,14 @@ PQprint(FILE *fout,
1139
1147
}
1140
1148
free (fields );
1141
1149
}
1150
+ if (po -> header && !po -> html3 )
1151
+ fprintf (fout ,"(%d row%s)\n\n" ,PQntuples (res ),
1152
+ (PQntuples (res )== 1 ) ?"" :"s" );
1142
1153
free (fieldMax );
1143
1154
free (fieldNotNum );
1144
1155
free (fieldNames );
1145
- if (usePipe ) {
1156
+ if (usePipe )
1157
+ {
1146
1158
pclose (fout );
1147
1159
signal (SIGPIPE ,SIG_DFL );
1148
1160
}