[dancer-users] Help with Dancer2 and Oracle DB, please. Problem with encoding

Козицкий Сергей kce at tut.by
Thu Feb 20 14:49:35 GMT 2014


I am beginner in Dancer. Help me please.

I am having database on Oracle 10g. Web server and Oracle Client is working
under openSUSE 12.3. DB data encoding is Windows-1251 (I can't change this).
I have set system environment variable NLS_LANG =
AMARICAN_AMERICA.CL8MSWIN1251. I am constantly workin with Perl and Oracle
DB and always do so.
My system console character set in openSUSE is UTF-8.

But after select I get the data in a double byte character set (I looked in
log). And this is not UTF-8. Why? What am I doing wrong?


My config.yml:

appname:    "AAA"
server:     "172.0.0.244"
port:       8008
environment:"development"
layout:     "main"
charset:    "UTF-8"
template:   "simple"
logger:     "file"
serializer: "JSON"
plugins:
    Database:
        driver:     "Oracle"
        host:       "172.0.0.250"
        sid:        "DEVDB"
        username:   "A"
        password:   "AAA"
        log_queries: 1
        auto_utf8:   0
        dbi_params:
            AutoCommit: 1
            RaiseError: 1
            PrintError: 0
            PrintWarn:  0


My simple application for test:

#!/usr/bin/perl

use v5.16;
use utf8;
use Dancer;
use Dancer::Plugin::Database;

get '/' => sub {
    var time => scalar(localtime);
    my $tst_set = database->selectcol_arrayref('SELECT label FROM et_list
WHERE tbl=1 AND gr=3');
    my $S;
    foreach  (@{$tst_set}) {
        my $s = $_;
        $S.= "$s<br>";
    }
    template 'test.tt', { test => $S };
};
dance;

In the browser, I see a clumsy unreadable text. :-(
I have tried add - Encode::from_to($s, 'cp-1251', 'utf-8'); - another clumsy
unreadable text
Encoding in the HTML set as UTF-8.

I have wrote simple perl script for test and run it from openSUSE system
console:

#!Perl
use v5.16;
use strict;
use DBI;

my $DB_Server   ='172.0.0.250';
my $DB_SID      ='DEVDB';
my $DB_User     ='A';
my $DB_Pass     ='AAA';

my $dbh;
eval{
    $dbh=DBI->connect("dbi:Oracle:host=$DB_Server;sid=$DB_SID",
             $DB_User, $DB_Pass, {
                                    AutoCommit  =>0,
                                    RaiseError  =>1,
                                    PrintError  =>0,
                                    PrintWarn   =>0
                                })
}; if ($@) {
    die "Connection error: $@"
}
my $tst_set = $dbh->selectcol_arrayref('SELECT label FROM et_list WHERE
tbl=1 AND gr=3');

say join("\n", @{$tst_set});

$dbh->disconnect;

An this work. All OK

I nothing understand.  Help me please.

PS. I have tried run this Dancer application under Windows-7 ( Dancer 1).
It's working OK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20140220/1b49a756/attachment.html>


More information about the dancer-users mailing list