Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Yet Another DBI error

by polettix (Vicar)
on Apr 05, 2005 at 18:06 UTC ( [id://445065]=perlquestion: print w/replies, xml ) Need Help??

polettix has asked for the wisdom of the Perl Monks concerning the following question:

Update: I happened to finish my CPAN::Mini donwload and reinstalling DBI. It all works good now, thanks to all and sorry for not trying the reinstall before boring you!
Wisest Monks,

I've having a hard time with the following code, which accuses me of an Attempt to free unreferenced scalar: SV 0x81bf1f8.

Here's the code:
#!/usr/bin/perl use strict; use warnings; use DBI; ###################################################################### +## package Category; sub new { bless {}, shift; } sub load_fromdb { my ($self, $dbh) = @_; my $query = "SELECT * FROM Category WHERE tag = 'tag'"; ########## -1- ########## print "load_fromdb: got " . $dbh->selectall_hashref($query, 'id') . "\n"; } sub save_todb { my ($self, $dbh) = @_; ########## -2- ########## local $dbh->{RaiseError}; print "localised \$dbh->{RaiseError}, became " . \$dbh->{'RaiseError'} . "\n"; print "\$dbh is $dbh\n"; ########## -3- ########## my @a = $dbh->selectrow_array("SELECT id FROM Tag WHERE id = 'ciao' +"); } ###################################################################### +## package main; my $dbh = DBI->connect("DBI:mysql:database=forecast_recurrent;host=localhost", "poletti", "", {'RaiseError' => 0, 'PrintError' => 0}); print "DB handler: $dbh\n"; my $c = new Category; $c->load_fromdb($dbh, 'HEAD'); print "\$c object holds " . scalar(keys %$c) . " elements\n"; $c->save_todb($dbh, 'TRY');
which yields:
DB handler: DBI::db=HASH(0x824be28) load_fromdb: got HASH(0x8231a10) $c object holds 0 elements localised $dbh->{RaiseError}, became SCALAR(0x81bf144) $dbh is DBI::db=HASH(0x824be28) Attempt to free unreferenced scalar: SV 0x81bf1f8.
So, the offending SV actually is the localised hash element.

Now, when I comment any line after a numbered comment, the error disappears. I may understand that commenting out the "offending" reference, i.e. line after comment #2, but I really cannot understand the other two!

Is it possible that's only a DBI bug, possibly resolved in latest versions? My "details":

poletti@flaviox ~> perl -v + This is perl, v5.8.6 built for i386-linux $DBI::VERSION = "1.40"; # From Slackware
TIA,

Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")

Don't fool yourself.

Replies are listed 'Best First'.
Re: Yet Another DBI error
by RazorbladeBidet (Friar) on Apr 05, 2005 at 19:38 UTC
    Gives me (no error):
    DB handler: DBI::db=HASH(0x20213164) load_fromdb: got HASH(0x201c70c4) $c object holds 0 elements localised $dbh->{RaiseError}, became SCALAR(0x2038d22c) $dbh is DBI::db=HASH(0x20213164)
    This is perl, v5.8.0 built for aix-thread-multi $DBI::VERSION = "1.42";
    But it's using Oracle, not MySql! (no MySql imp to use)

    Perhaps it is a problem with the disconnection of DBD::Mysql
    --------------
    "But what of all those sweet words you spoke in private?"
    "Oh that's just what we call pillow talk, baby, that's all."
Re: Yet Another DBI error
by tlm (Prior) on Apr 05, 2005 at 19:26 UTC

    I can't see the problem. Such "action at a distance errors" (i.e. the strange effects you observed when deleting some seemingly unrelated lines of code) remind me of my days as a C programmer. This more than anything else makes me take the possibility of a bug in DBI more seriously than I would have otherwise. That said, 9 out of 10 times I think I may have found a bug, it turns out that I'm the one who's wrong, so I've learned to be cautious about jumping to that conclusion.

    I'm sure you'll get better ideas, but when faced with a stumper like this, my first instinct is to step through the rough patch inside perldb, and try to localize the error as much as possible. The error appears to be happening during the execution of the call to selectrow_array; in my copy of DBI.pm that function is implemented in Perl, so you could step into it and see exactly where the error is triggered. This may give you a clue.

    the lowliest monk

Re: Yet Another DBI error
by NateTut (Deacon) on Apr 05, 2005 at 21:15 UTC
    Where are your prepare & execute statements? Did I miss them somewhere?
      selectall_hashref and friends handle the prepare (if needed), execute, and fetches under the hood.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://445065]
Approved by RolandGunslinger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found