mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-08 22:58:17 -04:00
more unicode tests; now I think #72418 can also be considered resolved
This commit is contained in:
parent
8c6a921eed
commit
843f5e1a7e
1 changed files with 136 additions and 74 deletions
|
@ -7,91 +7,153 @@ BEGIN {
|
||||||
}
|
}
|
||||||
|
|
||||||
use t::lib::Test;
|
use t::lib::Test;
|
||||||
use Test::More tests => 22;
|
use Test::More tests => 29 * 2 + 1;
|
||||||
use Test::NoWarnings;
|
use Test::NoWarnings;
|
||||||
use Encode;
|
use Encode;
|
||||||
|
|
||||||
my $unicode = "\x{263A}"; # (decoded) smiley character
|
unicode_test("\x{263A}"); # (decoded) smiley character
|
||||||
ok Encode::is_utf8($unicode), "smiley is correctly decoded";
|
unicode_test("\x{0100}"); # (decoded) capital A with macron
|
||||||
|
|
||||||
my $unicode_encoded = encode_utf8($unicode);
|
sub unicode_test {
|
||||||
|
my $unicode = shift;
|
||||||
|
|
||||||
{ # tests for an environment where everything is encoded
|
ok Encode::is_utf8($unicode), "correctly decoded";
|
||||||
|
|
||||||
my $dbh = connect_ok(sqlite_unicode => 0);
|
my $unicode_encoded = encode_utf8($unicode);
|
||||||
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";
|
{ # tests for an environment where everything is encoded
|
||||||
ok $dbh->do("insert into foo (id, $unicode_quoted) values (?, ?)", undef, 2, "text2"), "insert with unicode name successfully";
|
|
||||||
|
|
||||||
{
|
my $dbh = connect_ok(sqlite_unicode => 0);
|
||||||
my $sth = $dbh->prepare("select * from foo where id = ?");
|
$dbh->do("pragma foreign_keys = on");
|
||||||
$sth->execute(1);
|
my $unicode_quoted = $dbh->quote_identifier($unicode_encoded);
|
||||||
my $row = $sth->fetchrow_hashref;
|
$dbh->do("create table $unicode_quoted (id, $unicode_quoted primary key)");
|
||||||
is $row->{id} => 1, "got correct row";
|
$dbh->do("create table bar (id, ref references $unicode_quoted ($unicode_encoded))");
|
||||||
is $row->{$unicode_encoded} => "text", "got correct (encoded) unicode column data";
|
|
||||||
ok !exists $row->{$unicode}, "(decoded) unicode column does not exist";
|
ok $dbh->do("insert into $unicode_quoted values (?, ?)", undef, 1, "text"), "insert successfully";
|
||||||
|
ok $dbh->do("insert into $unicode_quoted (id, $unicode_quoted) values (?, ?)", undef, 2, "text2"), "insert with unicode name successfully";
|
||||||
|
|
||||||
|
{
|
||||||
|
my $sth = $dbh->prepare("insert into $unicode_quoted (id) values (:$unicode_encoded)");
|
||||||
|
$sth->bind_param(":$unicode_encoded", 5);
|
||||||
|
$sth->execute;
|
||||||
|
my ($id) = $dbh->selectrow_array("select id from $unicode_quoted where id = :$unicode_encoded", undef, 5);
|
||||||
|
is $id => 5, "unicode placeholders";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $sth = $dbh->prepare("select * from $unicode_quoted 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 $unicode_quoted 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 $unicode_quoted 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, $unicode_encoded, $unicode_encoded);
|
||||||
|
my $column_info = $sth->fetchrow_hashref;
|
||||||
|
is $column_info->{COLUMN_NAME} => $unicode_encoded, "column_info returns the correctly encoded column name";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $sth = $dbh->primary_key_info(undef, undef, $unicode_encoded);
|
||||||
|
my $primary_key_info = $sth->fetchrow_hashref;
|
||||||
|
is $primary_key_info->{COLUMN_NAME} => $unicode_encoded, "primary_key_info returns the correctly encoded primary key name";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $sth = $dbh->foreign_key_info(undef, undef, $unicode_encoded, undef, undef, 'bar');
|
||||||
|
my $foreign_key_info = $sth->fetchrow_hashref;
|
||||||
|
is $foreign_key_info->{PKCOLUMN_NAME} => $unicode_encoded, "foreign_key_info returns the correctly encoded foreign key name";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $sth = $dbh->table_info(undef, undef, $unicode_encoded);
|
||||||
|
my $table_info = $sth->fetchrow_hashref;
|
||||||
|
is $table_info->{TABLE_NAME} => $unicode_encoded, "table_info returns the correctly encoded table name";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{ # tests for an environment where everything is decoded
|
||||||
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 $dbh = connect_ok(sqlite_unicode => 1);
|
||||||
my $sth = $dbh->prepare("select id from foo where $unicode_quoted = ?");
|
$dbh->do("pragma foreign_keys = on");
|
||||||
$sth->execute("text");
|
my $unicode_quoted = $dbh->quote_identifier($unicode);
|
||||||
my ($id) = $sth->fetchrow_array;
|
$dbh->do("create table $unicode_quoted (id, $unicode_quoted primary key)");
|
||||||
is $id => 1, "got correct id by the (encoded) unicode column value";
|
$dbh->do("create table bar (id, ref references $unicode_quoted ($unicode_quoted))");
|
||||||
}
|
|
||||||
|
|
||||||
{
|
ok $dbh->do("insert into $unicode_quoted values (?, ?)", undef, 1, "text"), "insert successfully";
|
||||||
my $sth = $dbh->column_info(undef, undef, 'foo', $unicode_encoded);
|
ok $dbh->do("insert into $unicode_quoted (id, $unicode_quoted) values (?, ?)", undef, 2, "text2"), "insert with unicode name successfully";
|
||||||
my $column_info = $sth->fetchrow_hashref;
|
|
||||||
is $column_info->{COLUMN_NAME} => $unicode_encoded, "column_info returns the correctly encoded column name";
|
{
|
||||||
}
|
my $sth = $dbh->prepare("insert into $unicode_quoted (id) values (:$unicode)");
|
||||||
}
|
$sth->bind_param(":$unicode", 5);
|
||||||
|
$sth->execute;
|
||||||
{ # tests for an environment where everything is decoded
|
my ($id) = $dbh->selectrow_array("select id from $unicode_quoted where id = :$unicode", undef, 5);
|
||||||
|
is $id => 5, "unicode placeholders";
|
||||||
my $dbh = connect_ok(sqlite_unicode => 1);
|
}
|
||||||
my $unicode_quoted = $dbh->quote_identifier($unicode);
|
|
||||||
$dbh->do("create table foo (id, $unicode_quoted)");
|
{
|
||||||
|
my $sth = $dbh->prepare("select * from $unicode_quoted where id = ?");
|
||||||
ok $dbh->do("insert into foo values (?, ?)", undef, 1, "text"), "insert successfully";
|
$sth->execute(1);
|
||||||
ok $dbh->do("insert into foo (id, $unicode_quoted) values (?, ?)", undef, 2, "text2"), "insert with unicode name successfully";
|
my $row = $sth->fetchrow_hashref;
|
||||||
|
is $row->{id} => 1, "got correct row";
|
||||||
{
|
is $row->{$unicode} => "text", "got correct (decoded) unicode column data";
|
||||||
my $sth = $dbh->prepare("select * from foo where id = ?");
|
ok !exists $row->{$unicode_encoded}, "(encoded) unicode column does not exist";
|
||||||
$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";
|
my $sth = $dbh->prepare("select $unicode_quoted from $unicode_quoted where id = ?");
|
||||||
ok !exists $row->{$unicode_encoded}, "(encoded) unicode column does not exist";
|
$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 $unicode_quoted from foo where id = ?");
|
}
|
||||||
$sth->execute(1);
|
|
||||||
my $row = $sth->fetchrow_hashref;
|
{
|
||||||
is $row->{$unicode} => "text", "got correct (decoded) unicode column data";
|
my $sth = $dbh->prepare("select id from $unicode_quoted where $unicode_quoted = ?");
|
||||||
ok !exists $row->{$unicode_encoded}, "(encoded) unicode column does not exist";
|
$sth->execute("text2");
|
||||||
}
|
my ($id) = $sth->fetchrow_array;
|
||||||
|
is $id => 2, "got correct id by the (decoded) unicode column value";
|
||||||
{
|
}
|
||||||
my $sth = $dbh->prepare("select id from foo where $unicode_quoted = ?");
|
|
||||||
$sth->execute("text2");
|
{
|
||||||
my ($id) = $sth->fetchrow_array;
|
my $sth = $dbh->column_info(undef, undef, $unicode, $unicode);
|
||||||
is $id => 2, "got correct id by the (decoded) unicode column value";
|
my $column_info = $sth->fetchrow_hashref;
|
||||||
}
|
is $column_info->{COLUMN_NAME} => $unicode, "column_info returns the correctly decoded column name";
|
||||||
|
}
|
||||||
{
|
|
||||||
my $sth = $dbh->column_info(undef, undef, 'foo', $unicode);
|
{
|
||||||
my $column_info = $sth->fetchrow_hashref;
|
my $sth = $dbh->primary_key_info(undef, undef, $unicode);
|
||||||
is $column_info->{COLUMN_NAME} => $unicode, "column_info returns the correctly decoded column name";
|
my $primary_key_info = $sth->fetchrow_hashref;
|
||||||
|
is $primary_key_info->{COLUMN_NAME} => $unicode, "primary_key_info returns the correctly decoded primary key name";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $sth = $dbh->foreign_key_info(undef, undef, $unicode, undef, undef, 'bar');
|
||||||
|
my $foreign_key_info = $sth->fetchrow_hashref;
|
||||||
|
is $foreign_key_info->{PKCOLUMN_NAME} => $unicode, "foreign_key_info returns the correctly decoded foreign key name";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
my $sth = $dbh->table_info(undef, undef, $unicode);
|
||||||
|
my $table_info = $sth->fetchrow_hashref;
|
||||||
|
is $table_info->{TABLE_NAME} => $unicode, "table_info returns the correctly decoded table name";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue