Subject: | garbled characters in Tk |
I load data from Tk widget into DBD::CSV and then back to the widget. Characters over \x100 are garbled when retrieved from db. Characters in widgets over \x100 not manipulated by db (Tk labels) are correct. A script uses encoding 'utf-8' pragma. Running a script without packing doesn't exhibit this problem.
test.pl included
PAR 0.87, perl 5.8.6, Windows XP
DBI 1.47, DBD::CSV 0.21
Radek
use DBI qw(:utils);
use Tk;
use encoding 'utf-8';
require encoding;
use strict;
use warnings;
my ($dir,$mw,$en,$dbh,$sth,$values,$text,@line,$desc,$desc2);
$mw = MainWindow->new();
$mw->geometry("100x50");
$mw->Label(-text=>'žž',
-width=>20,
)->pack;
$en = $mw->Entry(-width=>20,
)->pack;
$en->focus;
$dbh = DBI->connect("DBI:CSV:csv_sep_char=\\|",{RaiseError => 1,AutoCommit => 1})
or die "Cannot connect: " . $DBI::errstr;
$values = "('šš','žž','cc')";
$desc = data_string_desc($values);
print "before: $desc\n";
$dbh->do(qq/INSERT INTO test VALUES $values/)
or die "Cannot insert: " . $DBI::errstr;
$sth = $dbh->prepare(qq/SELECT * FROM test/);
$sth->execute();
@line = $sth->fetchrow_array;
$text = "@line";
$desc2 = data_string_desc($text);
print "after: $desc2\n";
$sth->finish;
$dbh->disconnect;
$en->configure(-textvariable=>\$text);
MainLoop;
=head2 test DB
one|two|three
šš|žž|cc
=cut