Hi,

I have the following setup : Workstation, Primary, and Backup servers all 
running on a current version of Debian Stable. All run an identical LAMP stack 
of Apache/Mod_perl/Postgresql, except for default locale (see below). DBD::PG 
version is 3.0.0

My perl modules misbehave when connecting to a UTF8 encoded database on the 
backup server *only*. The link below shows the result of Data::Dumper, decode, 
and data_string_desc for each machine, for a record containing accented 
characters.

http://vincentveyron.com/tmp/tmp.html

I have 2 questions :

- Why does data_string_desc return 'UTF8 off' all servers, when the database is 
UTF8 encoded?

- What should I inspect to understand why data_string_desc gets a wrong number 
of characters in the backup server?

#
#/etc/default/locale for each server 
#
#Workstation
LANG=fr_FR.UTF-8

#Primary
LANG=fr_FR@euro
LANGUAGE=fr_FR:fr

#Backup
LANG=fr_FR@euro


#
#Code used for the example
#
package Mysite::utf8_db_handle ;

use strict ;
use warnings ;

use DBI qw(:utils) ;

use Data::Dumper ;

use Encode qw (decode) ;

use Apache2::Const -compile => qw (OK REDIRECT) ;

sub handler {

    my $r = shift ;

    my $dbh = DBI->connect_cached( "DBI:Pg:dbname=bla_2", 'www-data', undef, {
        PrintError => 1,
        RaiseError => 1,
        AutoCommit => 1,
        pg_bool_tf => 't'
                                  } ) ;

    my $sql = 'SELECT prenom FROM tblclient where id_client=2' ;

    my $result_set = $dbh->selectall_arrayref($sql) ;

    my $content = '<h1>Mysite</h1>' ;
    
    $content = '<h2>Not decoded, using Data::Dumper</h2>' ;

    $content .= '<pre>' ;

    $content .= Dumper($result_set) ;
    
    $content .= '</pre>' ;

    $content .= '<h2>Decoded using decode(UTF8,...</h2>' ;

    $content .= '<p>' . ( decode('UTF8', $result_set->[0]->[0] ) || 'wtf?' ) . 
'</p>' ;

    $content .= '<h2>data_string_desc</h2>' ;

    $content .= '<p>' . data_string_desc($result_set->[0]->[0]) . '</p>' ;

    $r->content_type('text/html; charset=UTF-8') ;

    $r->no_cache(1) ;

    print $content ;

    return Apache2::Const::OK ;

}

1 ;



-- 
                                        Salutations, Vincent Veyron

http://marica.fr/
Gestion des contentieux, des dossiers de sinistres assurance et des contrats 
pour le service juridique

Reply via email to