DBD-Firebird
view release on metacpan or search on metacpan
t/75-utf8.t view on Meta::CPAN
chr CHAR(20) CHARACTER SET UTF8,
blb BLOB SUB_TYPE TEXT CHARACTER SET UTF8
)
DEF
ok( $dbh->do($def), qq{CREATE TABLE '$table'} );
#
# Insert a row into the test table as raw SQL
#
ok( $dbh->do(qq{INSERT INTO $table VALUES (1, 'ASCII varchar', 'ASCII char', 'ASCII blob')}) );
#
# Now, see if selected data is plain ASCII as it should be
#
ok( my $cursor = $dbh->prepare("SELECT * FROM $table WHERE id = ?"),
'SELECT' );
ok( $cursor->execute(1) );
my $row = $cursor->fetchrow_arrayref;
$cursor->finish;
ok( !utf8::is_utf8($row->[0]), 'ASCII varchar' );
ok( !utf8::is_utf8($row->[1]), 'ASCII char' );
ok( !utf8::is_utf8($row->[2]), 'ASCII blob' );
#
# Insert with binding, still ASCII
#
ok( $dbh->do(
"INSERT INTO $table VALUES (2, ?, ?, ?)",
{},
'Still plain varchar',
'Still plain char',
'Still plain blob'
)
);
ok( $cursor->execute(2) );
$row = $cursor->fetchrow_arrayref;
$cursor->finish;
is( $row->[0], 2 );
is( $row->[1], 'Still plain varchar' );
is( $row->[2], 'Still plain char' );
is( $row->[3], 'Still plain blob' );
#
# Insert UTF8, embedded
#
ok( $dbh->do(
"INSERT INTO $table VALUES(3, 'VærÑà r', 'Tæst', 'â¬Ã·â')")
);
ok( $cursor->execute(3) );
$row = $cursor->fetchrow_arrayref;
$cursor->finish;
is( $row->[0], 3 );
is( $row->[1], 'VærÑà r' );
is( $row->[2], 'Tæst' );
is( $row->[3], 'â¬Ã·â', 'inline unicode blob' );
#
# Insert UTF8, binding
#
ok( $dbh->do(
"INSERT INTO $table VALUES(4, ?, ?, ?)",
{}, 'VærÑà r', 'Tæst', 'â¬Ã·â'
)
);
ok( $cursor->execute(4) );
$row = $cursor->fetchrow_arrayref;
$cursor->finish;
is( $row->[0], 4 );
is( $row->[1], 'VærÑà r' );
is( $row->[2], 'Tæst' );
is( $row->[3], 'â¬Ã·â', 'bound unicode blob' );
#
# Now turn off unicode support. things we fetch should not be flagged as
# unicode anymore
#
$dbh->{ib_enable_utf8} = 0;
ok( !$dbh->{ib_enable_utf8}, 'Turn off ib_enable_utf8' );
ok( $cursor->execute(4) );
$row = $cursor->fetchrow_arrayref;
$cursor->finish;
is( $row->[0], 4 );
is( $row->[1], encode_utf8('VærÑà r'), 'non-unicode varchar' );
is( $row->[2], encode_utf8('Tæst'), 'non-unicode char' );
is( $row->[3], encode_utf8('â¬Ã·â'), 'non-unicode blob' );
#
# ... and drop it.
#
ok($dbh->do("DROP TABLE $table"), "DROP TABLE '$table'");
#
# Finally disconnect.
#
ok($dbh->disconnect());
( run in 2.703 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )