From e12535f140db91c421a98595bf239c9e8ac5668d Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Wed, 5 Sep 2012 14:55:34 +0000 Subject: [PATCH] resolved #78833 with a patch from JAMADAM --- dbdimp.c | 5 +- t/rt_78833_utf8_flag_for_column_names.t | 97 +++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 t/rt_78833_utf8_flag_for_column_names.t diff --git a/dbdimp.c b/dbdimp.c index aa20de7..ff54b97 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -1093,7 +1093,10 @@ sqlite_st_FETCH_attrib(SV *sth, imp_sth_t *imp_sth, SV *keysv) /* char *dot = instr(fieldname, "."); */ /* if (dot) drop table name from field name */ /* fieldname = ++dot; */ - av_store(av, n, newSVpv(fieldname, 0)); + SV *sv_fieldname = newSVpv(fieldname, 0); + if (imp_dbh->unicode) + SvUTF8_on(sv_fieldname); + av_store(av, n, sv_fieldname); } } } diff --git a/t/rt_78833_utf8_flag_for_column_names.t b/t/rt_78833_utf8_flag_for_column_names.t new file mode 100644 index 0000000..0fb596a --- /dev/null +++ b/t/rt_78833_utf8_flag_for_column_names.t @@ -0,0 +1,97 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test; +use Test::More tests => 22; +use Test::NoWarnings; +use Encode; + +my $unicode = "\x{263A}"; # (decoded) smiley character +ok Encode::is_utf8($unicode), "smiley is correctly decoded"; + +my $unicode_encoded = encode_utf8($unicode); + +{ # tests for an environment where everything is encoded + + my $dbh = connect_ok(sqlite_unicode => 0); + my $unicode_quoted = $dbh->quote_identifier($unicode_encoded); + $dbh->do("create table foo (id, $unicode_quoted)"); + + ok $dbh->do("insert into foo values (?, ?)", undef, 1, "text"), "insert successfully"; + ok $dbh->do("insert into foo (id, $unicode_quoted) values (?, ?)", undef, 2, "text2"), "insert with unicode name successfully"; + + { + my $sth = $dbh->prepare("select * from foo where id = ?"); + $sth->execute(1); + my $row = $sth->fetchrow_hashref; + is $row->{id} => 1, "got correct row"; + is $row->{$unicode_encoded} => "text", "got correct (encoded) unicode column data"; + ok !exists $row->{$unicode}, "(decoded) unicode column does not exist"; + } + + { + my $sth = $dbh->prepare("select $unicode_quoted from foo where id = ?"); + $sth->execute(1); + my $row = $sth->fetchrow_hashref; + is $row->{$unicode_encoded} => "text", "got correct (encoded) unicode column data"; + ok !exists $row->{$unicode}, "(decoded) unicode column does not exist"; + } + + { + my $sth = $dbh->prepare("select id from foo where $unicode_quoted = ?"); + $sth->execute("text"); + my ($id) = $sth->fetchrow_array; + is $id => 1, "got correct id by the (encoded) unicode column value"; + } + + { + my $sth = $dbh->column_info(undef, undef, 'foo', $unicode_encoded); + my $column_info = $sth->fetchrow_hashref; + is $column_info->{COLUMN_NAME} => $unicode_encoded, "column_info returns the correctly encoded column name"; + } +} + +{ # tests for an environment where everything is decoded + + my $dbh = connect_ok(sqlite_unicode => 1); + my $unicode_quoted = $dbh->quote_identifier($unicode); + $dbh->do("create table foo (id, $unicode_quoted)"); + + ok $dbh->do("insert into foo values (?, ?)", undef, 1, "text"), "insert successfully"; + ok $dbh->do("insert into foo (id, $unicode_quoted) values (?, ?)", undef, 2, "text2"), "insert with unicode name successfully"; + + { + my $sth = $dbh->prepare("select * from foo where id = ?"); + $sth->execute(1); + my $row = $sth->fetchrow_hashref; + is $row->{id} => 1, "got correct row"; + is $row->{$unicode} => "text", "got correct (decoded) unicode column data"; + ok !exists $row->{$unicode_encoded}, "(encoded) unicode column does not exist"; + } + + { + my $sth = $dbh->prepare("select $unicode_quoted from foo where id = ?"); + $sth->execute(1); + my $row = $sth->fetchrow_hashref; + is $row->{$unicode} => "text", "got correct (decoded) unicode column data"; + ok !exists $row->{$unicode_encoded}, "(encoded) unicode column does not exist"; + } + + { + my $sth = $dbh->prepare("select id from foo where $unicode_quoted = ?"); + $sth->execute("text2"); + my ($id) = $sth->fetchrow_array; + is $id => 2, "got correct id by the (decoded) unicode column value"; + } + + { + my $sth = $dbh->column_info(undef, undef, 'foo', $unicode); + my $column_info = $sth->fetchrow_hashref; + is $column_info->{COLUMN_NAME} => $unicode, "column_info returns the correctly decoded column name"; + } +}