Re: psql \dFp's behavior

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql \dFp's behavior
Date: 2007-12-11 20:50:53
Message-ID: 475EF82D.6070904@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane a écrit :
> Guillaume Lelarge <guillaume(at)lelarge(dot)info> writes:
>> I'm not sure psql handles \dFp the right way. The query allows
>> translators to translate some columns' values but forgets to escape the
>> strings. So, here is a patch that escapes these translated strings.
>
> This seems mighty ugly, and it's not the way we handle any other \d
> command. Why is it needed for \dFp (and only that)?
>

Oh I didn't say only \dFp needs this kind of fix. I've found an issue
with \dFp+ today, so I'm trying to fix it. Here is the issue I found :

guillaume(at)laptop:/opt/postgresql-head$ LANG=en psql postgres
Welcome to psql 8.3beta4, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

Text search parser "pg_catalog.default"
Method | Function | Description
-----------------+----------------+-------------
Start parse | prsd_start |
Get next token | prsd_nexttoken |
End parse | prsd_end |
Get headline | prsd_headline |
Get token types | prsd_lextype |

Token types for parser "pg_catalog.default"
[...]

OK, it works great. Now, in french :

guillaume(at)laptop:/opt/postgresql-head$ LANG=fr_FR.UTF-8 psql postgres
Bienvenue dans psql 8.3beta4, l'interface interactive de PostgreSQL.

Saisissez:
\copyright pour les termes de distribution
\h pour l'aide-mémoire des commandes SQL
\? pour l'aide-mémoire des commandes psql
\g ou point-virgule en fin d'instruction pour exécuter la requête
\q pour quitter

postgres=# set lc_messages to 'C';
SET
postgres=# \dFp+
ERROR: syntax error at or near "analyse"
LIGNE 1 : SELECT 'Début de l'analyse' AS "Méthode",
^

The problem here is that "Start parse" is translated with "Début de
l'analyse" (which is a bad translation but that's not the point). The
point is that the query is not protected against quotes and backslashes
and this is bad. My code is probably ugly, I trust you on this, but I
think we need to fix this. I think we have two ways to do it :
- escaping the translated words ;
- removing the call to gettext (so no translations for these strings).

I found \dFp but we could have the same problems with \dp because it
puts directly in the query the translations of some words (table, view,
sequence, aggregate, function, operator, datatype, rule, trigger) which
is not a problem in French but can be one in another language. \du, \dg,
\d seem to have problems too.

Regards.

--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-12-11 20:59:41 Re: psql \dFp's behavior
Previous Message Tom Lane 2007-12-11 20:16:33 Re: psql \dFp's behavior