Re: lc_time and localized dates - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: lc_time and localized dates
Date
Msg-id 200805180425.m4I4PkZ05239@momjian.us
Whole thread Raw
In response to Re: lc_time and localized dates  (Euler Taveira de Oliveira <euler@timbira.com>)
Responses Re: lc_time and localized dates  (Euler Taveira de Oliveira <euler@timbira.com>)
Re: lc_time and localized dates  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
I have reviewed this patch.  I like the method you used, but I did find
a few things I had to change.

First, I found the abbreviated variable names confusing so I used longer
ones, like:

    extern char       *localized_abbrev_days[7];
    extern char       *localized_full_days[7];
    extern char       *localized_abbrev_months[12];
    extern char       *localized_full_months[12];

Second, I found that the code doing upper/lower case didn't work.  It
was copying the buffer into a 'result' variable, but then incrementing
'result' so by the end 'result' pointed to only the null byte, and that
is the pointer that was returned.  Third, there were a few places where
the code assumed str_toupper() modified the passed buffer, rather than
returning a new one.  And finally, while you used strdup() to save
values in the cache (good), you never free()'ed the old values when you
were reloading the cache.

I have fixed all these items and the updated patch is at:

    ftp://momjian.us/pub/postgresql/mypatches/lc_time

The original patch was here:

    http://archives.postgresql.org/message-id/481011DC.3050900@timbira.com

---------------------------------------------------------------------------

Euler Taveira de Oliveira wrote:
> Bruce Momjian wrote:
>
> > Euler, have you updated this patch yet?
> >
> Here is an updated patch. It follows the Oracle behaviour and uses a
> cache mechanism to avoid calling setlocale() all the time. I unified the
> localized_* and str_* functions.  I didn't test it on Windows. I would
> appreciate some feedback.
>
>
> euler=# select to_char(now(), 'dy tmDy tmDay mon tmMON tmmonth YYYY');
>                to_char
> -----------------------------------
>   thu Qui Quinta apr ABR abril 2008
> (1 registro)
>
> euler=# set lc_time to 'it_IT.UTF-8';
> SET
> euler=# select to_char(now(), 'dy tmDy tmDay mon tmMON tmmonth YYYY');
>                 to_char
> -------------------------------------
>   thu Gio Gioved? apr APR aprile 2008
> (1 registro)
>
> euler=# set lc_time to 'es_ES.UTF-8';
> SET
> euler=# select to_char(now(), 'dy tmDy tmDay mon tmMON tmmonth YYYY');
>                to_char
> -----------------------------------
>   thu Jue Jueves apr ABR abril 2008
> (1 registro)
>
> euler=# set lc_time to 'fr_FR.UTF-8';
> SET
> euler=# select to_char(now(), 'dy tmDy tmDay mon tmMON tmmonth YYYY');
>               to_char
> ----------------------------------
>   thu Jeu Jeudi apr AVR avril 2008
> (1 registro)
>
> euler=# set lc_time to 'cs_CZ.UTF-8';
> SET
> euler=# select to_char(now(), 'dy tmDy tmDay mon tmMON tmmonth YYYY');
>                to_char
> -----------------------------------
>   thu ?t ?tvrtek apr DUB duben 2008
> (1 registro)
>
>
> --
>    Euler Taveira de Oliveira
>    http://www.timbira.com/

[ application/x-gzip is not supported, skipping... ]

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

pgsql-patches by date:

Previous
From: Euler Taveira de Oliveira
Date:
Subject: Re: pg_dump lock timeout - resend
Next
From: Euler Taveira de Oliveira
Date:
Subject: Re: lc_time and localized dates