mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
resolved #78833 with a patch from JAMADAM
This commit is contained in:
parent
8c8a575e37
commit
e12535f140
2 changed files with 101 additions and 1 deletions
5
dbdimp.c
5
dbdimp.c
|
@ -1093,7 +1093,10 @@ sqlite_st_FETCH_attrib(SV *sth, imp_sth_t *imp_sth, SV *keysv)
|
||||||
/* char *dot = instr(fieldname, "."); */
|
/* char *dot = instr(fieldname, "."); */
|
||||||
/* if (dot) drop table name from field name */
|
/* if (dot) drop table name from field name */
|
||||||
/* fieldname = ++dot; */
|
/* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
97
t/rt_78833_utf8_flag_for_column_names.t
Normal file
97
t/rt_78833_utf8_flag_for_column_names.t
Normal file
|
@ -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";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue