|
Packit |
723767 |
#!/usr/bin/perl
|
|
Packit |
723767 |
|
|
Packit |
723767 |
use strict;
|
|
Packit |
723767 |
BEGIN {
|
|
Packit |
723767 |
$| = 1;
|
|
Packit |
723767 |
$^W = 1;
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|
|
Packit |
723767 |
use lib "t/lib";
|
|
Packit |
723767 |
use SQLiteTest qw/connect_ok/;
|
|
Packit |
723767 |
use Test::More;
|
|
Packit |
723767 |
BEGIN {
|
|
Packit |
723767 |
if ( $] >= 5.008005 ) {
|
|
Packit |
723767 |
plan( tests => 50 );
|
|
Packit |
723767 |
} else {
|
|
Packit |
723767 |
plan( skip_all => 'Unicode is not supported before 5.8.5' );
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
use Test::NoWarnings;
|
|
Packit |
723767 |
use DBI qw/:sql_types/;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
my $dbh = connect_ok(sqlite_unicode => 1);
|
|
Packit |
723767 |
$dbh->do('create table test1 (id integer, b blob)');
|
|
Packit |
723767 |
|
|
Packit |
723767 |
my $blob = "\x{82}\x{A0}";
|
|
Packit |
723767 |
my $str = "\x{20ac}";
|
|
Packit |
723767 |
|
|
Packit |
723767 |
{
|
|
Packit |
723767 |
my $sth = $dbh->prepare('insert into test1 values (?, ?)');
|
|
Packit |
723767 |
|
|
Packit |
723767 |
$sth->execute(1, $blob);
|
|
Packit |
723767 |
|
|
Packit |
723767 |
$sth->bind_param(1, 2);;
|
|
Packit |
723767 |
$sth->bind_param(2, $blob, SQL_BLOB);
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
$sth->bind_param(1, 3);;
|
|
Packit |
723767 |
$sth->bind_param(2, $blob, {TYPE => SQL_BLOB});
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
$sth->bind_param(2, undef, SQL_VARCHAR);
|
|
Packit |
723767 |
$sth->execute(4, $str);
|
|
Packit |
723767 |
|
|
Packit |
723767 |
$sth->bind_param(1, 5);;
|
|
Packit |
723767 |
$sth->bind_param(2, utf8::encode($str), SQL_BLOB);
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
$sth->bind_param(1, 6);;
|
|
Packit |
723767 |
$sth->bind_param(2, utf8::encode($str), {TYPE => SQL_BLOB});
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
$sth->finish;
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|
|
Packit |
723767 |
{
|
|
Packit |
723767 |
my $sth = $dbh->prepare('select * from test1 order by id');
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
my $expected = [undef, 1, 0, 0, 1, 1, 1];
|
|
Packit |
723767 |
for (1..6) {
|
|
Packit |
723767 |
my $row = $sth->fetch;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
ok $row && $row->[0] == $_;
|
|
Packit |
723767 |
ok $row && utf8::is_utf8($row->[1]) == $expected->[$_],
|
|
Packit |
723767 |
"row $_ is ".($expected->[$_] ? "unicode" : "not unicode");
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
$sth->finish;
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|
|
Packit |
723767 |
{
|
|
Packit |
723767 |
my $sth = $dbh->prepare('select * from test1 order by id');
|
|
Packit |
723767 |
$sth->bind_col(1, \my $col1);
|
|
Packit |
723767 |
$sth->bind_col(2, \my $col2);
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
my $expected = [undef, 1, 0, 0, 1, 1, 1];
|
|
Packit |
723767 |
for (1..6) {
|
|
Packit |
723767 |
$sth->fetch;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
ok $col1 && $col1 == $_;
|
|
Packit |
723767 |
ok $col1 && utf8::is_utf8($col2) == $expected->[$_],
|
|
Packit |
723767 |
"row $_ is ".($expected->[$_] ? "unicode" : "not unicode");
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
$sth->finish;
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|
|
Packit |
723767 |
{
|
|
Packit |
723767 |
my $sth = $dbh->prepare('select * from test1 order by id');
|
|
Packit |
723767 |
$sth->bind_col(1, \my $col1);
|
|
Packit |
723767 |
$sth->bind_col(2, \my $col2, SQL_BLOB);
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
my $expected = [undef, 0, 0, 0, 0, 0, 0];
|
|
Packit |
723767 |
for (1..6) {
|
|
Packit |
723767 |
$sth->fetch;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
ok $col1 && $col1 == $_;
|
|
Packit |
723767 |
ok $col2 && utf8::is_utf8($col2) == $expected->[$_],
|
|
Packit |
723767 |
"row $_ is ".($expected->[$_] ? "unicode" : "not unicode");
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
$sth->finish;
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
|
|
Packit |
723767 |
{
|
|
Packit |
723767 |
my $sth = $dbh->prepare('select * from test1 order by id');
|
|
Packit |
723767 |
$sth->bind_col(1, \my $col1);
|
|
Packit |
723767 |
$sth->bind_col(2, \my $col2, {TYPE => SQL_BLOB});
|
|
Packit |
723767 |
$sth->execute;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
my $expected = [undef, 0, 0, 0, 0, 0, 0];
|
|
Packit |
723767 |
for (1..6) {
|
|
Packit |
723767 |
$sth->fetch;
|
|
Packit |
723767 |
|
|
Packit |
723767 |
ok $col1 && $col1 == $_;
|
|
Packit |
723767 |
ok $col2 && utf8::is_utf8($col2) == $expected->[$_],
|
|
Packit |
723767 |
"row $_ is ".($expected->[$_] ? "unicode" : "not unicode");
|
|
Packit |
723767 |
}
|
|
Packit |
723767 |
$sth->finish;
|
|
Packit |
723767 |
}
|