NT4, sp6, ASPerl 629, DBI , DBD:: Oracle |see code below|
I was experimenting to get an INSERT working with my DBI - DBD::Oracle,
however, I can't quite understand the problem. Anyone got any ideas? I'm
completely new to this game.
ERROR output (echoed to DOS window):
Can't set DBI::db=HASH(0x1e00130)->{RaisEerror}: unrecognised attribute
at D:/Perl/site/lib/DB
I.pm line 437.
Thanks in advance,
Steve Few
Raleigh, NC
-------------------code-----------------------------------------------
#!usr/bin/perl -w
use strict;
use DBI;
my $can;
my @row;
my $dbh =DBI->connect('DBI:Oracle:opn.ambient','Steve','Oracle',
{RaisEerror=>1,Autocommit=>0}
)
or die "Couldn't connect to database: " .
"$DBI::errstr";
# Prepare statement for execution
my $sth = $dbh->prepare("select PDATE from dat");
my $cnt = $dbh->prepare("select count(*) from dat");
# Execute statement
$sth->execute;
$cnt->execute;
print "$cnt\n";
while (@row = $sth->fetchrow_array() ) { print "Row: @row\n";}
warn "data fetching terminated by early error:
$DBI::errstr\n";
my @ary = (
["Nov 11, 2001", "DK", "20" ],
[ "Nov 12, 2001", "ST", "30" ],
[ "Nov 13, 2001", "ST", "40" ],
[" Nov 14, 2001", "DK", "50" ]
);
# my $sth = " ";
# my $dbh = " ";
$dbh->do("INSERT INTO dat (PDATE, CAN, SITELETTER,RTIME) VALUES
('$ary[0]','$ary[1]','$ary[2]','$ary[3]')");
better $sth = ( "INSERT INTO dat (PDATE, CAN, SITELETTER,RTIME)
VALUES ('$ary[0]','$ary[1]','$ary[2]','$ary[3]')" );
$dbh->do($sth) or die "Copy mistake ($sth)";
my $sql = qq { insert into dat(PDATE, CAN, SITELETTER,RTIME)
values (?,?,?,?)};
$sth = $dbh->prepare($sql);
for (@ary) {
eval {
$sth->bind_param( 1, @$_->[0] );
$sth->bind_param( 2, @$_->[1]);
$sth->bind_param( 3, @$_->[2]);
$sth->bind_param( 4, @$_->[3]);
$sth->execute();
$dbh->commit();
}; # stop the eval
if( $@ ) {
warn "Database error: $DBI::errstr\n";
$dbh->rollback(); #just die if rollback is failing
} # stopping the loopif
} # stopping the for loop
$sth->finish();
$dbh->disconnect or warn "disconnect failed: $DBI::errstr\n";
exit;