translating exception messages of postgresql functions

Поиск
Список
Период
Сортировка
Искать

translating exception messages of postgresql functions

От:
Julius Tuskenis <julius@nsoft.lt>
Дата:
Hello,

I'd like to ask how is translation of raised exceptions done in 
postgresql applications?   In Sybase ASA you can specify the error 
number when raising it, but in postgresql theres just exception message. 
As I've read - postgresql always generates P0001 SQLSTATE code for 
raised exceptions. Have enyone tried to distinguish one exception from 
the other in the application?

-- 
Julius Tuskenis
Programavimo skyriaus vadovas
UAB nSoft
mob. +37068233050

Re: translating exception messages of postgresql functions

От:
Alvaro Herrera <alvherre@commandprompt.com>
Дата:
Julius Tuskenis wrote:
> Hello,
>
> I'd like to ask how is translation of raised exceptions done in  
> postgresql applications?

You want it translated or not translated?

> In Sybase ASA you can specify the error  
> number when raising it, but in postgresql theres just exception message.  
> As I've read - postgresql always generates P0001 SQLSTATE code for  
> raised exceptions. Have enyone tried to distinguish one exception from  
> the other in the application?

In Postgres 8.4 you will be able to specify error codes to raised
exceptions in PL/pgSQL.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: translating exception messages of postgresql functions

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Julius Tuskenis  writes:
> As I've read - postgresql always generates P0001 SQLSTATE code for 
> raised exceptions. Have enyone tried to distinguish one exception from 
> the other in the application?

You'd have to rely on looking at the error message text.

8.4 will let you specify SQLSTATE in RAISE:
http://developer.postgresql.org/pgdocs/postgres/plpgsql-errors-and-messages.html

			regards, tom lane

Re: translating exception messages of postgresql functions

От:
Julius Tuskenis <julius@nsoft.lt>
Дата:
Alvaro Herrera rašė:
> Julius Tuskenis wrote:
>   
>> Hello,
>>
>> I'd like to ask how is translation of raised exceptions done in  
>> postgresql applications?
>>     
>
> You want it translated or not translated?
>   
I want to translate the exception message. For example I raise an 
exception in pg function like RAISE EXCEPTION 'my exception', then in my 
application that calls the function I catch the exception. But before I 
show it to the user of application I have to translate it. How do I know 
what exception it is? As Tom Lane answered - the only way is to rely on 
message text.

-- 
Julius Tuskenis
Programavimo skyriaus vadovas
UAB nSoft
mob. +37068233050

Re: translating exception messages of postgresql functions

От:
Alvaro Herrera <alvherre@commandprompt.com>
Дата:
Julius Tuskenis wrote:

> I want to translate the exception message. For example I raise an  
> exception in pg function like RAISE EXCEPTION 'my exception', then in my  
> application that calls the function I catch the exception. But before I  
> show it to the user of application I have to translate it. How do I know  
> what exception it is? As Tom Lane answered - the only way is to rely on  
> message text.

You want to translate it from english to another language, or you want
to change the nature of the message reported?  If you just want to
translate it to another language, see here:

http://pgtranslation.projects.postgresql.org/status.html

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Re: translating exception messages of postgresql functions

От:
Julius Tuskenis <julius@nsoft.lt>
Дата:
Alvaro Herrera rašė:
> Julius Tuskenis wrote:
>
>   
>> I want to translate the exception message. For example I raise an  
>> exception in pg function like RAISE EXCEPTION 'my exception', then in my  
>> application that calls the function I catch the exception. But before I  
>> show it to the user of application I have to translate it. How do I know  
>> what exception it is? As Tom Lane answered - the only way is to rely on  
>> message text.
>>     
>
> You want to translate it from english to another language, or you want
> to change the nature of the message reported?  If you just want to
> translate it to another language, see here:
>
> http://pgtranslation.projects.postgresql.org/status.html
>
>   
Thank you, Alvaro, but it seems you have slightly misunderstood me. I 
want to translate the exceptions I rise myself. That is I do RAISE 
EXCEPT 'user "%" not found', prm_user; in pl/pgsql function, but I want 
the user to see it translated to the language he uses. Using whole error 
message is inconvenient because the application gets 'user "Peter" not 
found' or 'user "John" not found' - not 'user "%" not found'. Thats 
where the problem is.

-- 
Julius Tuskenis
Programavimo skyriaus vadovas
UAB nSoft
mob. +37068233050

Re: translating exception messages of postgresql functions

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Julius Tuskenis  writes:
> Alvaro Herrera rašė:
>> You want to translate it from english to another language, or you want
>> to change the nature of the message reported?  If you just want to
>> translate it to another language, see here:
>> 
>> http://pgtranslation.projects.postgresql.org/status.html
>> 
> Thank you, Alvaro, but it seems you have slightly misunderstood me. I 
> want to translate the exceptions I rise myself. That is I do RAISE 
> EXCEPT 'user "%" not found', prm_user; in pl/pgsql function, but I want 
> the user to see it translated to the language he uses.

I wonder if it would help to make plpgsql pass the RAISE format string
through gettext?

This would only be a usable approach if there were some fairly easy way
to add installation-specific translations to gettext's table.  I don't
know enough about gettext to know if that's doable.

			regards, tom lane

Re: translating exception messages of postgresql functions

От:
Alvaro Herrera <alvherre@commandprompt.com>
Дата:
Tom Lane wrote:

> I wonder if it would help to make plpgsql pass the RAISE format string
> through gettext?

Hmm, nice idea.  However,

> This would only be a usable approach if there were some fairly easy way
> to add installation-specific translations to gettext's table.  I don't
> know enough about gettext to know if that's doable.

There are lots of caveats -- the first being that you would need to
extract the messages from the function body.  I don't think there's a
gettext PL/pgSQL parser, so there's a first hurdle there.

Then there's the matter of not mixing the "postgres" message domain with
the user's, so we would need to change it just before calling RAISE and
restore it afterwards.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
FAQ