Perl/Oracle Error

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
omer
Lance Naik
Posts: 44
Joined: Fri Sep 05, 2003 10:22 pm

Perl/Oracle Error

Post by omer »

Whenever I try to connect to the Oracle DB from my script using :

Code: Select all

sub dbconnect {

my ($data_souce, $db_user, $db_pass, $dbhandle) = @_;

my $dbh = DBI->connect( $data_source, $db_user, $db_pass,
                      {
                        RaiseError => 1,
                        AutoCommit => 0
                      }
                   )  ||
        die "Database connection not made: $DBI::errstr";
print "Connected to DB...Initializing transactions...";

$dbhandle = $dbh;
}
i get the following warning/error...:



Issuing rollback() for database handle being DESTROY'd without explicit disconnect() at....


Any ideas why this is or how to better write this code?...should be trivial dont you think?
pervaze
Cadet
Posts: 9
Joined: Fri May 28, 2004 8:52 am
Location: Pittsburgh, USA

Post by pervaze »

The message is self-explanatory :D

You need to do a disconnect from the database explicitly, rather than letting the handle be destroyed automatically when your application terminates. Any pending transactions would be discarded at this point, as a safeguard, by the database.
omer
Lance Naik
Posts: 44
Joined: Fri Sep 05, 2003 10:22 pm

Post by omer »

OFCOURSE!,
This is just the function to connect to the database, I do the transactions in a separate method and close the connection by calling a terminate() subroutine. So once again,...the same question.
pervaze
Cadet
Posts: 9
Joined: Fri May 28, 2004 8:52 am
Location: Pittsburgh, USA

Post by pervaze »

I know little about perl, but...

isn't this declaring local variables? $dbhandle will be destroyed on exiting this subroutine.

my ($data_souce, $db_user, $db_pass, $dbhandle) = @_;

Ok.. forget that. The last statement is returned as the subroutine result. However, you could always make the db handle a global, and see if never having the db handle in a local, gets rid of the problem.
omer
Lance Naik
Posts: 44
Joined: Fri Sep 05, 2003 10:22 pm

Post by omer »

$dbhandle is global.. i pass it by reference to the dbconnect function..
heres the call from the main body....:

Code: Select all

dbconnect($data_source, $db_user, $db_pass, \$dbhandle);
and then i just assign $dbh to $dbhandle at the end of the subroutine. Oh wait..do I have to undef $dbh? hmm...well...shall try that..let me know..
thanks for your help....
appreciate it.
-omer
omer
Lance Naik
Posts: 44
Joined: Fri Sep 05, 2003 10:22 pm

Post by omer »

nevermind...
solved it myself...
my own stupidity...assigning back the value to the reference should have been:
$$dbhandle = $dbh;
instead of
$dbhandle = $dbh;

apologies,
-omer
There are three kinds of people in this world....
those who know how to count...
and those who dont
Post Reply