#!/usr/bin/perl -w
DBI->trace(
shift
)
if
1 <
@ARGV
&&
$ARGV
[0] =~ /^-
die
"syntax: $0 [-# trace] base user pass"
if
3 >
@ARGV
;
my
(
$inst
,
$user
,
$pass
) =
@ARGV
;
my
$dbh
= DBI->
connect
(
"dbi:Oracle:$inst"
,
$user
,
$pass
,
{
AutoCommit
=> 0,
RaiseError
=> 1,
PrintError
=> 0 } )
or
die
$DBI::errstr
;
print
"Creating table\n"
;
eval
{
$dbh
->
do
(
'CREATE TABLE primes ( prime NUMBER )'
); };
warn
$@
if
$@;
print
"Loading table"
;
my
$sth
=
$dbh
->prepare(
'INSERT INTO primes VALUES ( ? )'
);
while
( <DATA> ) {
chomp
;
print
" $_"
;
$sth
->execute(
$_
);
print
" commit ("
,
$dbh
->commit,
")"
if
11 ==
$_
;
}
print
"\n"
;
my
$prime
;
print
"Reading table for the first time\n"
;
$sth
=
$dbh
->prepare(
'SELECT prime FROM primes ORDER BY prime'
);
$sth
->execute;
$sth
->bind_columns( {}, \
$prime
);
while
(
$sth
->fetch ) {
print
" $prime"
;
}
$sth
->finish;
print
"\n"
;
print
"rollback ("
,
$dbh
->rollback,
")\n"
;
print
"Reading table for the second time.\n"
;
$sth
->execute;
$sth
->bind_columns( {}, \
$prime
);
while
(
$sth
->fetch ) {
print
" $prime"
;
}
$sth
->finish;
print
"\n"
;
$dbh
->
do
(
'DROP TABLE primes'
);
print
"Table Dropped\n"
;
$dbh
->disconnect;