#!perl -w
$|=1;
eval
{
import
Storable
qw(dclone)
;
import
Encode
qw(_utf8_on _utf8_off is_utf8)
;
};
plan
skip_all
=>
"Unable to load required module ($@)"
unless
defined
&_utf8_on
;
plan
tests
=> 16;
$dbh
= DBI->
connect
(
"dbi:Sponge:foo"
,
""
,
""
, {
PrintError
=> 0,
RaiseError
=> 1,
});
my
$source_rows
= [
[ 41,
"AAA"
, 9 ],
[ 42,
"BB"
,
undef
],
[ 43,
undef
, 7 ],
[ 44,
"DDD"
, 6 ],
];
my
(
$sth
,
$col0
,
$col1
,
$col2
,
$rows
);
my
@col_names
=
qw(Col1 Col2 Col3)
;
_utf8_on(
$col_names
[1]);
ok is_utf8(
$col_names
[1]);
ok !is_utf8(
$col_names
[0]);
$sth
=
$dbh
->prepare(
"foo"
, {
rows
=> dclone(
$source_rows
),
NAME
=> \
@col_names
,
});
ok(
$sth
->bind_columns(\(
$col0
,
$col1
,
$col2
)) );
ok(
$sth
->execute(),
$DBI::errstr
);
ok
$sth
->fetch;
cmp_ok
$col1
,
'eq'
,
"AAA"
;
ok !is_utf8(
$col1
);
_utf8_on(
$col1
);
ok is_utf8(
$col1
);
ok
$sth
->fetch;
cmp_ok
$col1
,
'eq'
,
"BB"
;
ok !is_utf8(
$col1
);
ok
$sth
->fetch;
ok !
defined
$col1
;
ok !is_utf8(
$col1
);
ok
my
$hash
=
$sth
->fetchrow_hashref;
ok 1 ==
grep
{ is_utf8(
$_
) }
keys
%$hash
;
$sth
->finish;