File: 30Oracle.t

package info (click to toggle)
libdbd-odbc-perl 1.37-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,272 kB
  • sloc: perl: 7,932; ansic: 5,991; makefile: 33; sql: 8
file content (75 lines) | stat: -rwxr-xr-x 2,139 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl -I./t -w
# $Id: 30Oracle.t 11714 2008-09-01 19:24:09Z mjevans $

use Test::More;
$| = 1;

my $has_test_nowarnings = 1;
eval "require Test::NoWarnings";
$has_test_nowarnings = undef if $@;
my $tests = 5;
$tests += 1 if $has_test_nowarnings;
plan tests => $tests;

# use_ok('DBI', qw(:sql_types));
# can't seem to get the imports right this way
use DBI qw(:sql_types);
use_ok('ODBCTEST');
use_ok('Data::Dumper');

# to help ActiveState's build process along by behaving (somewhat) if a dsn is not provided
BEGIN {
    plan skip_all => "DBI_DSN is undefined"
        if (!defined $ENV{DBI_DSN});
}
END {
    Test::NoWarnings::had_no_warnings()
          if ($has_test_nowarnings);
}

my $dbh = DBI->connect();
unless($dbh) {
   BAIL_OUT("Unable to connect to the database $DBI::errstr\nTests skipped.\n");
   exit 0;
}

my $dbname = $dbh->get_info(17); # DBI::SQL_DBMS_NAME
SKIP:
{
   skip "Oracle tests not supported using " . $dbname, 3 unless ($dbname =~ /Oracle/i);


   $dbh->do("create or replace function PERL_DBD_TESTFUNC(a in integer, b in integer) return integer is c integer; begin if b is null then c := 0; else c := b; end if; return a * c + 1; end;");
   my $sth = $dbh->prepare("{ ? = call PERL_DBD_TESTFUNC(?, ?) }");
   my $value = undef;
   my $b = 30;
   $sth->bind_param_inout(1, \$value, 50, SQL_INTEGER);
   $sth->bind_param(2, 10, SQL_INTEGER);
   $sth->bind_param(3, 30, SQL_INTEGER);
   $sth->execute;
   is($value, 301);

   $b = undef;
   $sth->bind_param_inout(1, \$value, 50, SQL_INTEGER);
   $sth->bind_param(2, 20, SQL_INTEGER);
   $sth->bind_param(3, undef, SQL_INTEGER);
   $sth->execute;
   is($value,1);

   eval{$dbh->do("drop function PERL_DBD_TESTFUNC");};

   $dbh->do("create or replace procedure PERL_DBD_TESTPROC(a in integer,b out integer) is begin b := a + 1; end;");
   $sth = $dbh->prepare("{call PERL_DBD_TESTPROC(?,?)}");
   $sth->bind_param(1, 10, SQL_INTEGER);
   $sth->bind_param_inout(2, \$value, 50, SQL_INTEGER);
   $sth->execute;
   is($value, 11);

   eval{$dbh->do("drop procedure PERL_DBD_TESTPROC");};
};

if (DBI->trace > 0) {
   DBI->trace(0);
}

$dbh->disconnect;