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 76 77 78 79 80 81
|
#!perl -w
use DBI;
use DBD::Oracle qw(ORA_RSET SQLCS_NCHAR);
use strict;
use Test::More;
unshift @INC ,'t';
require 'nchar_test_lib.pl';
$| = 1;
## ----------------------------------------------------------------------------
## 56embbeded.t
## By John Scoles, The Pythian Group
## ----------------------------------------------------------------------------
## Just a few checks to see if I can select embedded objectes with Oracle::DBD
## Nothing fancy.
## ----------------------------------------------------------------------------
# create a database handle
my $dsn = oracle_test_dsn();
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
my $dbh;
eval {$dbh = DBI->connect($dsn, $dbuser, '', { RaiseError=>1,
AutoCommit=>1,
PrintError => 0 })};
if ($dbh) {
plan tests => 4;
} else {
plan skip_all => "Unable to connect to Oracle";
}
# check that our db handle is good
isa_ok($dbh, "DBI::db");
my $table = "table_embed";
my $type = $table.'a_type';
#do not warn if already there
eval {
local $dbh->{PrintError} = 0;
$dbh->do(qq{drop TABLE $table });
};
eval {
local $dbh->{PrintError} = 0;
$dbh->do(qq{drop TYPE $type });
};
$dbh->do(qq{CREATE or replace TYPE $type as varray(10) of varchar(30) });
$dbh->do(qq{
CREATE TABLE $table
( aa_type $type)
});
$dbh->do("insert into $table values ($type('1','2','3','4','5'))");
# simple execute
my $sth;
ok ($sth = $dbh->prepare("select * from $table"), '... Prepare should return true');
my $problems;
ok ($sth->execute(), '... Select should return true');
while (my ($a)=$sth->fetchrow()){
$problems= scalar(@$a);
}
cmp_ok(scalar($problems), '==',5, '... we should have 5 items');
$dbh->do("drop table $table");
$dbh->do("drop type $type");
$dbh->disconnect;
1;
|