-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These tests exist in the latest CPAN release, but apparently haven't been added to git.
- Loading branch information
Showing
3 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!perl | ||
#written by Andrey A Voropaev ([email protected]) | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use DBI; | ||
use FindBin qw($Bin); | ||
use lib 't/lib'; | ||
use DBDOracleTestLib qw/ db_handle /; | ||
|
||
my $dbh; | ||
$| = 1; | ||
SKIP: { | ||
$dbh = db_handle(); | ||
|
||
# $dbh->{PrintError} = 1; | ||
plan skip_all => 'Unable to connect to Oracle' unless $dbh; | ||
|
||
note("Testing multiple cached connections...\n"); | ||
|
||
plan tests => 1; | ||
|
||
system("perl -MExtUtils::testlib $Bin/cache2.pl"); | ||
ok($? == 0, "clean termination with multiple cached connections"); | ||
} | ||
|
||
__END__ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#!perl | ||
#written by Andrey A Voropaev ([email protected]) | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use DBI; | ||
use DBD::Oracle qw(ORA_OCI); | ||
use Encode; | ||
use lib 't/lib'; | ||
use DBDOracleTestLib qw/ db_handle drop_table table force_drop_table /; | ||
|
||
my $dbh1; | ||
my $dbh2; | ||
$| = 1; | ||
SKIP: { | ||
plan skip_all => | ||
'Unable to run multiple cset test, perl version is less than 5.6' | ||
unless ( $] >= 5.006 ); | ||
|
||
$dbh1 = db_handle({ | ||
RaiseError => 0, | ||
PrintError => 0, | ||
AutoCommit => 1, | ||
ora_charset => 'WE8MSWIN1252', | ||
}); | ||
|
||
plan skip_all => 'Unable to connect to Oracle' unless $dbh1; | ||
|
||
plan skip_all => 'Oracle charset tests unreliable for Oracle 8 client' | ||
if ORA_OCI() < 9.0 and !$ENV{DBD_ALL_TESTS}; | ||
|
||
my $h = $dbh1->ora_nls_parameters(); | ||
my $chs = $h->{NLS_CHARACTERSET}; | ||
if($chs ne 'WE8MSWIN1252' && $chs ne 'WE8ISO8859P1' && $chs !~ /^AL[13]/) | ||
{ | ||
plan skip_all => 'Oracle uses incompatible charset'; | ||
} | ||
note("Testing multiple connections with different charsets...\n"); | ||
|
||
$dbh2 = db_handle({ | ||
RaiseError => 0, | ||
PrintError => 0, | ||
AutoCommit => 1, | ||
ora_charset => 'AL32UTF8', | ||
}); | ||
|
||
my $testcount = 3; | ||
|
||
plan tests => $testcount; | ||
|
||
my $tname = table(); | ||
force_drop_table($dbh1); | ||
$dbh1->do( | ||
qq{create table $tname (idx number, txt varchar2(50))} | ||
); | ||
die "Failed to create test table\n" if($dbh1->err); | ||
|
||
my $sth = $dbh1->prepare( | ||
qq{insert into $tname (idx, txt) values(?, ?)} | ||
); | ||
my $utf8_txt = 'äöüÜÖÄ'; | ||
my $x = $utf8_txt; | ||
Encode::from_to($x, 'UTF-8', 'Latin1'); | ||
$sth->execute(1, $x); | ||
|
||
$sth = $dbh1->prepare( | ||
qq{select txt from $tname where idx=1} | ||
); | ||
$sth->execute(); | ||
my $r = $sth->fetchall_arrayref(); | ||
ok(must_be_latin1($r, $utf8_txt), "Latin1 support"); | ||
|
||
$sth = $dbh2->prepare( | ||
qq{insert into $tname (idx, txt) values(?, ?)} | ||
); | ||
# insert bytes | ||
$x = $utf8_txt; | ||
$sth->execute(2, $x); | ||
# insert characters | ||
$x = $utf8_txt; | ||
$sth->execute(3, Encode::decode('UTF-8', $x)); | ||
|
||
$sth = $dbh2->prepare( | ||
qq{select txt from $tname where idx=?} | ||
); | ||
$sth->execute(2); | ||
$r = $sth->fetchall_arrayref(); | ||
ok(must_be_utf8($r, $utf8_txt), "UTF-8 as bytes"); | ||
$sth->execute(3); | ||
$r = $sth->fetchall_arrayref(); | ||
ok(must_be_utf8($r, $utf8_txt), "UTF-8 as characters"); | ||
} | ||
|
||
sub must_be_latin1 | ||
{ | ||
my $r = shift; | ||
return unless @$r == 1; | ||
my $x = $r->[0][0]; | ||
# it shouldn't be encoded | ||
return if Encode::is_utf8($x); | ||
Encode::from_to($x, 'Latin1', 'UTF-8'); | ||
return $x eq $_[0]; | ||
} | ||
|
||
sub must_be_utf8 | ||
{ | ||
my $r = shift; | ||
return unless @$r == 1; | ||
my $x = $r->[0][0]; | ||
# it should be encoded | ||
return unless Encode::is_utf8($x); | ||
return Encode::encode('UTF-8', $x) eq $_[0]; | ||
} | ||
|
||
|
||
END { | ||
eval { | ||
drop_table($dbh1) | ||
}; | ||
} | ||
|
||
__END__ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!perl | ||
#written by Andrey A Voropaev ([email protected]) | ||
|
||
use strict; | ||
|
||
use DBI; | ||
|
||
tst1(); | ||
tst2(); | ||
tst1(); | ||
tst2(); | ||
|
||
sub tst1 | ||
{ | ||
my $dbh = db_handle({ | ||
RaiseError => 0, | ||
PrintError => 0, | ||
AutoCommit => 1, | ||
ora_charset => 'WE8MSWIN1252', | ||
}); | ||
my $sth = $dbh->prepare( | ||
q{ select 1 from dual } | ||
); | ||
$sth->execute(); | ||
my $r = $sth->fetchall_arrayref(); | ||
} | ||
|
||
sub tst2 | ||
{ | ||
my $dbh = db_handle({ | ||
RaiseError => 0, | ||
PrintError => 0, | ||
AutoCommit => 1, | ||
ora_charset => 'AL32UTF8', | ||
}); | ||
my $sth = $dbh->prepare( | ||
q{ select 2 from dual } | ||
); | ||
$sth->execute(); | ||
my $r = $sth->fetchall_arrayref(); | ||
} | ||
|
||
|
||
sub oracle_test_dsn { | ||
my ( $default, $dsn ) = ( 'dbi:Oracle:', $ENV{ORACLE_DSN} ); | ||
|
||
$dsn ||= $ENV{DBI_DSN} | ||
if $ENV{DBI_DSN} && ( $ENV{DBI_DSN} =~ m/^$default/io ); | ||
$dsn ||= $default; | ||
|
||
return $dsn; | ||
} | ||
|
||
sub db_handle { | ||
|
||
my $p = shift; | ||
my $dsn = oracle_test_dsn(); | ||
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger'; | ||
my $dbh = DBI->connect_cached( $dsn, $dbuser, '', $p ); | ||
return $dbh | ||
|
||
} | ||
|