Error codes as numbers or in other languages etc.

Поиск
Список
Период
Сортировка
От Aasmund Midttun Godal
Тема Error codes as numbers or in other languages etc.
Дата
Msg-id 20011023170808.2262.qmail@ns.krot.org
обсуждение исходный текст
Список pgsql-sql
I have seen several people asking about getting error numbers or similar things out of postgres. The way I have done
thisis as follows:
 

CREATE TABLE errors (errorstring TEXT PRIMARY KEY,message TEXT
);

INSERT INTO errors VALUES ('^FATAL 1:  Database "([^\"]+)" does not exist in the system catalog.$', 'FATALE 1: Le
database"$1" n''existe pas dans le catalogue systeme');
 

Now in the app if we use perl and DBI we set RaiseError => 1 and catch the error via $dbh->errstr or something

pass it into a query like:

prepare('SELECT * FROM errors WHERE ? ~ errorstring'); 
#Isn't postgres great? reverse regular expression searches :)
my $s = execute($dbh->errstr);

then we exploit perl's ability:

$dbh->errstr =~ /$s->{'errorstring'}/"$s->{'message'}"/e;

Hopes someone else find it usefull,

Getting out numbers is offcourse even easier.

Aasmund Midttun Godal

aasmund@godal.com - http://www.godal.com/
+47 40 45 20 46


В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Index of a table is not used (in any case)
Следующее
От: "Andre Schnabel"
Дата:
Сообщение: Re: Diferent databases on same query...