List:MySQL and Perl« Previous MessageNext Message »
From:Gaal Yahas Date:June 10 2004 12:26pm
Subject:Re: [PATCH] Re: blessing db data as utf8
View as plain text  
On Thu, Jun 10, 2004 at 12:07:54PM +0200, Jochen Wiedmann wrote:
> 
> Good patch, in particular because it includes the docs!

Thanks. Here's a test script I've been using that may be seriousified
and ported into the DBD test suite. I didn't do that last step myself
because I was unfamiliar with the idioms.

-- 
Gaal Yahas <gaal@stripped>
http://gaal.livejournal.com/


#!/usr/bin/perl -w
# make sure utf8 patch is applied to current DBD::mysql

use strict;
use charnames ':full';
use DBI;

my $dbh = DBI->connect("DBI:mysql:database=test", "", "",
    {mysql_enable_utf8=>1}) or die "dbi: $DBI::errstr";

$dbh->{mysql_enable_utf8} or die "couldn't init mysql_enable_utf8";

# uncomment this for proof this whole feature is necessary
#$dbh->{mysql_enable_utf8} = 0; print "Your test WILL fail, you know.\n";

$dbh->do("DROP TABLE IF EXISTS test_u8");
$dbh->do(<<DML);
CREATE TABLE test_u8 (
    id integer,
    name varchar(40)
);
DML

# "Eli".
my $name =
    "\N{HEBREW LETTER ALEF}\N{HEBREW LETTER LAMED}\N{HEBREW LETTER YOD}";
length $name == 3 or die "your perl sucks. $name isn't in utf8?";

my $sth = $dbh->prepare("INSERT INTO test_u8 (id, name) values (?, ?)");
$sth->execute(1, $name);

my @row = $dbh->selectrow_array("SELECT id, name FROM test_u8;");
die "number didn't stay the same!?!?!!"       unless $row[0] == 1;
die "sorry, utf8 discipline failed: len != 3" unless length $row[1] == 3;
die "sorry, utf8 discipline failed: strcmp"   unless $row[1] eq $name;

print "yay, you are teh utf king!!!!11\n";
$dbh->do("DROP TABLE test_u8");
Thread
blessing db data as utf8Gaal Yahas9 Jun
  • Re: blessing db data as utf8Jochen Wiedmann9 Jun
    • Re: blessing db data as utf8Gaal Yahas9 Jun
      • Re: blessing db data as utf8Jochen Wiedmann9 Jun
        • Re: blessing db data as utf8Gaal Yahas9 Jun
  • [PATCH] Re: blessing db data as utf8Gaal Yahas9 Jun
    • Re: [PATCH] Re: blessing db data as utf8Jochen Wiedmann10 Jun
      • Re: [PATCH] Re: blessing db data as utf8Gaal Yahas10 Jun
      • Re: [PATCH] Re: blessing db data as utf8Steve Hay10 Jun
        • Re: [PATCH] Re: blessing db data as utf8Gaal Yahas10 Jun
          • Re: [PATCH] Re: blessing db data as utf8Steve Hay11 Jun
            • Re: [PATCH] Re: blessing db data as utf8Gaal Yahas11 Jun
              • Re: [PATCH] Re: blessing db data as utf8Steve Hay11 Jun
Re: blessing db data as utf8Gaal Yahas10 Jun