Re: Error Codes - Mailing list pgsql-hackers

From David Fetter
Subject Re: Error Codes
Date
Msg-id 20040706191912.GA30090@fetter.org
Whole thread Raw
In response to Re: Error Codes  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
On Tue, Jul 06, 2004 at 01:22:35PM -0400, Bruce Momjian wrote:
> David Fetter wrote:
> > Kind people,
> > 
> > So far, I have found two places where one can find the SQLSTATE
> > error codes: a header file, and the errcodes-appendix doc.  Those
> > are excellent places.
> > 
> > Did I miss how to get a list of them in SQL?  If I missed it
> > because it isn't there, what would be a good way to have a current
> > list available?
> 
> You know, it would be cool to have the codes and descriptions in a
> global SQL table.

I think so, too :)

So, I'm looking at src/include/utils/errcodes.h in CVS tip, and I see
what looks to me like two columns in a table:

sqlstate (e.g. 0100C)
warning (e.g. ERRCODE_WARNING_DYNAMIC_RESULT_SETS_RETURNED)

this would make an excellent table to have handy.  How to make sure
that it is, in fact, available, and that its contents match
errcodes.h?  Here is a perl hack for parsing errcodes.h:

#!/usr/bin/perl -wl

use strict;

open F, "<errcodes.h" or die "Can't open errcodes.h: $!";
while(<F>) {   chomp;   next unless (/^#define\s+ERRCODE_(\S+)\s+MAKE_SQLSTATE\('(.*)'\).*$/);   # print;   my
($warning,$sqlstate) = ($1, $2);    $warning =~ s/^ERRCODE_//;    $sqlstate =~ s/\W//g; # clean up   my $sql = "INSERT
INTOsqlstates (sqlstate, warning) VALUES ($sqlstate, $warning);";   print $sql;   # Now, do the inserts...but where?
 
}


Cheers,
D
-- 
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!


pgsql-hackers by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Point in Time Recovery
Next
From: Simon Riggs
Date:
Subject: Re: Point in Time Recovery