agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Jürgen Purtz <juergen@purtz.de>
To: pgsql-sql@lists.postgresql.org
Subject: Re: SQL conformity regarding SQLSTATE
Date: Fri, 22 Dec 2017 18:15:43 +0100
Message-ID: <d69ce4f1-dd4e-61c1-070e-25f662e9c622@purtz.de> (raw)
In-Reply-To: <2414.1513875032@sss.pgh.pa.us>
References: <c2c1a96d-dae9-6667-bf11-eb423ee90385@purtz.de>
	<31999.1513697414@sss.pgh.pa.us>
	<c5fb7c99-0f02-75cf-9b97-95693fc6adc7@purtz.de>
	<11558.1513819695@sss.pgh.pa.us>
	<6f4d8b10-0d24-86f5-3e14-b3d362181381@purtz.de>
	<2414.1513875032@sss.pgh.pa.us>


> 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

Attachments:

  [application/x-perl] generate-errcodes-table.pl (1.6K, ../d69ce4f1-dd4e-61c1-070e-25f662e9c622@purtz.de/2-generate-errcodes-table.pl)
  download

  [text/x-patch] generate-errcodes-table.pl.patch (1.6K, ../d69ce4f1-dd4e-61c1-070e-25f662e9c622@purtz.de/3-generate-errcodes-table.pl.patch)
  download | inline diff:
commit 817d377437f2e23da0189df7e3417a5956e3053a
Author: JuergenPurtz <juergen@purtz.de>
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;
+}

view thread (8+ messages)

Message-ID: <d69ce4f1-dd4e-61c1-070e-25f662e9c622@purtz.de>
Permalink:  ../d69ce4f1-dd4e-61c1-070e-25f662e9c622@purtz.de/
Also on:    postgresql.org/message-id/d69ce4f1-dd4e-61c1-070e-25f662e9c622@purtz.de

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: juergen@purtz.de, pgsql-sql@lists.postgresql.org
  Subject: Re: SQL conformity regarding SQLSTATE
  In-Reply-To: <d69ce4f1-dd4e-61c1-070e-25f662e9c622@purtz.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox