Re: SQL conformity regarding SQLSTATE
Jürgen Purtz <[email protected]>
| Newsgroups | gmane.comp.db.postgresql.sql |
|---|---|
| Message-ID | <[email protected]> |
> I think what might make sense is to rewrite generate-errcodes-table.pl > so that it sorts the entries for itself rather than relying on the > input file to determine the order. > OK, tested for HTML and PDF output. Kind regards Jürgen Purtz
generate-errcodes-table.pl
(application/x-perl, 1.6 KB)
#!/usr/bin/perl
#
# Generate the errcodes-table.sgml file from errcodes.txt
# Copyright (c) 2000-2017, PostgreSQL Global Development Group
use warnings;
use strict;
# A hash to store those lines, which belong to the same class/section,
# with the intention to sort them before printing
my %linesInClass;
print
"<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n";
open my $errcodes, '<', $ARGV[0] or die;
while (<$errcodes>)
{
chomp;
# Skip comments
next if /^#/;
next if /^\s*$/;
# Emit section headers
if (/^Section:/)
{
# print previous section
generateLines();
# Remove the Section: string
s/^Section: //;
# Escape dashes for SGML
s/-/—/;
# Wrap PostgreSQL in <productname/>
s/PostgreSQL/<productname>PostgreSQL<\/>/g;
print "\n\n";
print "<row>\n";
print "<entry spanname=\"span12\">";
print "<emphasis role=\"bold\">$_</></entry>\n";
print "</row>\n";
next;
}
die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
(my $sqlstate, my $type, my $errcode_macro, my $condition_name) =
($1, $2, $3, $4);
# Skip lines without PL/pgSQL condition names
next unless defined($condition_name);
# store sqlcode and text
$linesInClass{$1} = $4;
}
# last section
generateLines();
close $errcodes;
# Sort lines according to SQLCODE, generate output, and re-initialize the hash
sub generateLines {
foreach my $sqlstate ( sort keys %linesInClass ) {
print "\n";
print "<row>\n";
print "<entry><literal>$sqlstate</literal></entry>\n";
print "<entry><symbol>$linesInClass{$sqlstate}</symbol></entry>\n";
print "</row>\n";
}
undef %linesInClass;
}
generate-errcodes-table.pl.patch
(text/x-patch, 1.6 KB)
commit 817d377437f2e23da0189df7e3417a5956e3053a Author: JuergenPurtz <[email protected]> Date: Fri Dec 22 17:21:48 2017 +0100 sort SQLCODE within class/section for generated output diff --git a/doc/src/sgml/generate-errcodes-table.pl b/doc/src/sgml/generate-errcodes-table.pl index 01fc616..21779a5 100644 --- a/doc/src/sgml/generate-errcodes-table.pl +++ b/doc/src/sgml/generate-errcodes-table.pl @@ -6,6 +6,10 @@ use warnings; use strict; +# A hash to store those lines, which belong to the same class/section, +# with the intention to sort them before printing +my %linesInClass; + print "<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n"; @@ -23,6 +27,9 @@ while (<$errcodes>) if (/^Section:/) { + # print previous section + generateLines(); + # Remove the Section: string s/^Section: //; @@ -49,11 +56,24 @@ while (<$errcodes>) # Skip lines without PL/pgSQL condition names next unless defined($condition_name); - print "\n"; - print "<row>\n"; - print "<entry><literal>$sqlstate</literal></entry>\n"; - print "<entry><symbol>$condition_name</symbol></entry>\n"; - print "</row>\n"; + # store sqlcode and text + $linesInClass{$1} = $4; + } +# last section +generateLines(); + close $errcodes; + +# Sort lines according to SQLCODE, generate output, and re-initialize the hash +sub generateLines { + foreach my $sqlstate ( sort keys %linesInClass ) { + print "\n"; + print "<row>\n"; + print "<entry><literal>$sqlstate</literal></entry>\n"; + print "<entry><symbol>$linesInClass{$sqlstate}</symbol></entry>\n"; + print "</row>\n"; + } + undef %linesInClass; +}