[Dbix-class] Am I using utf8_columns correctly.

Ian Docherty dbix-class at iandocherty.com
Tue May 27 19:02:45 BST 2008


Hi

I have a mysql database table and columns in the table with 
utf8_general_ci collation.

I can enter and read Bulgarian text (utf8) using phpmyadmin but cannot 
output it through DBIx::Class.

Am I using utf8_columns correctly?

Here is the output the code produces.

1: message = [Main Page] value=[???????? ????????]
2) message = [Main Page] value=[???????? ????????]

Here is the simplest code I can produce to demonstrate the problem.
Are there any other things I can do to investigate the problem?

Regards
Ian
########################

#!/usr/bin/perl -w
use strict;
use utf8;
use Encode;

########################
package DB::Main::Lexicon;

use base qw/DBIx::Class/;

__PACKAGE__->load_components(qw(PK::Auto UTF8Columns Core));
__PACKAGE__->table('lexicon');
__PACKAGE__->add_columns(qw(id language path message value notes));
__PACKAGE__->set_primary_key('id');
__PACKAGE__->utf8_columns(qw/value notes/);

########################
package DB::Main;

use base qw/DBIx::Class::Schema/;

__PACKAGE__->load_classes(qw(Lexicon));

########################
package main;

my $schema = 
DB::Main->connect('DBI:mysql:host=localhost;database=test_db','user','secret');

my $lex = $schema->resultset('Lexicon')->first;

# just output without encoding
print "1: message = [".$lex->message."] value=[".$lex->value."]\n";

# output encoded, based on advent calendar article 
http://catalyst.perl.org/calendar/2006/21
print Encode::encode('utf-8', "2) message = [".$lex->message."] 
value=[".$lex->value."]\n");

1;





More information about the DBIx-Class mailing list