Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

DBD::ODBC - Why do i get an "out of memory" exception?

by karlgoethebier (Curate)
on Apr 18, 2014 at 11:44 UTC ( #1082749=perlquestion: print w/ replies, xml ) Need Help??
karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

in some older code i found something like this:

do { my @row; while (@row = $sth->fetchrow_array()) { # do stuff here } } while ( defined( $sth->{odbc_more_results}) );

This one throws an "out of memory" exception. I don"t know who wrote it ;-)

According to the manual of DBD::ODBC the code should be:

do { my @row; while (@row = $sth->fetchrow_array()) { # do stuff here } } while ( $sth->{odbc_more_results} );

This one works as expected. No need to worry - i use this code.

But i wonder why the first example fails.

Update: defined for ever?

#!/usr/bin/env perl + use feature qw (say); use strict; use warnings; my $foo; ( defined $foo ) ? say qq(D'oh!) : say qq(No!); $foo = 0; ( defined $foo ) ? say qq(D'oh!) : say qq(No!);

Thank you very much for any hint and best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Comment on DBD::ODBC - Why do i get an "out of memory" exception?
Select or Download Code
Re: DBD::ODBC - Why do i get an "out of memory" exception?
by sundialsvc4 (Abbot) on Apr 18, 2014 at 12:57 UTC

    On the one hand, I do believe that the use of defined() in the original code is incorrect.   But, on the other hand, I do not see from what has been presented here a valid cause for an “out of memory” condition.   I suspect that the true cause of the problem lies within the body of the loop, and, unless you can actually, at-will reproduce the condition using exactly the code snippet you posted here, you should assume the same.   Never “think you know” why a piece of code is screwing-up ... prove it.

      "I suspect that the true cause of the problem lies within the body of the loop..."

      Mmh, i don't think so. No. I just join each row and print to a CSV file the usual way.

      Regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Re: DBD::ODBC - Why do i get an "out of memory" exception?
by Laurent_R (Parson) on Apr 18, 2014 at 13:17 UTC
    Yes, probably "defined for ever". It is quite possible that your method just keeps returning a false but defined value (say zero or an empty string) even when that is no more piece of data to return.
      "It is quite possible that your method just keeps returning a false but defined value..."

      Yes. I should study the sources...

      Thanks and best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Re: DBD::ODBC - Why do i get an "out of memory" exception?
by mje (Deacon) on Apr 22, 2014 at 17:15 UTC

    odbc_more_results returns 1 when there are more results and 0 when there are no more results. As you have seen both are defined but one is false.

      "As you have seen both are defined but one is false..."

      Yes. Thank you mje and best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-10-01 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (386 votes), past polls