I'm new to DBI programming, and get an error on exiting my program,
which does query the database and return values.  The problem seems to
be with the line $rc = $dbh->disconnect, which does not appear to be
executed.  Can anyone point out what I'm doing wrong? 

Rick

(begin error messages)

(in cleanup) Uncaught exception from user code:
Can't call method "FETCH" on an undefined value at
C:/Perl/site/lib/Win32/TieRegistry.pm line 1486, <> line 4 during global
destruction.
Win32::TieRegistry::DESTROY('Win32::TieRegistry=HASH(0x22292a0)') called
at ora-test.pl line 0
eval {...} called at ora-test.pl line 0

(end error messages)


(begin program listing)

#!/usr/bin/perl -w
use diagnostics;
use strict;
use DBI;
use Term::ReadKey;

my ($rc, $user, $passwd) = '';
print "Username: ";
chomp ($user = <>);

print "Password, please: ";

if ($^O eq 'MSWin32') { 
        ReadMode 'noecho'; 
} else { 
        system ("stty -echo"); 
}

chomp ($passwd = <>);

if ($^O eq 'MSWin32') {
        ReadMode 'normal';
} else {
        system ("stty echo");
}

my $dbh = DBI->connect("dbi:Oracle:DSDB", lc($user), $passwd)
        or die "Couldn't connect to database: " . DBI->errstr;

my $sth = $dbh->prepare('SELECT * FROM prsn WHERE pr_surname_nm = ?')
        or die "Couldn't prepare statement: " . $dbh->errstr;

print "\n\nEnter name> ";
while (my $queryname = <>) {                                    # Read input from user
        chomp $queryname;
        if ($queryname eq '') { exit };
        my @data;
        $sth->execute(uc($queryname))                           # Execute the query
                or die "Couldn't execute statement: " . $sth->errstr;
                
        # Read the matching records and print them out
        while (@data = $sth->fetchrow_array()) {
                my $pn_id = $data[0];
                my $last_name = $data[1];
                my $first_name = $data[2];
                my $middle_name = $data[3];
                print "\t$pn_id: $first_name $middle_name $last_name\n";
        }
        
        if ($sth->rows == 0) { print "No names matched '$queryname'.\n\n"; }
        
        $sth->finish;
        print "\nEnter name> ";
}

$rc = $dbh->disconnect;
print "Return code was $rc\n";

(end program listing)
-- 
Rick Nakroshis
Applications Interface Manager
SEIT Contract Team

Defense Security Service
Ft. Meade, Maryland

(301) 677-5015
 DSN  923-5015

Reply via email to