Om!

Problem:
my $dbh = DBI->connect("dbi:Sybase:server=$percdb", $user, $passwd, {'RaiseError' => 1} ); if ($DBI::errstr) { FATAL($DBI::errstr); exit 1; } else { DEBUG('Successfully connected to database!'); } my $sth = $dbh->prepare($QUERY); $sth->execute; handle_db_error(); $result_hash = $sth->fetchall_hashref('ent_id'); handle_db_error(); sub handle_db_error { if ($dbh->err) { FATAL("Error: $DBI::errstr"); exit 9; } }
You see that I connect to the database and try to fetch all rows into a hash. It works most of the time and always from the shell (though not always when called from cron - strange!) Now my problem is that sometimes there is nothing in $sth and I get the following error: DBD::Sybase::st fetchall_hashref failed: Field 'ent_id' does not exist (not one of COL(1)) at /.../.../myscript line 75. As I do error checking, it looks like it just doesn't create an error. As is is a Select statement, I also cannot use the $sth->rows to check if there are any rows.

Any wisdom greatly appreciated!

Thanks, Sven

In reply to DBI::Sybase sometimes returns nothing, but does not generate an error -> how can I catch this? by svenXY

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.