I did not also unset PrintError, but I just tried that, and still no luck.
I am using the ODBC DBD at the time, but I believe I had also tried this with Oracle.
Basically, I have code which wants RaiseError on for a prepare and execute. Then, I do NOT want it on for the fetches, because there is a fetch that could potentially throw an error. With RaiseError off (what I want) this code works:
# there is more to fetch, so set this high
if ($sth->fetchrow_arrayref)
{
$extraFetch = 5000000;
}
else
{
$extraFetch = $numRowsDisplayed;
}
This fetch could potentially be outside the boundaries of the rows returned. With RaiseError off, I don't die and the conditiom works fine. With RaiseError on, I get this error:
DBD::ODBC::st fetchrow_arrayref failed: (DBD: no select statement currently executing err=-1)
If RaiseError could be off at this point, all would be good.
However there are other areas in my code where I would have this same problem. Typically I will want to encapsulate a few statements in a transaction (with eval) and want RaiseError on for that. Then I will want it off, as there is code that follows which does things along the lines of
execute($sql) || handle the error
(where a die being thrown would never get into my "handle the error code)
Matt
| [reply] [d/l] |
This prints "1 error 3" for me with PostgreSQL, as I'd expect. I don't have ODBC handy to check.
#!perl -w
$|=1;
use strict;
use DBI;
my $dbh=DBI->connect('dbi:Pg:dbname=test1');
$dbh->{PrintError}=0;
$dbh->do('junk');
print "1";
eval {
local $dbh->{RaiseError}=1;
$dbh->do('junk');
print "2";
};
print " error " if $@;
$dbh->do('junk');
print "3";
| [reply] [d/l] |
Your sample code works for me as well (on ODBC).
So something is obviously awry with my code.
Hmm! More to come... :)
(and thanks again)
Matt
| [reply] |
if ($sth->fetchrow_arrayref)
{
$extraFetch = 5000000;
}
else
{
$extraFetch = $numRowsDisplayed;
}
You might want to check for $sth->{Active} instead, it should be true if there is more to fetch and false otherwise. | [reply] [d/l] |