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

Hi monks!

I have a handle named $sth thru which i am preparing, binding parameters and calling a Stored procedure. What gets returned from '$sth->Execute' statement, irrespective of what the Stored procedure code actually returns!!

To make things more clear, take this scenario...if a database error occured or if the procedure itself is missing during the execution of the statement, what does Oracle send back to the perl program ?

Putting the question in C-language style, what is the return-type of the $sth->execute() function in perl ??

Some help please...

Replies are listed 'Best First'.
Re: what does sth->execute return ?
by Emanuel (Pilgrim) on Apr 07, 2003 at 12:17 UTC
    hi

    assuming you use DBI & DBD::Oracle, here's a snippet from the DBI documentation:

    Perform whatever processing is necessary to execute the prepared statement. An undef is returned if an error occurs. A successful execute always returns true regardless of the number of rows affected, even if it's zero (see below). It is always important to check the return status of execute (and most other DBI methods) for errors if you're not using /RaiseError

    see also this

    hth
    emanuel
Re: what does sth->execute return ?
by davorg (Chancellor) on Apr 07, 2003 at 12:57 UTC

    The return type is a scalar. It is either true or false (undef) depending on whether or not the execute succeeded. If the execute failed then you can get more details from $sth->err or $sth->errstr.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

(jeffa) Re: what does sth->execute return ?
by jeffa (Bishop) on Apr 07, 2003 at 14:31 UTC
    "if a database error occured or if the procedure itself is missing during the execution of the statement..."

    Regardless of what DBI::execute returns, i always (well ... 99% of the time) handle errors by setting the RaiseError attrib to a true value:

    my $dbh = DBI->connect( qw(DBI:vendor:database:host user pass), {RaiseError=>1} );
    Now, every error is caught, so i can safely use:
    my $sth = $dbh->prepare('select foo from bar'); $sth->execute();
    without having to check for errors ... DBI will do it for me. ;)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)