CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: DBI:
err, state & errstr captured only on fetarray, not on execute


New User

Aug 24, 2015, 5:15 AM

Post #1 of 2 (20877 views)
err, state & errstr captured only on fetarray, not on execute Can't Post

Hi All,

I am new to the perl world. I am trying to connect to a odbc data source, execute a procedure and fetch the o/p result set.

Now the procedure I am calling, I know, will error out (because of deliberate raiseeror in an attempt to test the error handling). But when I execute the script the error is captured not in $sth->execute(), instead at sth->fetcharray_hashref().

I am doing this with a non-standard ODBC driver (I mean ODBC driver of a non-relational database).

Below is the code snipped I am trying:

use strict;
use warnings;

use DBI;
use DBD::ODBC;
my $dbh = DBI->connect('dbi:ODBC:testing', '', '') or die "ERROR: Failed to connect, $DBI::errstr";

my $query = "exec testing.parent";
my $sth = $dbh->prepare($query) or die "ERROR: Failed prepare of stmt to fetch proc parms, $DBI::errstr";

my $temp = $sth->execute();
my $errstr = $sth->errstr();
print "ret $temp\n"; # pirnts -1
print "$errstr\n"; # Says $errstr is uninitialized

my $array = $sth->fetchrow_hashref(); # Throws error
$errstr = $sth->errstr();
print "$errstr\n"; # prints the intended error string

exit 0;

Is this a normal behavior? or is this problem with the non-standard odbc driver vendor provided?

As per my requirements, I have to capture the SQL Error after execute.

Please help.

Veteran / Moderator

Aug 24, 2015, 8:10 AM

Post #2 of 2 (20871 views)
Re: [abandekar] err, state & errstr captured only on fetarray, not on execute [In reply to] Can't Post

What you're seeing is normal behavior and should be expected.

There is a difference between a statement that can't be executed vs a statement that can be executed but deliberately raises an exception.

If it helps, think of it as the difference between perl's compile time vs runtime errors.

(This post was edited by FishMonger on Aug 24, 2015, 8:13 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives