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

Commitef2ba42

Browse files
committed
Attached is a patch that enhances the output of psql's HTML mode.The output now validates as HTML 4.01 Strict, XHTML 1.0 strict,and XHTML 1.1 (assuming you wrap it in a valid html/body document).It also wraps the output of PGRES_COMMAND_OK if the HTML tag is on,for full compliance: this is why html_escaped_print has to beexternalized.Greg Sabino Mullane greg@turnstep.com
1 parente9cda08 commitef2ba42

File tree

3 files changed

+50
-27
lines changed

3 files changed

+50
-27
lines changed

‎src/bin/psql/common.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.62 2003/03/25 02:44:36 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.63 2003/06/12 07:52:51 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -525,7 +525,18 @@ PrintQueryResults(PGresult *results,
525525
success= true;
526526
sprintf(buf,"%u", (unsignedint)PQoidValue(results));
527527
if (!QUIET())
528-
fprintf(pset.queryFout,"%s\n",PQcmdStatus(results));
528+
{
529+
if (pset.popt.topt.format==PRINT_HTML)
530+
{
531+
fputs("<p>",pset.queryFout);
532+
html_escaped_print(PQcmdStatus(results),pset.queryFout);
533+
fputs("</p>\n",pset.queryFout);
534+
}
535+
else
536+
{
537+
fprintf(pset.queryFout,"%s\n",PQcmdStatus(results));
538+
}
539+
}
529540
SetVariable(pset.vars,"LASTOID",buf);
530541
break;
531542
}

‎src/bin/psql/print.c

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.37 2003/04/04 15:48:38 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.38 2003/06/12 07:52:51 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -577,7 +577,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
577577
/**********************/
578578

579579

580-
staticvoid
580+
void
581581
html_escaped_print(constchar*in,FILE*fout)
582582
{
583583
constchar*p;
@@ -595,7 +595,13 @@ html_escaped_print(const char *in, FILE *fout)
595595
fputs("&gt;",fout);
596596
break;
597597
case'\n':
598-
fputs("<br>",fout);
598+
fputs("<br />\n",fout);
599+
break;
600+
case'"':
601+
fputs("&quot;",fout);
602+
break;
603+
case'\'':
604+
fputs("&apos;",fout);
599605
break;
600606
default:
601607
fputc(*p,fout);
@@ -615,7 +621,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
615621
unsignedinti;
616622
constchar*const*ptr;
617623

618-
fprintf(fout,"<table border=%d",opt_border);
624+
fprintf(fout,"<table border=\"%d\"",opt_border);
619625
if (opt_table_attr)
620626
fprintf(fout," %s",opt_table_attr);
621627
fputs(">\n",fout);
@@ -636,7 +642,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
636642
col_count++;
637643
if (!opt_barebones)
638644
{
639-
fputs(" <th align=center>",fout);
645+
fputs(" <th align=\"center\">",fout);
640646
html_escaped_print(*ptr,fout);
641647
fputs("</th>\n",fout);
642648
}
@@ -648,12 +654,11 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
648654
for (i=0,ptr=cells;*ptr;i++,ptr++)
649655
{
650656
if (i %col_count==0)
651-
fputs(" <tr valign=top>\n",fout);
657+
fputs(" <tr valign=\"top\">\n",fout);
652658

653-
fprintf(fout," <td align=%s>",opt_align[(i) %col_count]=='r' ?"right" :"left");
654-
if ((*ptr)[strspn(*ptr," \t")]=='\0')/* is string only
655-
* whitespace? */
656-
fputs("&nbsp;",fout);
659+
fprintf(fout," <td align=\"%s\">",opt_align[(i) %col_count]=='r' ?"right" :"left");
660+
if ((*ptr)[strspn(*ptr," \t")]=='\0')/* is string only whitespace? */
661+
fputs("&nbsp; ",fout);
657662
else
658663
html_escaped_print(*ptr,fout);
659664
fputs("</td>\n",fout);
@@ -666,13 +671,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
666671

667672
/* print footers */
668673

669-
if (footers&& !opt_barebones)
674+
if (!opt_barebones&&footers&&*footers)
675+
{
676+
fputs("<p>",fout);
670677
for (ptr=footers;*ptr;ptr++)
671678
{
672679
html_escaped_print(*ptr,fout);
673-
fputs("<br>\n",fout);
680+
fputs("<br />\n",fout);
674681
}
675-
682+
fputs("</p>",fout);
683+
}
676684
fputc('\n',fout);
677685
}
678686

@@ -690,7 +698,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
690698
unsignedintrecord=1;
691699
constchar*const*ptr;
692700

693-
fprintf(fout,"<table border=%d",opt_border);
701+
fprintf(fout,"<table border=\"%d\"",opt_border);
694702
if (opt_table_attr)
695703
fprintf(fout," %s",opt_table_attr);
696704
fputs(">\n",fout);
@@ -713,19 +721,18 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
713721
if (i %col_count==0)
714722
{
715723
if (!opt_barebones)
716-
fprintf(fout,"\n <tr><td colspan=2 align=center>Record %d</td></tr>\n",record++);
724+
fprintf(fout,"\n <tr><td colspan=\"2\" align=\"center\">Record %d</td></tr>\n",record++);
717725
else
718-
fputs("\n <tr><td colspan=2>&nbsp;</td></tr>\n",fout);
726+
fputs("\n <tr><td colspan=\"2\">&nbsp;</td></tr>\n",fout);
719727
}
720-
fputs(" <tr valign=top>\n"
728+
fputs(" <tr valign=\"top\">\n"
721729
" <th>",fout);
722730
html_escaped_print(headers[i %col_count],fout);
723731
fputs("</th>\n",fout);
724732

725-
fprintf(fout," <td align=%s>",opt_align[i %col_count]=='r' ?"right" :"left");
726-
if ((*ptr)[strspn(*ptr," \t")]=='\0')/* is string only
727-
* whitespace? */
728-
fputs("&nbsp;",fout);
733+
fprintf(fout," <td align=\"%s\">",opt_align[i %col_count]=='r' ?"right" :"left");
734+
if ((*ptr)[strspn(*ptr," \t")]=='\0')/* is string only whitespace? */
735+
fputs("&nbsp; ",fout);
729736
else
730737
html_escaped_print(*ptr,fout);
731738
fputs("</td>\n </tr>\n",fout);
@@ -734,13 +741,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
734741
fputs("</table>\n",fout);
735742

736743
/* print footers */
737-
if (footers&& !opt_barebones)
744+
if (!opt_barebones&&footers&&*footers)
745+
{
746+
fputs("<p>",fout);
738747
for (ptr=footers;*ptr;ptr++)
739748
{
740749
html_escaped_print(*ptr,fout);
741-
fputs("<br>\n",fout);
750+
fputs("<br />\n",fout);
742751
}
743-
752+
fputs("</p>",fout);
753+
}
744754
fputc('\n',fout);
745755
}
746756

@@ -1115,6 +1125,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11151125
char*align;
11161126
inti;
11171127

1128+
11181129
/* extract headers */
11191130

11201131
nfields=PQnfields(result);

‎src/bin/psql/print.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.16 2003/03/18 22:15:44 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.17 2003/06/12 07:52:51 momjian Exp $
77
*/
88
#ifndefPRINT_H
99
#definePRINT_H
@@ -13,6 +13,7 @@
1313

1414
externFILE*PageOutput(intlines,unsigned shortintpager);
1515

16+
externvoidhtml_escaped_print(constchar*in,FILE*fout);
1617

1718
enumprintFormat
1819
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp