Skip to content

Commit

Permalink
Fix for rt 64244 - don't fail but skip tests if can not connect by M…
Browse files Browse the repository at this point in the history
…artin J. Evans and John Scoles

 

git-svn-id: http://svn.perl.org/modules/dbd-oracle/trunk@14656 50811bd7-b8ce-0310-adc1-d9db26280581
  • Loading branch information
byterock committed Jan 27, 2011
1 parent d4e203d commit 7552405
Show file tree
Hide file tree
Showing 33 changed files with 202 additions and 144 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
=head1 Changes in DBD-Oracle 1.28 (svn rev 14583)

Fix for rt 64244 - don't bail out, skip tests we cannot connect by Martin J. Evans and John Scoles
Added DBI to PREREQ_PM in Makefile.PL by Martin J. Evans
Added build_requires in Makefile.PL by Martin J. Evans
Added workaround for ExtUtils::MakeMaker problems by Martin J. Evans
Expand Down
18 changes: 11 additions & 7 deletions t/10general.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ require 'nchar_test_lib.pl';

$| = 1;

plan tests => 30;

diag('Test preparsing, Active, NLS_NUMERIC_CHARACTERS, err, ping and OCI version');

my $dsn = oracle_test_dsn();
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
my $dbh = DBI->connect($dsn, $dbuser, '');

unless($dbh) {
BAIL_OUT("Unable to connect to Oracle ($DBI::errstr)\nTests skipped.\n");
exit 0;
my $dbh = DBI->connect($dsn, $dbuser, '',
{
PrintError => 0,
});

if ($dbh) {
plan tests => 30;
} else {
plan skip_all => "Unable to connect to Oracle";
}

my($sth, $p1, $p2, $tmp);
Expand Down Expand Up @@ -83,6 +86,7 @@ my $warn='';
eval {
local $SIG{__WARN__} = sub { $warn = $_[0] };
$dbh->{RaiseError} = 1;
$dbh->{PrintError} = 1;
$dbh->do("some invalid sql statement");
};
ok($@ =~ /DBD::Oracle::db do failed:/, "eval error: ``$@'' expected 'do failed:'");
Expand All @@ -92,7 +96,7 @@ ok($DBI::err, 'err defined');
ok($ora_errno, 'ora_errno defined');
is($ora_errno, $DBI::err, 'ora_errno and err equal');
$dbh->{RaiseError} = 0;

$dbh->{PrintError} = 0;
# ---

ok( $dbh->ping, 'ping - connected');
Expand Down
13 changes: 9 additions & 4 deletions t/12impdata.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ BEGIN {
die $use_threads_err if $use_threads_err; # need threads
}

use Test::More tests => 7;

unshift @INC, 't';
require 'nchar_test_lib.pl';

my $dsn = oracle_test_dsn();
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
my $dbh = DBI->connect( $dsn, $dbuser, '', );

my $dbh = DBI->connect( $dsn, $dbuser, '', {
PrintError => 0,
});

if ($dbh) {
plan tests => 7;
} else {
plan skip_all => "Unable to connect to Oracle";
}
my $drh = $dbh->{Driver};
my ($sess_1) = $dbh->selectrow_array("select userenv('sessionid') from dual");

Expand Down
14 changes: 13 additions & 1 deletion t/14threads.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ BEGIN {
use strict;
use DBI;

use Test::More tests => 19;
use Test::More;

unshift @INC, 't';
require 'nchar_test_lib.pl';

my $dsn = oracle_test_dsn();
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
my $dbh = DBI->connect($dsn, $dbuser, '',{
PrintError => 0,
});

if ($dbh) {
plan tests => 19;
$dbh->disconnect;
} else {
plan skip_all => "Unable to connect to Oracle";
}

my $last_session : shared;
our @pool : shared;
Expand Down
48 changes: 22 additions & 26 deletions t/15nls.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,41 @@ unshift @INC ,'t';
require 'nchar_test_lib.pl';

my $testcount = 9;
plan tests => $testcount;

$| = 1;

diag('test nls_date_format, ora_can_unicode');
my $dsn = oracle_test_dsn();
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';

SKIP :
{
my $dbh = DBI->connect($dsn, $dbuser, '',
{
AutoCommit => 1,
PrintError => 1,
});

skip "Unable to connect to Oracle ($DBI::errstr)", $testcount
unless ($dbh);
my $dbh = DBI->connect($dsn, $dbuser, '',{
PrintError => 0,
});
if ($dbh) {
plan tests => $testcount;
} else {
plan skip_all => "Unable to connect to Oracle";
}

my ($nls_parameters_before, $nls_parameters_after);
my $old_date_format = 'HH24:MI:SS DD/MM/YYYY';
my $new_date_format = 'YYYYMMDDHH24MISS';
my ($nls_parameters_before, $nls_parameters_after);
my $old_date_format = 'HH24:MI:SS DD/MM/YYYY';
my $new_date_format = 'YYYYMMDDHH24MISS';

ok($dbh->do("alter session set nls_date_format='$old_date_format'"), 'set date format');
ok($dbh->do("alter session set nls_date_format='$old_date_format'"), 'set date format');

like($dbh->ora_can_unicode, qr/^[0123]/, 'ora_can_unicode');
like($dbh->ora_can_unicode, qr/^[0123]/, 'ora_can_unicode');

ok($nls_parameters_before = $dbh->ora_nls_parameters, 'fetch ora_nls_parameters');
is(ref($nls_parameters_before), 'HASH', 'check ora_nls_parameters returned hashref');
is($nls_parameters_before->{'NLS_DATE_FORMAT'}, $old_date_format, 'check returned nls_date_format');
ok($nls_parameters_before = $dbh->ora_nls_parameters, 'fetch ora_nls_parameters');
is(ref($nls_parameters_before), 'HASH', 'check ora_nls_parameters returned hashref');
is($nls_parameters_before->{'NLS_DATE_FORMAT'}, $old_date_format, 'check returned nls_date_format');

ok($dbh->do("alter session set nls_date_format='$new_date_format'"), 'alter date format');
ok(eq_hash($nls_parameters_before, $dbh->ora_nls_parameters), 'check ora_nls_parameters caches old values');
ok($dbh->do("alter session set nls_date_format='$new_date_format'"), 'alter date format');
ok(eq_hash($nls_parameters_before, $dbh->ora_nls_parameters), 'check ora_nls_parameters caches old values');

$nls_parameters_before->{NLS_DATE_FORMAT} = 'foo';
isnt($nls_parameters_before->{NLS_DATE_FORMAT},
$dbh->ora_nls_parameters->{NLS_DATE_FORMAT}, 'check ora_nls_parameters returns a copy');
$nls_parameters_before->{NLS_DATE_FORMAT} = 'foo';
isnt($nls_parameters_before->{NLS_DATE_FORMAT},
$dbh->ora_nls_parameters->{NLS_DATE_FORMAT}, 'check ora_nls_parameters returns a copy');

is($dbh->ora_nls_parameters(1)->{'NLS_DATE_FORMAT'}, $new_date_format, 'refetch and check new nls_date_format value');
}
is($dbh->ora_nls_parameters(1)->{'NLS_DATE_FORMAT'}, $new_date_format, 'refetch and check new nls_date_format value');

__END__
7 changes: 3 additions & 4 deletions t/20select.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ my $table = "dbd_ora__drop_me" . ($ENV{DBD_ORACLE_SEQ}||'');
my $dsn = oracle_test_dsn();
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
my $dbh = DBI->connect($dsn, $dbuser, '', {
AutoCommit => 1,
PrintError => 0,
});
PrintError => 0,
});

if ($dbh) {
plan tests=>$tests;
} else {
plan skip_all => "Unable to connect to oracle ($DBI::errstr)\n";
plan skip_all => "Unable to connect to oracle\n";
}

diag('test simple select statements with [utf8]');
Expand Down
3 changes: 2 additions & 1 deletion t/21nchar.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ SKIP: {
plan skip_all => "Unable to run 8bit char test, perl version is less than 5.6" unless ( $] >= 5.006 );

$dbh = db_handle();
plan skip_all => "Not connected to oracle" if not $dbh;
# $dbh->{PrintError} = 1;
plan skip_all => "Unable to connect to Oracle" if not $dbh;

diag("testing control and 8 bit chars:\n") ;
diag(" Database and client versions and character sets:\n");
Expand Down
2 changes: 1 addition & 1 deletion t/22nchar_al32utf8.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SKIP: {
set_nls_nchar( (ORA_OCI >= 9.2) ? 'AL32UTF8' : 'UTF8', 1 );
$dbh = db_handle();

plan skip_all => "Not connected to oracle" if not $dbh;
plan skip_all => "Unable to connect to Oracle" if not $dbh;
plan skip_all => "Database NCHAR character set is not Unicode" if not db_nchar_is_utf($dbh) ;
print "testing utf8 with nchar columns\n" ;

Expand Down
2 changes: 1 addition & 1 deletion t/22nchar_utf8.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SKIP: {
set_nls_nchar( (ORA_OCI >= 9.2) ? 'AL32UTF8' : 'UTF8' ,1 );
$dbh = db_handle();

plan skip_all => "Not connected to oracle" if not $dbh;
plan skip_all => "Unable to connect to Oracle" if not $dbh;
plan skip_all => "Database NCHAR character set is not Unicode" if not db_nchar_is_utf($dbh) ;
diag("testing utf8 with nchar columns\n");

Expand Down
2 changes: 1 addition & 1 deletion t/23wide_db.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SKIP: {
#! #set_nls_nchar( 'WE8ISO8859P1' ,1 ); #it breaks and it is stupid to do this... doc it XXX
$dbh = db_handle();

plan skip_all => "Not connected to oracle" if not $dbh;
plan skip_all => "Unable to connect to Oracle" if not $dbh;
plan skip_all => "Database character set is not Unicode" if not db_ochar_is_utf($dbh) ;
print "testing utf8 with char columns (wide mode database)\n" ;

Expand Down
2 changes: 1 addition & 1 deletion t/23wide_db_8bit.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SKIP: {
set_nls_lang_charset( 'WE8MSWIN1252' ,1 );
$dbh = db_handle();

plan skip_all => "Not connected to oracle" if not $dbh;
plan skip_all => "Unable to connect to Oracle" if not $dbh;
plan skip_all => "Database character set is not Unicode" if not db_ochar_is_utf($dbh) ;
print "testing utf8 with char columns (wide mode database)\n" ;

Expand Down
2 changes: 1 addition & 1 deletion t/23wide_db_al32utf8.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SKIP: {
set_nls_lang_charset( (ORA_OCI >= 9.2) ? 'AL32UTF8' : 'UTF8', 1 );
$dbh = db_handle();

plan skip_all => "Not connected to oracle" if not $dbh;
plan skip_all => "Unable to connect to Oracle" if not $dbh;
plan skip_all => "Database character set is not Unicode" if not db_ochar_is_utf($dbh) ;
diag("testing utf8 with char columns (wide mode database)\n") ;

Expand Down
4 changes: 3 additions & 1 deletion t/24implicit_utf8.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ SKIP: {
if ORA_OCI() < 9.0 and !$ENV{DBD_ALL_TESTS};

$dbh = db_handle(); # just to check connection and db NCHAR character set
plan skip_all => "Not connected to oracle" if not $dbh;


plan skip_all => "Unable to connect to Oracle" if not $dbh;
plan skip_all => "Database NCHAR character set is not Unicode" if not db_nchar_is_utf($dbh) ;
$dbh->disconnect();

Expand Down
2 changes: 1 addition & 1 deletion t/25plsql.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if ($dbh) {
}
plan tests=>82;
} else {
plan skip_all => "Unable to connect to Oracle ($DBI::errstr)\n";
plan skip_all => "Unable to connect to Oracle \n";
}


Expand Down
28 changes: 13 additions & 15 deletions t/26exe_array.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@ $| = 1;
## an ASCII only DB
## ----------------------------------------------------------------------------


# create a database handle
my $dsn = oracle_test_dsn();
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
$ENV{NLS_NCHAR} = "US7ASCII";
$ENV{NLS_LANG} = "AMERICAN";
my $dbh = DBI->connect($dsn, $dbuser, '', {
AutoCommit=>1,
PrintError => 0,
ora_envhp => 0,
});

if ($dbh){
plan tests => 16;
my $dbh;

eval {
$dbh = DBI->connect($dsn, $dbuser, '', { RaiseError=>1,
AutoCommit=>1,
PrintError => 0,
ora_envhp => 0,
})
};
if ($dbh) {
plan tests => 16;
} else {
plan skip_all => "Unable to connect to Oracle";
}
else {

plan skip_all => "Not connected to oracle" if not $dbh;
}



# check that our db handle is good
isa_ok($dbh, "DBI::db");
Expand Down
10 changes: 6 additions & 4 deletions t/28array_bind.t
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sub db_connect($) {

my $p = {
AutoCommit => 1,
PrintError => 1,
PrintError => 0,
FetchHashKeyName => 'NAME_lc',
ora_envhp => 0, # force fresh environment (with current NLS env vars)
};
Expand Down Expand Up @@ -278,13 +278,15 @@ sub test_number_SP($){
SKIP: {
$dbh = db_connect(0);

plan skip_all => "Not connected to oracle" if not $dbh;
plan tests => 19;
if ($dbh) {
plan tests => 15;
} else {
plan skip_all => "Unable to connect to Oracle" if not $dbh;
}

test_varchar2_table_3_tests($dbh);
test_number_table_3_tests($dbh);
test_inout_array_tests($dbh);
test_number_SP($dbh);

};

Expand Down
18 changes: 15 additions & 3 deletions t/30long.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ my $tests = @test_sets * $tests_per_set-1;
#very odd little thing that took a while to figure out.
#Seems I now have 479 tests which is 9 more so 96 test then -1 to round it off

plan tests => $tests;

$| = 1;
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
my $table = table();
Expand All @@ -42,7 +40,21 @@ my $sz = 8;

my($p1, $p2, $tmp, @tmp);

my $dbh = db_handle() or BAILOUT("Can't connect to database: $DBI::errstr");
#my $dbh = db_handle();


$dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
my $dsn = oracle_test_dsn();
my $dbh = DBI->connect($dsn, $dbuser, '',{
PrintError => 0,
});

if ($dbh) {
plan tests => $tests;
} else {
plan skip_all => "Unable to connect to Oracle";
}

my $ora_server_version = $dbh->func("ora_server_version");
diag("ora_server_version: @$ora_server_version\n");
show_db_charsets($dbh) if $dbh;
Expand Down
Loading

0 comments on commit 7552405

Please sign in to comment.